Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d8d0ce0
Make integration test helper types more general.
fisx Dec 14, 2020
bdedb58
Search by email: integration tests.
fisx Dec 14, 2020
789dbf4
Clean up ES/bloodhound test helpers.
fisx Dec 14, 2020
0cfd3ed
Naive implementation (without query).
fisx Dec 14, 2020
d241818
noop
fisx Dec 18, 2020
0d603f4
migration version [get back to this and understand it!]
fisx Dec 18, 2020
b9956d8
[noise] Focus on integration test.
fisx Dec 22, 2020
7a7fe5c
Split up Brig.User.Search.Index into seperate modules.
fisx Dec 22, 2020
7721e35
Introduce browse-team (rest end-point and es query skeleton).
fisx Dec 23, 2020
a19afd3
Merge remote-tracking branch 'origin/develop' into fisx/es-updates
smatting Jan 15, 2021
4bb8931
...
smatting Jan 15, 2021
50a6b31
Make email changes trigger a reindex
smatting Jan 18, 2021
faa840d
Add fields saml_idp, managed_by and created_at to index
smatting Jan 19, 2021
9f7b112
Fix writetimeToUTC
smatting Jan 20, 2021
835baf2
align TeamContact with UserDoc
smatting Jan 20, 2021
2ca23f2
Add tests for email and empty query
smatting Jan 20, 2021
7a50620
extend IndexQuery with sort params
smatting Jan 20, 2021
9e6c5fc
Implement: Empty query sorts on created_at desc
smatting Jan 20, 2021
db28ae0
Change endpoint /search/browse-team/:tid -> /teams/:tid/search
smatting Jan 20, 2021
25cd033
Adapt roundtrip test & fix discovered bug
smatting Jan 20, 2021
f12ed13
clean up
smatting Jan 20, 2021
ab6d13c
Add dummy "role" to mapping and data structures
smatting Jan 21, 2021
5780cf0
Remove irrelevant(?) comment
smatting Jan 21, 2021
1fb27aa
update unit test
smatting Jan 21, 2021
3838f9b
Fix compilation
smatting Jan 21, 2021
c1c06c4
Refrence to pre-PR mapping to old mapping in tests
smatting Jan 21, 2021
11ca2e9
Merge remote-tracking branch 'origin/develop' into fisx/es-updates
smatting Jan 21, 2021
809156b
Update services/brig/src/Brig/User/API/Search.hs
smatting Jan 22, 2021
57893f2
Apply suggestions from code review
smatting Jan 22, 2021
1bf01ca
Trigger index when UserSSOId changes
smatting Jan 22, 2021
d5cf65c
rename browse team -> team user search
smatting Jan 22, 2021
39896bc
Revert: Remove deleteIndex
smatting Jan 22, 2021
77956e2
Adapt tests to new modules
smatting Jan 22, 2021
ab6dc7f
rename TODOs to FUTUREWORKs
smatting Jan 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions deploy/services-demo/conf/nginz/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ http {
proxy_pass http://brig;
}

location ~* ^/teams/([^/]+)/search$ {
include common_response_with_zauth.conf;
proxy_pass http://brig;
}

location /connections {
include common_response_with_zauth.conf;
proxy_pass http://brig;
Expand Down
2 changes: 1 addition & 1 deletion libs/cassandra-util/src/Cassandra/CQL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import Database.CQL.Protocol as C
Set (Set),
Tagged (Tagged),
TimeUuid (TimeUuid),
Value (CqlAscii, CqlBigInt, CqlBlob, CqlBoolean, CqlDouble, CqlInt, CqlList, CqlText, CqlUdt),
Value (CqlAscii, CqlBigInt, CqlBlob, CqlBoolean, CqlDouble, CqlInt, CqlList, CqlText, CqlTimestamp, CqlUdt),
Version (V4),
W,
ctype,
Expand Down
6 changes: 4 additions & 2 deletions libs/wire-api/src/Wire/API/Swagger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ models =
User.Profile.modelAsset,
User.RichInfo.modelRichInfo,
User.RichInfo.modelRichField,
User.Search.modelSearchResult,
User.Search.modelSearchContact
User.Search.modelSearchResult User.Search.modelSearchContact,
User.Search.modelSearchResult User.Search.modelTeamContact,
User.Search.modelSearchContact,
User.Search.modelTeamContact
]
83 changes: 79 additions & 4 deletions libs/wire-api/src/Wire/API/User/Search.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,24 @@
module Wire.API.User.Search
( SearchResult (..),
Contact (..),
TeamContact (..),

-- * Swagger
modelSearchResult,
modelSearchContact,
modelTeamContact,
)
where

import Data.Aeson
import Data.Id (TeamId, UserId)
import Data.Json.Util (UTCTimeMillis)
import qualified Data.Swagger.Build.Api as Doc
import Imports
import Wire.API.Arbitrary (Arbitrary, GenericUniform (..))
import Wire.API.Team.Role (Role)
import Wire.API.User (ManagedBy)
import Wire.API.User.Identity (Email (..))

--------------------------------------------------------------------------------
-- SearchResult
Expand All @@ -46,16 +52,16 @@ data SearchResult a = SearchResult
deriving stock (Eq, Show, Generic)
deriving (Arbitrary) via (GenericUniform (SearchResult a))

modelSearchResult :: Doc.Model
modelSearchResult = Doc.defineModel "SearchResult" $ do
modelSearchResult :: Doc.Model -> Doc.Model
modelSearchResult modelContact = Doc.defineModel "SearchResult" $ do
Doc.description "Search Result"
Doc.property "found" Doc.int32' $
Doc.description "Total number of hits"
Doc.property "returned" Doc.int32' $
Doc.description "Number of hits returned"
Doc.property "took" Doc.int32' $
Doc.description "Search time in ms"
Doc.property "documents" (Doc.array (Doc.ref modelSearchContact)) $
Doc.property "documents" (Doc.array (Doc.ref modelContact)) $
Doc.description "List of contacts found"

instance ToJSON a => ToJSON (SearchResult a) where
Expand All @@ -78,7 +84,8 @@ instance FromJSON a => FromJSON (SearchResult a) where
--------------------------------------------------------------------------------
-- Contact

-- | This is a subset of 'User' and json instances should reflect that.
-- | Returned by 'searchIndex' under @/contacts/search@.
-- This is a subset of 'User' and json instances should reflect that.
data Contact = Contact
{ contactUserId :: UserId,
contactName :: Text,
Expand Down Expand Up @@ -124,3 +131,71 @@ instance FromJSON Contact where
<*> o .:? "accent_id"
<*> o .:? "handle"
<*> o .:? "team"

--------------------------------------------------------------------------------
-- TeamContact

-- | Returned by 'browseTeam' under @/teams/:tid/search@.
data TeamContact = TeamContact
{ teamContactUserId :: UserId,
teamContactName :: Text,
teamContactColorId :: Maybe Int,
teamContactHandle :: Maybe Text,
teamContactTeam :: Maybe TeamId,
teamContactEmail :: Maybe Email,
teamContactCreatedAt :: Maybe UTCTimeMillis,
teamContactManagedBy :: Maybe ManagedBy,
teamContactSAMLIdp :: Maybe Text,
teamContactRole :: Maybe Role
}
deriving stock (Eq, Show, Generic)
deriving (Arbitrary) via (GenericUniform TeamContact)

modelTeamContact :: Doc.Model
modelTeamContact = Doc.defineModel "TeamContact" $ do
Doc.description "Contact discovered through search"
Doc.property "id" Doc.string' $
Doc.description "User ID"
Doc.property "name" Doc.string' $
Doc.description "Name"
Doc.property "handle" Doc.string' $
Doc.description "Handle"
Doc.property "accent_id" Doc.int32' $ do
Doc.description "Accent color"
Doc.optional
Doc.property "team" Doc.string' $ do
Doc.description "Team ID"
Doc.optional
Doc.property "email" Doc.string' $ do
Doc.description "Email address"
Doc.optional

instance ToJSON TeamContact where
toJSON c =
object
[ "id" .= teamContactUserId c,
"name" .= teamContactName c,
"accent_id" .= teamContactColorId c,
"handle" .= teamContactHandle c,
"team" .= teamContactTeam c,
"email" .= teamContactEmail c,
"created_at" .= teamContactCreatedAt c,
"managed_by" .= teamContactManagedBy c,
"saml_idp" .= teamContactSAMLIdp c,
"role" .= teamContactRole c
]

instance FromJSON TeamContact where
parseJSON =
withObject "Contact" $ \o ->
TeamContact
<$> o .: "id"
<*> o .: "name"
<*> o .:? "accent_id"
<*> o .:? "handle"
<*> o .:? "team"
<*> o .:? "email"
<*> o .:? "created_at"
<*> o .:? "managed_by"
<*> o .:? "saml_idp"
<*> o .:? "role"
10 changes: 9 additions & 1 deletion services/brig/brig.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 7e6bada8622059c2b1e26bbe89e7ed25aa702ac5b7221503f86aad80e842b388
-- hash: c5312f061d226f10f6e7e3dd06dce7730af75b112fd4251c5c7455dc1ab25a4f

name: brig
version: 1.35.0
Expand Down Expand Up @@ -98,6 +98,9 @@ library
Brig.User.Phone
Brig.User.Search.Index
Brig.User.Search.Index.Types
Brig.User.Search.SearchIndex
Brig.User.Search.TeamSize
Brig.User.Search.TeamUserSearch
Brig.User.Template
Brig.Whitelist
Brig.ZAuth
Expand Down Expand Up @@ -189,6 +192,7 @@ library
, ropes >=0.4.20
, safe >=0.3
, safe-exceptions >=0.1
, saml2-web-sso
, scientific >=0.3.4
, scrypt >=0.5
, semigroups >=0.15
Expand Down Expand Up @@ -278,6 +282,7 @@ executable brig-integration
API.Settings
API.Team
API.Team.Util
API.TeamUserSearch
API.User
API.User.Account
API.User.Auth
Expand Down Expand Up @@ -339,6 +344,7 @@ executable brig-integration
, pem
, proto-lens
, random >=1.0
, raw-strings-qq
, retry >=0.6
, safe
, saml2-web-sso
Expand Down Expand Up @@ -470,9 +476,11 @@ test-suite brig-tests
, imports
, polysemy
, polysemy-wire-zoo
, raw-strings-qq
, retry
, tasty
, tasty-hunit
, time
, tinylog
, types-common
, unliftio
Expand Down
5 changes: 5 additions & 0 deletions services/brig/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ library:
- smtp-mail >=0.1
- split >=0.2
- safe-exceptions >=0.1
- saml2-web-sso
- semigroups >=0.15
- servant
- servant-server
Expand Down Expand Up @@ -147,6 +148,7 @@ tests:
- -with-rtsopts=-N
dependencies:
- aeson
- brig
- base
- bloodhound
- brig
Expand All @@ -157,9 +159,11 @@ tests:
- imports
- polysemy
- polysemy-wire-zoo
- raw-strings-qq
- retry
- tasty
- tasty-hunit
- time
- tinylog
- types-common
- unliftio
Expand Down Expand Up @@ -226,6 +230,7 @@ executables:
- pem
- proto-lens
- QuickCheck
- raw-strings-qq
- random >=1.0
- retry >=0.6
- safe
Expand Down
10 changes: 8 additions & 2 deletions services/brig/src/Brig/API/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import qualified Brig.API.User as API
import Brig.API.Util (validateHandle)
import Brig.App
import qualified Brig.Data.User as Data
import qualified Brig.IO.Intra as Intra
import Brig.Options hiding (internalEvents, sesQueue)
import qualified Brig.Provider.API as Provider
import qualified Brig.Team.API as Team
Expand All @@ -40,6 +41,7 @@ import Brig.Types.Intra
import Brig.Types.Team.LegalHold (LegalHoldClientRequest (..))
import qualified Brig.User.API.Auth as Auth
import qualified Brig.User.API.Search as Search
import Brig.User.Event (UserEvent (UserUpdated), UserUpdatedData (eupSSOId, eupSSOIdRemoved), emptyUserUpdatedData)
import Control.Error hiding (bool)
import Control.Lens (view)
import Data.Aeson hiding (json)
Expand Down Expand Up @@ -477,14 +479,18 @@ updateSSOIdH (uid ::: _ ::: req) = do
ssoid :: UserSSOId <- parseJsonBody req
success <- lift $ Data.updateSSOId uid (Just ssoid)
if success
then return empty
then do
lift $ Intra.onUserEvent uid Nothing (UserUpdated ((emptyUserUpdatedData uid) {eupSSOId = Just ssoid}))
return empty
else return . setStatus status404 $ plain "User does not exist or has no team."

deleteSSOIdH :: UserId ::: JSON -> Handler Response
deleteSSOIdH (uid ::: _) = do
success <- lift $ Data.updateSSOId uid Nothing
if success
then return empty
then do
lift $ Intra.onUserEvent uid Nothing (UserUpdated ((emptyUserUpdatedData uid) {eupSSOIdRemoved = True}))
return empty
else return . setStatus status404 $ plain "User does not exist or has no team."

updateManagedByH :: UserId ::: JSON ::: JsonRequest ManagedByUpdate -> Handler Response
Expand Down
4 changes: 2 additions & 2 deletions services/brig/src/Brig/API/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ import Brig.User.Event
import Brig.User.Handle
import Brig.User.Handle.Blacklist
import Brig.User.Phone
import qualified Brig.User.Search.Index as Index
import qualified Brig.User.Search.TeamSize as TeamSize
import Control.Arrow ((&&&))
import Control.Concurrent.Async (mapConcurrently, mapConcurrently_)
import Control.Error
Expand Down Expand Up @@ -303,7 +303,7 @@ createUser new@NewUser {..} = do
ensureMemberCanJoin :: TeamId -> ExceptT CreateUserError AppIO ()
ensureMemberCanJoin tid = do
maxSize <- fromIntegral . setMaxTeamSize <$> view settings
(TeamSize teamSize) <- Index.teamSize tid
(TeamSize teamSize) <- TeamSize.teamSize tid
when (teamSize >= maxSize) $
throwE TooManyTeamMembers
-- FUTUREWORK: The above can easily be done/tested in the intra call.
Expand Down
13 changes: 9 additions & 4 deletions services/brig/src/Brig/IO/Intra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ updateSearchIndex :: UserId -> UserEvent -> AppIO ()
updateSearchIndex orig e = case e of
-- no-ops
UserCreated {} -> return ()
UserIdentityUpdated {} -> return ()
UserIdentityUpdated UserIdentityUpdatedData {..} -> do
when (isJust eiuEmail) $ Search.reindex orig
UserIdentityRemoved {} -> return ()
UserLegalHoldDisabled {} -> return ()
UserLegalHoldEnabled {} -> return ()
Expand All @@ -172,9 +173,11 @@ updateSearchIndex orig e = case e of
or
[ isJust eupName,
isJust eupAccentId,
isJust eupHandle
isJust eupHandle,
isJust eupManagedBy,
isJust eupSSOId || eupSSOIdRemoved
]
when (interesting) $ Search.reindex orig
when interesting $ Search.reindex orig

journalEvent :: UserId -> UserEvent -> AppIO ()
journalEvent orig e = case e of
Expand Down Expand Up @@ -361,7 +364,7 @@ toPushFormat (UserEvent (UserActivated u)) =
[ "type" .= ("user.activate" :: Text),
"user" .= SelfProfile u
]
toPushFormat (UserEvent (UserUpdated (UserUpdatedData i n pic acc ass hdl loc mb))) =
toPushFormat (UserEvent (UserUpdated (UserUpdatedData i n pic acc ass hdl loc mb ssoId ssoIdDel))) =
Just $
M.fromList
[ "type" .= ("user.update" :: Text),
Expand All @@ -375,6 +378,8 @@ toPushFormat (UserEvent (UserUpdated (UserUpdatedData i n pic acc ass hdl loc mb
# "handle" .= hdl
# "locale" .= loc
# "managed_by" .= mb
# "sso_id" .= ssoId
# "sso_id_deleted" .= ssoIdDel
# []
)
]
Expand Down
2 changes: 1 addition & 1 deletion services/brig/src/Brig/Index/Migrations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ migrate l es cas = do

-- | Increase this number any time you want to force reindexing.
expectedMigrationVersion :: MigrationVersion
expectedMigrationVersion = MigrationVersion 2
expectedMigrationVersion = MigrationVersion 3

indexName :: ES.IndexName
indexName = ES.IndexName "wire_brig_migrations"
Expand Down
4 changes: 2 additions & 2 deletions services/brig/src/Brig/Team/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import Brig.Types.Intra (AccountStatus (..), NewUserScimInvitation (..), UserAcc
import Brig.Types.Team (TeamSize)
import Brig.Types.Team.Invitation
import Brig.Types.User (Email, InvitationCode, emailIdentity)
import qualified Brig.User.Search.Index as ESIndex
import qualified Brig.User.Search.TeamSize as TeamSize
import Control.Lens (view, (^.))
import Control.Monad.Trans.Except (mapExceptT)
import Data.Aeson hiding (json)
Expand Down Expand Up @@ -193,7 +193,7 @@ teamSizeH :: JSON ::: TeamId -> Handler Response
teamSizeH (_ ::: t) = json <$> teamSize t

teamSize :: TeamId -> Handler TeamSize
teamSize t = lift $ ESIndex.teamSize t
teamSize t = lift $ TeamSize.teamSize t

getInvitationCodeH :: JSON ::: TeamId ::: InvitationId -> Handler Response
getInvitationCodeH (_ ::: t ::: r) = do
Expand Down
Loading