mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-07-28 09:59:44 +00:00
fix: group role change
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user