Skip to content
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

WPB-5845 guests should not be able to join conversations under legalhold #3853

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
1 change: 1 addition & 0 deletions changelog.d/3-bug-fixes/WPB-5845
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Guests cannot be added to conversations that are under legalhold
battermann marked this conversation as resolved.
Show resolved Hide resolved
48 changes: 48 additions & 0 deletions integration/test/Test/LegalHold.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,54 @@ import Testlib.MockIntegrationService
import Testlib.Prekeys
import Testlib.Prelude

testLHPreventAddingGuests :: App ()
testLHPreventAddingGuests = do
battermann marked this conversation as resolved.
Show resolved Hide resolved
startDynamicBackends [mempty] $ \[dom] -> do
withMockServer lhMockApp $ \lhPort _chan -> do
(owner, tid, [alice, alex]) <- createTeam dom 3

void $ legalholdWhitelistTeam owner tid >>= assertSuccess
void $ legalholdIsTeamInWhitelist owner tid >>= assertSuccess
void $ postLegalHoldSettings owner tid (mkLegalHoldSettings lhPort) >>= getJSON 201

george <- randomUser dom def
georgeQId <- george %. "qualified_id"
connectUsers =<< forM [alice, george] make
connectUsers =<< forM [alex, george] make
conv <- postConversation alice (defProteus {qualifiedUsers = [alex], team = Just tid}) >>= getJSON 201

-- the guest should be added to the conversation
bindResponse (addMembers alice conv def {users = [georgeQId]}) $ \resp -> do
resp.status `shouldMatchInt` 200
resp.json %. "type" `shouldMatch` "conversation.member-join"

-- assert that the guest is in the conversation
checkConvHasOtherMembers conv alice [alex, george]

-- now request legalhold for alex (but not alice)
requestLegalHoldDevice tid owner alex >>= assertSuccess

-- the guest should be removed from the conversation
checkConvHasOtherMembers conv alice [alex]

-- it should not be possible neither for alex nor for alice to add the guest back
bindResponse (addMembers alex conv def {users = [georgeQId]}) $ \resp -> do
resp.status `shouldMatchInt` 403
resp.json %. "label" `shouldMatch` "not-connected"

bindResponse (addMembers alice conv def {users = [georgeQId]}) $ \resp -> do
resp.status `shouldMatchInt` 403
resp.json %. "label" `shouldMatch` "missing-legalhold-consent"
where
checkConvHasOtherMembers :: HasCallStack => Value -> Value -> [Value] -> App ()
checkConvHasOtherMembers conv u us =
bindResponse (getConversation u conv) $ \resp -> do
resp.status `shouldMatchInt` 200
mems <-
resp.json %. "members.others" & asList >>= traverse \m -> do
m %. "qualified_id"
mems `shouldMatchSet` forM us (\m -> m %. "qualified_id")

abstractTestLHMessageExchange :: HasCallStack => String -> Int -> Bool -> Bool -> Bool -> Bool -> App ()
abstractTestLHMessageExchange dom lhPort clients1New clients2New consentFrom1 consentFrom2 = do
(owner, tid, [mem1, mem2]) <- createTeam dom 3
Expand Down
7 changes: 5 additions & 2 deletions services/galley/src/Galley/API/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -986,8 +986,11 @@ allLegalholdConsentGiven uids = do
-- a whitelisted team is equivalent to have given consent to be in a
-- conversation with user under legalhold.
flip allM (chunksOf 32 uids) $ \uidsPage -> do
teamsPage <- nub . Map.elems <$> getUsersTeams uidsPage
allM isTeamLegalholdWhitelisted teamsPage
teamsPage <- getUsersTeams uidsPage
allM (eitherTeamMemberAndLHAllowedOrDefLHStatus teamsPage) uidsPage
where
eitherTeamMemberAndLHAllowedOrDefLHStatus teamsPage uid = do
fromMaybe (consentGiven defUserLegalHoldStatus == ConsentGiven) <$> (for (Map.lookup uid teamsPage) isTeamLegalholdWhitelisted)

-- | Add to every uid the legalhold status
getLHStatusForUsers ::
Expand Down
Loading