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-9685] don't react with "legalhold already disabled" when on pending state #4104

Merged
merged 4 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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-9685
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disabling legalhold before user's approval doesn't result in an error
22 changes: 20 additions & 2 deletions integration/test/Test/LegalHold.hs
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,8 @@ testLHCannotCreateGroupWithUsersInConflict = do
postConversation bob defProteus {qualifiedUsers = [debora, alice], newUsersRole = "wire_member", team = Just tidAlice}
>>= assertLabel 403 "missing-legalhold-consent"

testNoConsentCannotBeInvited :: (HasCallStack) => App ()
testNoConsentCannotBeInvited = do
testLHNoConsentCannotBeInvited :: (HasCallStack) => App ()
testLHNoConsentCannotBeInvited = do
-- team that is legalhold whitelisted
(legalholder, tidLH, userLHNotActivated : _) <- createTeam OwnDomain 2
legalholdWhitelistTeam tidLH legalholder >>= assertStatus 200
Expand Down Expand Up @@ -904,3 +904,21 @@ testNoConsentCannotBeInvited = do
resp.json %. "status" `shouldMatch` "enabled"

addMembers userLHNotActivated cid (def {users = [peer3]}) >>= assertLabel 403 "not-connected"

testLHDisableBeforeApproval :: (HasCallStack) => App ()
testLHDisableBeforeApproval = do
(alice, tid, [bob]) <- createTeam OwnDomain 2
legalholdWhitelistTeam tid alice >>= assertStatus 200

withMockServer def lhMockApp \lhDomAndPort _chan -> do
postLegalHoldSettings tid alice (mkLegalHoldSettings lhDomAndPort) >>= assertStatus 201

-- alice requests a legalhold device for bob and sets his status to "pending"
requestLegalHoldDevice tid alice bob >>= assertSuccess
let getBob'sStatus = (getUser bob bob >>= getJSON 200) %. "legalhold_status" & asString
getBob'sStatus `shouldMatch` "pending"

-- alice disables legalhold. the status for bob should now not be pending anymore
disableLegalHold tid alice bob defPassword
>>= assertStatus 200
getBob'sStatus `shouldMatch` "disabled"
15 changes: 12 additions & 3 deletions services/galley/src/Galley/API/LegalHold.hs
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,18 @@ disableForUser lzusr tid uid (Public.DisableLegalHoldForUserRequest mPassword) =

userLHStatus <-
maybe defUserLegalHoldStatus (view legalHoldStatus) <$> getTeamMember tid (tUnqualified luid)
if not $ userLHEnabled userLHStatus
then pure DisableLegalHoldWasNotEnabled
else disableLH (tUnqualified lzusr) luid userLHStatus $> DisableLegalHoldSuccess

let doDisable = disableLH (tUnqualified lzusr) luid userLHStatus $> DisableLegalHoldSuccess
case userLHStatus of
-- no state change necessary
UserLegalHoldDisabled -> pure DisableLegalHoldWasNotEnabled
UserLegalHoldNoConsent ->
-- no state change allowed
-- we cannot go to disabled because that would subsume consent
pure DisableLegalHoldWasNotEnabled
-- LH is enabled or pending, we can disable (change state) without issue
UserLegalHoldEnabled -> doDisable
UserLegalHoldPending -> doDisable
where
disableLH :: UserId -> Local UserId -> UserLegalHoldStatus -> Sem r ()
disableLH zusr luid userLHStatus = do
Expand Down
Loading