Skip to content

Commit 1c458bf

Browse files
committed
refactor: Leif feedback
1 parent 5339025 commit 1c458bf

File tree

3 files changed

+45
-36
lines changed

3 files changed

+45
-36
lines changed

integration/test/Test/TeamCollaborators.hs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ testImplicitConnectionNoCollaborator = do
157157
-- Alice and Bob aren't connected at all.
158158
postOne2OneConversation bob alice team0 "chit-chat" >>= assertLabel 403 "no-team-member"
159159

160-
testRemoveMemberInTeamsO2O :: (HasCallStack) => App ()
161-
testRemoveMemberInTeamsO2O = do
160+
testRemoveCollaboratorInTeamsO2O :: (HasCallStack) => App ()
161+
testRemoveCollaboratorInTeamsO2O = do
162162
(owner0, team0, [alice]) <- createTeam OwnDomain 2
163163
(owner1, team1, [bob]) <- createTeam OwnDomain 2
164164

@@ -181,8 +181,8 @@ testRemoveMemberInTeamsO2O = do
181181
Internal.getConversation convId >>= assertLabel 404 "no-conversation"
182182
getMLSOne2OneConversation charlie bob >>= assertSuccess
183183

184-
testRemoveMemberInO2OConnected :: (HasCallStack) => App ()
185-
testRemoveMemberInO2OConnected = do
184+
testRemoveCollaboratorInO2OConnected :: (HasCallStack) => App ()
185+
testRemoveCollaboratorInO2OConnected = do
186186
(owner0, team0, [alice]) <- createTeam OwnDomain 2
187187

188188
-- At the time of writing, it wasn't clear if this should be a bot instead.
@@ -197,8 +197,8 @@ testRemoveMemberInO2OConnected = do
197197

198198
getMLSOne2OneConversation bob alice >>= assertSuccess
199199

200-
testRemoveMemberInO2O :: (HasCallStack) => App ()
201-
testRemoveMemberInO2O = do
200+
testRemoveCollaboratorInO2O :: (HasCallStack) => App ()
201+
testRemoveCollaboratorInO2O = do
202202
(owner0, team0, [alice]) <- createTeam OwnDomain 2
203203

204204
-- At the time of writing, it wasn't clear if this should be a bot instead.
@@ -223,8 +223,8 @@ testRemoveMemberInO2O = do
223223
getMLSOne2OneConversation bob alice >>= assertSuccess
224224
Internal.getConversation personalConvId >>= assertSuccess
225225

226-
testRemoveMemberInTeamConversation :: (HasCallStack) => App ()
227-
testRemoveMemberInTeamConversation = do
226+
testRemoveCollaboratorInTeamConversation :: (HasCallStack) => App ()
227+
testRemoveCollaboratorInTeamConversation = do
228228
(owner, team, [alice, bob]) <- createTeam OwnDomain 3
229229

230230
conv <-
@@ -233,7 +233,7 @@ testRemoveMemberInTeamConversation = do
233233
defProteus {team = Just team, qualifiedUsers = [alice, bob]}
234234
>>= getJSON 201
235235

236-
withWebSockets [owner, alice] $ \[wsOwner, wsAlice] -> do
236+
withWebSockets [owner, alice, bob] $ \[wsOwner, wsAlice, wsBob] -> do
237237
removeTeamCollaborator owner team bob >>= assertSuccess
238238

239239
bobUnqualifiedId <- bob %. "qualified_id.id"
@@ -244,6 +244,7 @@ testRemoveMemberInTeamConversation = do
244244
evt %. "transient" `shouldMatch` True
245245

246246
awaitMatch isTeamMemberLeaveNotif wsOwner >>= checkEvent
247+
awaitMatch isTeamMemberLeaveNotif wsBob >>= checkEvent
247248
assertNoEvent 0 wsAlice
248249

249250
getConversation alice conv `bindResponse` \resp -> do

libs/wire-api/src/Wire/API/Routes/Public/Galley/TeamMember.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ type TeamMemberAPI =
210210
:<|> Named
211211
"remove-team-collaborator"
212212
( Summary "Remove a collaborator from the team."
213-
:> From 'V11
213+
:> From 'V12
214214
:> ZLocalUser
215215
:> "teams"
216216
:> Capture "tid" TeamId

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

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -933,32 +933,31 @@ removeFromConvsAndPushConvLeaveEvent lusr zcon tid remove = do
933933
for_ cc $ \c ->
934934
E.getConversation c >>= \conv ->
935935
for_ conv $ \dc ->
936-
case () of
937-
_
938-
| dc.metadata.cnvmType == One2OneConv ->
939-
E.deleteConversation dc.id_
940-
| otherwise ->
941-
when (remove `isMember` dc.localMembers) $ do
942-
E.deleteMembers c (UserList [remove] [])
943-
let (bots, allLocUsers) = localBotsAndUsers (dc.localMembers)
944-
targets =
945-
BotsAndMembers
946-
(Set.fromList $ (.id_) <$> allLocUsers)
947-
(Set.fromList $ (.id_) <$> dc.remoteMembers)
948-
(Set.fromList bots)
949-
void $
950-
notifyConversationAction
951-
(sing @'ConversationRemoveMembersTag)
952-
(tUntagged lusr)
953-
True
954-
zcon
955-
(qualifyAs lusr dc)
956-
targets
957-
( ConversationRemoveMembers
958-
(pure . tUntagged . qualifyAs lusr $ remove)
959-
EdReasonDeleted
960-
)
961-
def
936+
case dc.metadata.cnvmType of
937+
One2OneConv ->
938+
E.deleteConversation dc.id_
939+
_ ->
940+
when (remove `isMember` dc.localMembers) $ do
941+
E.deleteMembers c (UserList [remove] [])
942+
let (bots, allLocUsers) = localBotsAndUsers (dc.localMembers)
943+
targets =
944+
BotsAndMembers
945+
(Set.fromList $ (.id_) <$> allLocUsers)
946+
(Set.fromList $ (.id_) <$> dc.remoteMembers)
947+
(Set.fromList bots)
948+
void $
949+
notifyConversationAction
950+
(sing @'ConversationRemoveMembersTag)
951+
(tUntagged lusr)
952+
True
953+
zcon
954+
(qualifyAs lusr dc)
955+
targets
956+
( ConversationRemoveMembers
957+
(pure . tUntagged . qualifyAs lusr $ remove)
958+
EdReasonDeleted
959+
)
960+
def
962961

963962
getTeamConversations ::
964963
( Member (ErrorS 'NotATeamMember) r,
@@ -1343,6 +1342,15 @@ removeTeamCollaborator lusr tid rusr = do
13431342
. (.status)
13441343
uncheckedDeleteTeamMember lusr Nothing tid rusr toNotify
13451344
internalRemoveTeamCollaborator rusr tid
1345+
now <- Now.get
1346+
let e = newEvent tid now (EdCollaboratorRemove rusr)
1347+
pushNotifications
1348+
[ def
1349+
{ origin = Just $ tUnqualified lusr,
1350+
json = toJSONObject e,
1351+
recipients = [userRecipient $ tUnqualified lusr]
1352+
}
1353+
]
13461354
where
13471355
-- The @'NotATeamMember@ and @'TeamNotFound@ errors cannot happen at this
13481356
-- point: the user is a team member because we fetched the list of teams

0 commit comments

Comments
 (0)