Skip to content

Commit 37e4bb1

Browse files
committed
Restore previous behaviour of kicking
After #2667, when users are kicked out of a conversation, the events being sent out would look like normal leave events. This commit restores the previous behaviour: the events reflect the fact that the user was kicked out, with the originating user set to the user who caused the change that required users to be removed.
1 parent 9513659 commit 37e4bb1

File tree

3 files changed

+69
-40
lines changed

3 files changed

+69
-40
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Users being kicked out results in member-leave events originating from the user who caused the change in the conversation

services/galley/src/Galley/API/Action.hs

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ performAction tag origUser lconv action = do
340340
E.setConversationReceiptMode (tUnqualified lcnv) (cruReceiptMode action)
341341
pure (mempty, action)
342342
SConversationAccessDataTag -> do
343-
(bm, act) <- performConversationAccessData lconv action
343+
(bm, act) <- performConversationAccessData origUser lconv action
344344
pure (bm, act)
345345

346346
performConversationJoin ::
@@ -457,14 +457,11 @@ performConversationJoin qusr lconv (ConversationJoin invited role) = do
457457
then do
458458
for_ convUsersLHStatus $ \(mem, status) ->
459459
when (consentGiven status == ConsentNotGiven) $ do
460-
let lvictim = qualifyAs lconv (lmId mem)
461-
void . runError @NoChanges $
462-
updateLocalConversation
463-
@'ConversationLeaveTag
464-
(fmap convId lconv)
465-
(qUntagged lvictim)
466-
Nothing
467-
()
460+
kickMember
461+
qusr
462+
lconv
463+
(convBotsAndMembers (tUnqualified lconv))
464+
(qUntagged (qualifyAs lconv (lmId mem)))
468465
else throwS @'MissingLegalholdConsent
469466

470467
checkLHPolicyConflictsRemote ::
@@ -474,10 +471,11 @@ performConversationJoin qusr lconv (ConversationJoin invited role) = do
474471

475472
performConversationAccessData ::
476473
(HasConversationActionEffects 'ConversationAccessDataTag r) =>
474+
Qualified UserId ->
477475
Local Conversation ->
478476
ConversationAccessData ->
479477
Sem r (BotsAndMembers, ConversationAccessData)
480-
performConversationAccessData lconv action = do
478+
performConversationAccessData qusr lconv action = do
481479
when (convAccessData conv == action) noChanges
482480
-- Remove conversation codes if CodeAccess is revoked
483481
when
@@ -506,16 +504,8 @@ performConversationAccessData lconv action = do
506504
let bmToNotify = current {bmBots = bmBots desired}
507505

508506
-- Remove users and notify everyone
509-
for_ (bmQualifiedMembers lcnv toRemove) $ \userToRemove -> do
510-
(extraTargets, action') <- performAction SConversationLeaveTag userToRemove lconv ()
511-
notifyConversationAction
512-
(sing @'ConversationLeaveTag)
513-
userToRemove
514-
True
515-
Nothing
516-
lconv
517-
(bmToNotify <> extraTargets)
518-
action'
507+
for_ (bmQualifiedMembers lcnv toRemove) $
508+
kickMember qusr lconv bmToNotify
519509

520510
pure (mempty, action)
521511
where
@@ -792,3 +782,40 @@ notifyRemoteConversationAction loc rconvUpdate con = do
792782
let bots = []
793783

794784
pushConversationEvent con event localPresentUsers bots $> event
785+
786+
-- | Kick a user from a conversation and send notifications.
787+
--
788+
-- This function removes the given victim from the conversation by making them
789+
-- leave, but then sends notifications as if the user was removed by someone
790+
-- else.
791+
kickMember ::
792+
( Member (Error InternalError) r,
793+
Member ExternalAccess r,
794+
Member FederatorAccess r,
795+
Member GundeckAccess r,
796+
Member ProposalStore r,
797+
Member (Input UTCTime) r,
798+
Member (Input Env) r,
799+
Member MemberStore r,
800+
Member TinyLog r
801+
) =>
802+
Qualified UserId ->
803+
Local Conversation ->
804+
BotsAndMembers ->
805+
Qualified UserId ->
806+
Sem r ()
807+
kickMember qusr lconv targets victim = void . runError @NoChanges $ do
808+
(extraTargets, _) <-
809+
performAction
810+
SConversationLeaveTag
811+
victim
812+
lconv
813+
()
814+
notifyConversationAction
815+
(sing @'ConversationRemoveMembersTag)
816+
qusr
817+
True
818+
Nothing
819+
lconv
820+
(targets <> extraTargets)
821+
(pure victim)

services/galley/test/integration/API.hs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,9 +1483,9 @@ postConvertTeamConv = do
14831483
-- non-team members get kicked out
14841484
liftIO $ do
14851485
WS.assertMatchN_ (5 # Second) [wsA, wsB, wsE, wsM] $
1486-
wsAssertMemberLeave qconv qeve (pure qeve)
1486+
wsAssertMemberLeave qconv qalice (pure qeve)
14871487
WS.assertMatchN_ (5 # Second) [wsA, wsB, wsE, wsM] $
1488-
wsAssertMemberLeave qconv qmallory (pure qmallory)
1488+
wsAssertMemberLeave qconv qalice (pure qmallory)
14891489
-- joining (for mallory) is no longer possible
14901490
postJoinCodeConv mallory j !!! const 403 === statusCode
14911491
-- team members (dave) can still join
@@ -1537,14 +1537,17 @@ testAccessUpdateGuestRemoved = do
15371537
-- note that removing users happens asynchronously, so this check should
15381538
-- happen while the mock federator is still available
15391539
WS.assertMatchN_ (5 # Second) [wsA, wsB, wsC] $
1540-
wsAssertMembersLeave (cnvQualifiedId conv) charlie [charlie]
1540+
wsAssertMembersLeave (cnvQualifiedId conv) alice [charlie]
15411541
WS.assertMatchN_ (5 # Second) [wsA, wsB, wsC] $
1542-
wsAssertMembersLeave (cnvQualifiedId conv) dee [dee]
1542+
wsAssertMembersLeave (cnvQualifiedId conv) alice [dee]
15431543

15441544
-- dee's remote receives a notification
1545+
let compareLists [] ys = [] @?= ys
1546+
compareLists (x : xs) ys = case break (== x) ys of
1547+
(ys1, _ : ys2) -> compareLists xs (ys1 <> ys2)
1548+
_ -> assertFailure $ "Could not find " <> show x <> " in " <> show ys
15451549
liftIO $
1546-
sortOn
1547-
(fmap fst)
1550+
compareLists
15481551
( map
15491552
( \fr -> do
15501553
cu <- eitherDecode (frBody fr)
@@ -1558,20 +1561,18 @@ testAccessUpdateGuestRemoved = do
15581561
reqs
15591562
)
15601563
)
1561-
@?= sortOn
1562-
(fmap fst)
1563-
[ Right (charlie, SomeConversationAction (sing @'ConversationLeaveTag) ()),
1564-
Right (dee, SomeConversationAction (sing @'ConversationLeaveTag) ()),
1565-
Right
1566-
( alice,
1567-
SomeConversationAction
1568-
(sing @'ConversationAccessDataTag)
1569-
ConversationAccessData
1570-
{ cupAccess = mempty,
1571-
cupAccessRoles = Set.fromList [TeamMemberAccessRole]
1572-
}
1573-
)
1574-
]
1564+
[ Right (alice, SomeConversationAction (sing @'ConversationRemoveMembersTag) (pure charlie)),
1565+
Right (alice, SomeConversationAction (sing @'ConversationRemoveMembersTag) (pure dee)),
1566+
Right
1567+
( alice,
1568+
SomeConversationAction
1569+
(sing @'ConversationAccessDataTag)
1570+
ConversationAccessData
1571+
{ cupAccess = mempty,
1572+
cupAccessRoles = Set.fromList [TeamMemberAccessRole]
1573+
}
1574+
)
1575+
]
15751576

15761577
-- only alice and bob remain
15771578
conv2 <-

0 commit comments

Comments
 (0)