fix: group role change

This commit is contained in:
Paul Bottinelli
2026-06-21 19:40:56 +01:00
committed by Evgeny Poberezkin
parent 9216b983b7
commit 8fcdd1502c
2 changed files with 33 additions and 1 deletions
+1 -1
View File
@@ -3122,7 +3122,7 @@ processAgentMessageConn cxt user@User {userId} corrId agentConnId agentMessage =
where
GroupMember {memberId = membershipMemId} = membership
changeMemberRole gInfo' member@GroupMember {memberRole = fromRole} gEvent
| senderRole < GRAdmin || senderRole < fromRole =
| senderRole < maximum ([GRAdmin, fromRole, memRole] :: [GroupMemberRole]) =
messageError "x.grp.mem.role with insufficient member permissions" $> Nothing
| otherwise = do
withStore' $ \db -> updateGroupMemberRole db user member memRole
+32
View File
@@ -81,6 +81,7 @@ chatGroupTests = do
it "group live message" testGroupLiveMessage
it "update group profile" testUpdateGroupProfile
it "update member role" testUpdateMemberRole
it "check owner role change" testOwnerRoleChange
it "group description is shown as the first message to new members" testGroupDescription
it "moderate message of another group member" testGroupModerate
it "moderate own message (should process as deletion)" testGroupModerateOwn
@@ -1609,6 +1610,37 @@ testUpdateMemberRole =
alice ##> "/mr team alice admin"
alice <## "bad chat command: can't change role for self"
testOwnerRoleChange :: HasCallStack => TestParams -> IO ()
testOwnerRoleChange =
testChat3 aliceProfile bobProfile cathProfile $
\alice bob cath -> do
createGroup3 "team" alice bob cath
void $ withCCTransaction cath $ \db ->
DB.execute_
db
[sql|
UPDATE group_members
SET member_role = 'owner'
WHERE member_category = 'user'
AND group_id IN (
SELECT group_id FROM groups WHERE local_display_name = 'team'
)
|]
cath ##> "/mr #team bob owner"
cath <## "#team: you changed the role of bob to owner"
concurrentlyN_
[ alice <## "error: x.grp.mem.role with insufficient member permissions",
bob <## "error: x.grp.mem.role with insufficient member permissions"
]
bob ##> "/ms team"
bob
<### [ "alice (Alice): owner, host, connected",
"bob (Bob): admin, you, connected",
"cath (Catherine): admin, connected"
]
testGroupDescription :: HasCallStack => TestParams -> IO ()
testGroupDescription = testChat4 aliceProfile bobProfile cathProfile danProfile $ \alice bob cath dan -> do
connectUsers alice bob