-
Notifications
You must be signed in to change notification settings - Fork 333
WPB-10658 invitation and acceptance of individual users to teams #4229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fisx
merged 7 commits into
develop
from
WPB-10658-invitation-and-acceptance-of-individual-users-to-teams
Sep 17, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
440606c
WPB-10658: invite personal users into teams.
fisx 78a4068
fix invitation url generation on list invitations
battermann 0bddf32
simplify input constraint
battermann a167d92
2 additional tests
battermann 1ac8eae
additional test for list invitations
battermann bfc7777
Update libs/wire-api/src/Wire/API/Routes/Public/Brig.hs
fisx 8ff61f2
Update services/brig/src/Brig/App.hs
fisx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| With this release it will be possible to invite personal users to teams. In `brig`'s config, `emailSMS.team.tExistingUserInvitationUrl` is required to be set to a value that points to the correct teams/account page. | ||
| If `emailSMS.team` is not defined at all in the current environment, the value of `externalUrls.teamSettings` (or, if not present, `externalUrls.nginz`) will be used to construct the correct url, and no configuration change is necessary. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| A new endpoint `POST /teams/invitations/accept` allows a non-team user to accept an invitation to join a team |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Allow an existing non-team user to migrate to a team |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,6 +149,7 @@ library | |
| Test.Services | ||
| Test.Spar | ||
| Test.Swagger | ||
| Test.Teams | ||
| Test.TeamSettings | ||
| Test.User | ||
| Test.Version | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| -- This file is part of the Wire Server implementation. | ||
| -- | ||
| -- Copyright (C) 2024 Wire Swiss GmbH <opensource@wire.com> | ||
| -- | ||
| -- This program is free software: you can redistribute it and/or modify it under | ||
| -- the terms of the GNU Affero General Public License as published by the Free | ||
| -- Software Foundation, either version 3 of the License, or (at your option) any | ||
| -- later version. | ||
| -- | ||
| -- This program is distributed in the hope that it will be useful, but WITHOUT | ||
| -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| -- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | ||
| -- details. | ||
| -- | ||
| -- You should have received a copy of the GNU Affero General Public License along | ||
| -- with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| module Test.Teams where | ||
|
|
||
| import API.Brig | ||
| import API.BrigInternal (createUser, getInvitationCode, refreshIndex) | ||
| import API.Common | ||
| import API.Galley (getTeamMembers) | ||
| import API.GalleyInternal (setTeamFeatureStatus) | ||
| import Control.Monad.Codensity (Codensity (runCodensity)) | ||
| import Control.Monad.Extra (findM) | ||
| import Control.Monad.Reader (asks) | ||
| import Notifications (isUserUpdatedNotif) | ||
| import SetupHelpers | ||
| import Testlib.JSON | ||
| import Testlib.Prelude | ||
| import Testlib.ResourcePool (acquireResources) | ||
|
|
||
| testInvitePersonalUserToTeam :: (HasCallStack) => App () | ||
| testInvitePersonalUserToTeam = do | ||
| resourcePool <- asks (.resourcePool) | ||
| runCodensity (acquireResources 1 resourcePool) $ \[testBackend] -> do | ||
| let domain = testBackend.berDomain | ||
| (owner, tid, tm) <- runCodensity (startDynamicBackend testBackend def) $ \_ -> do | ||
| (owner, tid, tm : _) <- createTeam domain 2 | ||
| pure (owner, tid, tm) | ||
|
|
||
| runCodensity | ||
| ( startDynamicBackend | ||
| testBackend | ||
| (def {galleyCfg = setField "settings.exposeInvitationURLsTeamAllowlist" [tid]}) | ||
battermann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| $ \_ -> do | ||
| bindResponse (listInvitations owner tid) $ \resp -> do | ||
| resp.status `shouldMatchInt` 200 | ||
| resp.json %. "invitations" `shouldMatch` ([] :: [()]) | ||
| ownerId <- owner %. "id" & asString | ||
| setTeamFeatureStatus domain tid "exposeInvitationURLsToTeamAdmin" "enabled" >>= assertSuccess | ||
| user <- createUser domain def >>= getJSON 201 | ||
| uid <- user %. "id" >>= asString | ||
| email <- user %. "email" >>= asString | ||
| inv <- postInvitation owner (PostInvitation (Just email) Nothing) >>= getJSON 201 | ||
| checkListInvitations owner tid email | ||
| code <- getInvitationCode owner inv >>= getJSON 200 >>= (%. "code") & asString | ||
| inv %. "url" & asString >>= assertUrlContainsCode code | ||
| acceptTeamInvitation user code Nothing >>= assertStatus 400 | ||
| acceptTeamInvitation user code (Just "wrong-password") >>= assertStatus 403 | ||
| void $ withWebSockets [user] $ \wss -> do | ||
| acceptTeamInvitation user code (Just defPassword) >>= assertSuccess | ||
| for wss $ \ws -> do | ||
| n <- awaitMatch isUserUpdatedNotif ws | ||
| n %. "payload.0.user.team" `shouldMatch` tid | ||
| bindResponse (getSelf user) $ \resp -> do | ||
| resp.status `shouldMatchInt` 200 | ||
| resp.json %. "team" `shouldMatch` tid | ||
| -- a team member can now find the former personal user in the team | ||
| bindResponse (getTeamMembers tm tid) $ \resp -> do | ||
| resp.status `shouldMatchInt` 200 | ||
| members <- resp.json %. "members" >>= asList | ||
| ids <- for members ((%. "user") >=> asString) | ||
| ids `shouldContain` [uid] | ||
| -- the former personal user can now see other team members | ||
| bindResponse (getTeamMembers user tid) $ \resp -> do | ||
| resp.status `shouldMatchInt` 200 | ||
| members <- resp.json %. "members" >>= asList | ||
| ids <- for members ((%. "user") >=> asString) | ||
| tmId <- tm %. "id" & asString | ||
| ids `shouldContain` [ownerId] | ||
| ids `shouldContain` [tmId] | ||
| -- the former personal user can now search for the owner | ||
| bindResponse (searchContacts user (owner %. "name") domain) $ \resp -> do | ||
| resp.status `shouldMatchInt` 200 | ||
| documents <- resp.json %. "documents" >>= asList | ||
| ids <- for documents ((%. "id") >=> asString) | ||
| ids `shouldContain` [ownerId] | ||
| refreshIndex domain | ||
| -- a team member can now search for the former personal user | ||
| bindResponse (searchContacts tm (user %. "name") domain) $ \resp -> do | ||
| resp.status `shouldMatchInt` 200 | ||
| document <- resp.json %. "documents" >>= asList >>= assertOne | ||
| document %. "id" `shouldMatch` uid | ||
| document %. "team" `shouldMatch` tid | ||
fisx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| where | ||
| checkListInvitations :: Value -> String -> String -> App () | ||
| checkListInvitations owner tid email = do | ||
| newUserEmail <- randomEmail | ||
| void $ postInvitation owner (PostInvitation (Just newUserEmail) Nothing) >>= assertSuccess | ||
| bindResponse (listInvitations owner tid) $ \resp -> do | ||
| resp.status `shouldMatchInt` 200 | ||
| invitations <- resp.json %. "invitations" >>= asList | ||
|
|
||
| -- personal user invitations have a different invitation URL than non-existing user invitations | ||
| newUserInv <- invitations & findM (\i -> (i %. "email" >>= asString) <&> (== newUserEmail)) | ||
| newUserInvUrl <- newUserInv %. "url" & asString | ||
| newUserInvUrl `shouldContainString` "/register" | ||
|
|
||
| personalUserInv <- invitations & findM (\i -> (i %. "email" >>= asString) <&> (== email)) | ||
| personalUserInvUrl <- personalUserInv %. "url" & asString | ||
| personalUserInvUrl `shouldContainString` "/accept-invitation" | ||
|
|
||
| assertUrlContainsCode :: (HasCallStack) => String -> String -> App () | ||
| assertUrlContainsCode code url = do | ||
| queryParam <- url & asString <&> getQueryParam "team-code" | ||
| queryParam `shouldMatch` Just (Just code) | ||
|
|
||
| testInvitePersonalUserToTeamMultipleInvitations :: (HasCallStack) => App () | ||
| testInvitePersonalUserToTeamMultipleInvitations = do | ||
| (owner, tid, _) <- createTeam OwnDomain 0 | ||
| (owner2, _, _) <- createTeam OwnDomain 0 | ||
| user <- createUser OwnDomain def >>= getJSON 201 | ||
| email <- user %. "email" >>= asString | ||
| inv <- postInvitation owner (PostInvitation (Just email) Nothing) >>= getJSON 201 | ||
| inv2 <- postInvitation owner2 (PostInvitation (Just email) Nothing) >>= getJSON 201 | ||
| code <- getInvitationCode owner inv >>= getJSON 200 >>= (%. "code") & asString | ||
| acceptTeamInvitation user code (Just defPassword) >>= assertSuccess | ||
| bindResponse (getSelf user) $ \resp -> do | ||
| resp.status `shouldMatchInt` 200 | ||
| resp.json %. "team" `shouldMatch` tid | ||
| code2 <- getInvitationCode owner2 inv2 >>= getJSON 200 >>= (%. "code") & asString | ||
| bindResponse (acceptTeamInvitation user code2 (Just defPassword)) $ \resp -> do | ||
| resp.status `shouldMatchInt` 403 | ||
| resp.json %. "label" `shouldMatch` "cannot-join-multiple-teams" | ||
| bindResponse (getSelf user) $ \resp -> do | ||
| resp.status `shouldMatchInt` 200 | ||
| resp.json %. "team" `shouldMatch` tid | ||
| acceptTeamInvitation user code (Just defPassword) >>= assertStatus 400 | ||
|
|
||
| testInvitationTypesAreDistinct :: (HasCallStack) => App () | ||
| testInvitationTypesAreDistinct = do | ||
| -- We are only testing one direction because the other is not possible | ||
| -- because the non-existing user cannot have a valid session | ||
| (owner, _, _) <- createTeam OwnDomain 0 | ||
| user <- createUser OwnDomain def >>= getJSON 201 | ||
| email <- user %. "email" >>= asString | ||
| inv <- postInvitation owner (PostInvitation (Just email) Nothing) >>= getJSON 201 | ||
| code <- getInvitationCode owner inv >>= getJSON 200 >>= (%. "code") & asString | ||
| let body = | ||
| AddUser | ||
| { name = Just email, | ||
| email = Just email, | ||
| password = Just defPassword, | ||
| teamCode = Just code | ||
| } | ||
| addUser OwnDomain body >>= assertStatus 409 | ||
|
|
||
| testTeamUserCannotBeInvited :: (HasCallStack) => App () | ||
| testTeamUserCannotBeInvited = do | ||
| (_, _, tm : _) <- createTeam OwnDomain 2 | ||
| (owner2, _, _) <- createTeam OwnDomain 0 | ||
| email <- tm %. "email" >>= asString | ||
| postInvitation owner2 (PostInvitation (Just email) Nothing) >>= assertStatus 409 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.