core: batch apis - remove, block, change role of members (#5674)

* core: core: batch remove members

* order

* foldr

* list

* style

* batch block

* change role

* test

* if
This commit is contained in:
spaced4ndy authored and GitHub committed 2025-02-28 18:43:39 +00:00
1 parent dce8502165
commit dcea008fb9
10 files changed
+320 -162

No files matched your search

+11 -11
View File
@@ -122,7 +122,7 @@ testDirectoryService ps =
bob <# "SimpleX-Directory> You must grant directory service admin role to register the group"
bob ##> "/mr PSA SimpleX-Directory admin"
-- putStrLn "*** discover service joins group and creates the link for profile"
bob <## "#PSA: you changed the role of SimpleX-Directory from member to admin"
bob <## "#PSA: you changed the role of SimpleX-Directory to admin"
bob <# "SimpleX-Directory> Joining the group PSA…"
bob <## "#PSA: SimpleX-Directory joined the group"
bob <# "SimpleX-Directory> Joined the group PSA, creating the link…"
@@ -579,7 +579,7 @@ testDelistedRoleChanges ps =
groupFoundN 3 cath "privacy"
-- de-listed if service role changed
bob ##> "/mr privacy SimpleX-Directory member"
bob <## "#privacy: you changed the role of SimpleX-Directory from admin to member"
bob <## "#privacy: you changed the role of SimpleX-Directory to member"
cath <## "#privacy: bob changed the role of SimpleX-Directory from admin to member"
bob <# "SimpleX-Directory> SimpleX-Directory role in the group ID 1 (privacy) is changed to member."
bob <## ""
@@ -588,7 +588,7 @@ testDelistedRoleChanges ps =
groupNotFound cath "privacy"
-- re-listed if service role changed back without profile changes
cath ##> "/mr privacy SimpleX-Directory admin"
cath <## "#privacy: you changed the role of SimpleX-Directory from member to admin"
cath <## "#privacy: you changed the role of SimpleX-Directory to admin"
bob <## "#privacy: cath changed the role of SimpleX-Directory from member to admin"
bob <# "SimpleX-Directory> SimpleX-Directory role in the group ID 1 (privacy) is changed to admin."
bob <## ""
@@ -597,7 +597,7 @@ testDelistedRoleChanges ps =
groupFoundN 3 cath "privacy"
-- de-listed if owner role changed
cath ##> "/mr privacy bob admin"
cath <## "#privacy: you changed the role of bob from owner to admin"
cath <## "#privacy: you changed the role of bob to admin"
bob <## "#privacy: cath changed your role from owner to admin"
bob <# "SimpleX-Directory> Your role in the group ID 1 (privacy) is changed to admin."
bob <## ""
@@ -606,7 +606,7 @@ testDelistedRoleChanges ps =
groupNotFound cath "privacy"
-- re-listed if owner role changed back without profile changes
cath ##> "/mr privacy bob owner"
cath <## "#privacy: you changed the role of bob from admin to owner"
cath <## "#privacy: you changed the role of bob to owner"
bob <## "#privacy: cath changed your role from admin to owner"
bob <# "SimpleX-Directory> Your role in the group ID 1 (privacy) is changed to owner."
bob <## ""
@@ -627,7 +627,7 @@ testNotDelistedMemberRoleChanged ps =
cath <## "use @SimpleX-Directory <message> to send messages"
groupFoundN 3 cath "privacy"
bob ##> "/mr privacy cath member"
bob <## "#privacy: you changed the role of cath from owner to member"
bob <## "#privacy: you changed the role of cath to member"
cath <## "#privacy: bob changed your role from owner to member"
groupFoundN 3 cath "privacy"
@@ -641,11 +641,11 @@ testNotSentApprovalBadRoles ps =
submitGroup bob "privacy" "Privacy"
welcomeWithLink <- groupAccepted bob "privacy"
bob ##> "/mr privacy SimpleX-Directory member"
bob <## "#privacy: you changed the role of SimpleX-Directory from admin to member"
bob <## "#privacy: you changed the role of SimpleX-Directory to member"
updateProfileWithLink bob "privacy" welcomeWithLink 1
bob <# "SimpleX-Directory> You must grant directory service admin role to register the group"
bob ##> "/mr privacy SimpleX-Directory admin"
bob <## "#privacy: you changed the role of SimpleX-Directory from member to admin"
bob <## "#privacy: you changed the role of SimpleX-Directory to admin"
bob <# "SimpleX-Directory> SimpleX-Directory role in the group ID 1 (privacy) is changed to admin."
bob <## ""
bob <## "The group is submitted for approval."
@@ -666,14 +666,14 @@ testNotApprovedBadRoles ps =
updateProfileWithLink bob "privacy" welcomeWithLink 1
notifySuperUser superUser bob "privacy" "Privacy" welcomeWithLink 1
bob ##> "/mr privacy SimpleX-Directory member"
bob <## "#privacy: you changed the role of SimpleX-Directory from admin to member"
bob <## "#privacy: you changed the role of SimpleX-Directory to member"
let approve = "/approve 1:privacy 1"
superUser #> ("@SimpleX-Directory " <> approve)
superUser <# ("SimpleX-Directory> > " <> approve)
superUser <## " Group is not approved: SimpleX-Directory is not an admin."
groupNotFound cath "privacy"
bob ##> "/mr privacy SimpleX-Directory admin"
bob <## "#privacy: you changed the role of SimpleX-Directory from member to admin"
bob <## "#privacy: you changed the role of SimpleX-Directory to admin"
bob <# "SimpleX-Directory> SimpleX-Directory role in the group ID 1 (privacy) is changed to admin."
bob <## ""
bob <## "The group is submitted for approval."
@@ -940,7 +940,7 @@ testListUserGroups ps =
-- with de-listed group
groupFound cath "anonymity"
cath ##> "/mr anonymity SimpleX-Directory member"
cath <## "#anonymity: you changed the role of SimpleX-Directory from admin to member"
cath <## "#anonymity: you changed the role of SimpleX-Directory to member"
cath <# "SimpleX-Directory> SimpleX-Directory role in the group ID 1 (anonymity) is changed to member."
cath <## ""
cath <## "The group is no longer listed in the directory."
+100 -35
View File
@@ -173,7 +173,8 @@ chatGroupTests = do
it "messages are fully deleted" testBlockForAllFullDelete
it "another admin can unblock" testBlockForAllAnotherAdminUnblocks
it "member was blocked before joining group" testBlockForAllBeforeJoining
it "can't repeat block, unblock" testBlockForAllCantRepeat
it "repeat block, unblock" testBlockForAllRepeat
it "block multiple members" testBlockForAllMultipleMembers
describe "group member inactivity" $ do
it "mark member inactive on reaching quota" testGroupMemberInactive
describe "group member reports" $ do
@@ -265,7 +266,7 @@ testGroupShared alice bob cath checkMessages = do
-- test observer role
alice ##> "/mr team bob observer"
concurrentlyN_
[ alice <## "#team: you changed the role of bob from admin to observer",
[ alice <## "#team: you changed the role of bob to observer",
bob <## "#team: alice changed your role from admin to observer",
cath <## "#team: alice changed the role of bob from admin to observer"
]
@@ -280,7 +281,7 @@ testGroupShared alice bob cath checkMessages = do
]
alice ##> "/mr team bob admin"
concurrentlyN_
[ alice <## "#team: you changed the role of bob from observer to admin",
[ alice <## "#team: you changed the role of bob to admin",
bob <## "#team: alice changed your role from observer to admin",
cath <## "#team: alice changed the role of bob from observer to admin"
]
@@ -1460,7 +1461,7 @@ testUpdateMemberRole =
alice <## "to add members use /a team <name> or /create link #team"
addMember "team" alice bob GRAdmin
alice ##> "/mr team bob member"
alice <## "#team: you changed the role of bob from admin to member"
alice <## "#team: you changed the role of bob to member"
bob <## "#team: alice invites you to join the group as member"
bob <## "use /j team to accept"
bob ##> "/j team"
@@ -1472,7 +1473,7 @@ testUpdateMemberRole =
bob <## "#team: you have insufficient permissions for this action, the required role is admin"
alice ##> "/mr team bob admin"
concurrently_
(alice <## "#team: you changed the role of bob from member to admin")
(alice <## "#team: you changed the role of bob to admin")
(bob <## "#team: alice changed your role from member to admin")
bob ##> "/a team cath owner"
bob <## "#team: you have insufficient permissions for this action, the required role is owner"
@@ -1488,13 +1489,7 @@ testUpdateMemberRole =
alice <## "#team: new member cath is connected"
]
alice ##> "/mr team alice admin"
concurrentlyN_
[ alice <## "#team: you changed your role from owner to admin",
bob <## "#team: alice changed the role from owner to admin",
cath <## "#team: alice changed the role from owner to admin"
]
alice ##> "/d #team"
alice <## "#team: you have insufficient permissions for this action, the required role is owner"
alice <## "bad chat command: can't change role for self"
testGroupDescription :: HasCallStack => TestParams -> IO ()
testGroupDescription = testChat4 aliceProfile bobProfile cathProfile danProfile $ \alice bob cath dan -> do
@@ -1579,7 +1574,7 @@ testGroupModerate =
-- disableFullDeletion3 "team" alice bob cath
alice ##> "/mr team cath member"
concurrentlyN_
[ alice <## "#team: you changed the role of cath from admin to member",
[ alice <## "#team: you changed the role of cath to member",
bob <## "#team: alice changed the role of cath from admin to member",
cath <## "#team: alice changed your role from admin to member"
]
@@ -1662,7 +1657,7 @@ testGroupModerateFullDelete =
-- disableFullDeletion3 "team" alice bob cath
alice ##> "/mr team cath member"
concurrentlyN_
[ alice <## "#team: you changed the role of cath from admin to member",
[ alice <## "#team: you changed the role of cath to member",
bob <## "#team: alice changed the role of cath from admin to member",
cath <## "#team: alice changed your role from admin to member"
]
@@ -2691,7 +2686,7 @@ testGroupLinkMemberRole =
bob <## "#team: you don't have permission to send messages"
alice ##> "/mr #team bob member"
alice <## "#team: you changed the role of bob from observer to member"
alice <## "#team: you changed the role of bob to member"
bob <## "#team: alice changed your role from observer to member"
bob #> "#team hey now"
@@ -2721,7 +2716,7 @@ testGroupLinkMemberRole =
cath <## "#team: you don't have permission to send messages"
alice ##> "/mr #team cath admin"
alice <## "#team: you changed the role of cath from observer to admin"
alice <## "#team: you changed the role of cath to admin"
cath <## "#team: alice changed your role from observer to admin"
bob <## "#team: alice changed the role of cath from observer to admin"
@@ -2730,7 +2725,7 @@ testGroupLinkMemberRole =
bob <# "#team cath> hey"
cath ##> "/mr #team bob admin"
cath <## "#team: you changed the role of bob from member to admin"
cath <## "#team: you changed the role of bob to admin"
bob <## "#team: cath changed your role from member to admin"
alice <## "#team: cath changed the role of bob from member to admin"
@@ -4132,14 +4127,14 @@ testGroupMsgForwardReport =
alice ##> "/mr team bob moderator"
concurrentlyN_
[ alice <## "#team: you changed the role of bob from admin to moderator",
[ alice <## "#team: you changed the role of bob to moderator",
bob <## "#team: alice changed your role from admin to moderator",
cath <## "#team: alice changed the role of bob from admin to moderator"
]
alice ##> "/mr team cath member"
concurrentlyN_
[ alice <## "#team: you changed the role of cath from admin to member",
[ alice <## "#team: you changed the role of cath to member",
bob <## "#team: alice changed the role of cath from admin to member",
cath <## "#team: alice changed your role from admin to member"
]
@@ -4157,7 +4152,7 @@ testGroupMsgForwardReport =
alice ##> "/mr team bob member"
concurrentlyN_
[ alice <## "#team: you changed the role of bob from moderator to member",
[ alice <## "#team: you changed the role of bob to member",
bob <## "#team: alice changed your role from moderator to member",
cath <## "#team: alice changed the role of bob from moderator to member"
]
@@ -4315,7 +4310,7 @@ testGroupMsgForwardChangeRole =
setupGroupForwarding3 "team" alice bob cath
cath ##> "/mr #team bob member"
cath <## "#team: you changed the role of bob from admin to member"
cath <## "#team: you changed the role of bob to member"
alice <## "#team: cath changed the role of bob from admin to member"
bob <## "#team: cath changed your role from admin to member" -- TODO show as forwarded
@@ -5942,19 +5937,13 @@ testBlockForAllBeforeJoining =
cc <## "#team: alice added dan (Daniel) to the group (connecting...)"
cc <## "#team: new member dan is connected"
testBlockForAllCantRepeat :: HasCallStack => TestParams -> IO ()
testBlockForAllCantRepeat =
testBlockForAllRepeat :: HasCallStack => TestParams -> IO ()
testBlockForAllRepeat =
testChat3 aliceProfile bobProfile cathProfile $
\alice bob cath -> do
createGroup3 "team" alice bob cath
-- disableFullDeletion3 "team" alice bob cath
alice ##> "/unblock for all #team bob"
alice <## "bad chat command: already unblocked"
cath ##> "/unblock for all #team bob"
cath <## "bad chat command: already unblocked"
bob #> "#team 1"
[alice, cath] *<# "#team bob> 1"
@@ -5964,10 +5953,10 @@ testBlockForAllCantRepeat =
bob <// 50000
alice ##> "/block for all #team bob"
alice <## "bad chat command: already blocked"
alice <## "#team: you blocked bob"
cath ##> "/block for all #team bob"
cath <## "bad chat command: already blocked"
cath <## "#team: you blocked bob"
bob #> "#team 2"
alice <# "#team bob> 2 [blocked by admin] <muted>"
@@ -5979,16 +5968,92 @@ testBlockForAllCantRepeat =
bob <// 50000
alice ##> "/unblock for all #team bob"
alice <## "bad chat command: already unblocked"
alice <## "#team: you unblocked bob"
cath ##> "/unblock for all #team bob"
cath <## "bad chat command: already unblocked"
cath <## "#team: you unblocked bob"
bob #> "#team 3"
[alice, cath] *<# "#team bob> 3"
bob #$> ("/_get chat #1 count=3", chat, [(1, "1"), (1, "2"), (1, "3")])
testBlockForAllMultipleMembers :: HasCallStack => TestParams -> IO ()
testBlockForAllMultipleMembers =
testChat4 aliceProfile bobProfile cathProfile danProfile $
\alice bob cath dan -> do
createGroup3 "team" alice bob cath
connectUsers alice dan
addMember "team" alice dan GRMember
dan ##> "/j team"
concurrentlyN_
[ alice <## "#team: dan joined the group",
do
dan <## "#team: you joined the group"
dan
<### [ "#team: member bob (Bob) is connected",
"#team: member cath (Catherine) is connected"
],
do
bob <## "#team: alice added dan (Daniel) to the group (connecting...)"
bob <## "#team: new member dan is connected",
do
cath <## "#team: alice added dan (Daniel) to the group (connecting...)"
cath <## "#team: new member dan is connected"
]
-- lower roles to for batch block to be allowed (can't batch block if admins are selected)
alice ##> "/mr team bob member"
concurrentlyN_
[ alice <## "#team: you changed the role of bob to member",
bob <## "#team: alice changed your role from admin to member",
cath <## "#team: alice changed the role of bob from admin to member",
dan <## "#team: alice changed the role of bob from admin to member"
]
alice ##> "/mr team cath member"
concurrentlyN_
[ alice <## "#team: you changed the role of cath to member",
bob <## "#team: alice changed the role of cath from admin to member",
cath <## "#team: alice changed your role from admin to member",
dan <## "#team: alice changed the role of cath from admin to member"
]
bob #> "#team 1"
[alice, cath, dan] *<# "#team bob> 1"
cath #> "#team 2"
[alice, bob, dan] *<# "#team cath> 2"
alice ##> "/_block #1 2,3 blocked=on"
alice <## "#team: you blocked 2 members"
dan <## "#team: alice blocked bob"
dan <## "#team: alice blocked cath"
bob <// 50000
cath <// 50000
-- bob and cath don't know they are blocked and receive each other's messages
bob #> "#team 3"
[alice, dan] *<# "#team bob> 3 [blocked by admin] <muted>"
cath <# "#team bob> 3"
cath #> "#team 4"
[alice, dan] *<# "#team cath> 4 [blocked by admin] <muted>"
bob <# "#team cath> 4"
alice ##> "/_block #1 2,3 blocked=off"
alice <## "#team: you unblocked 2 members"
dan <## "#team: alice unblocked bob"
dan <## "#team: alice unblocked cath"
bob <// 50000
cath <// 50000
bob #> "#team 5"
[alice, cath, dan] *<# "#team bob> 5"
cath #> "#team 6"
[alice, bob, dan] *<# "#team cath> 6"
testGroupMemberInactive :: HasCallStack => TestParams -> IO ()
testGroupMemberInactive ps = do
withSmpServer' serverCfg' $ do
@@ -6067,13 +6132,13 @@ testGroupMemberReports =
-- disableFullDeletion3 "jokes" alice bob cath
alice ##> "/mr jokes bob moderator"
concurrentlyN_
[ alice <## "#jokes: you changed the role of bob from admin to moderator",
[ alice <## "#jokes: you changed the role of bob to moderator",
bob <## "#jokes: alice changed your role from admin to moderator",
cath <## "#jokes: alice changed the role of bob from admin to moderator"
]
alice ##> "/mr jokes cath member"
concurrentlyN_
[ alice <## "#jokes: you changed the role of cath from admin to member",
[ alice <## "#jokes: you changed the role of cath to member",
bob <## "#jokes: alice changed the role of cath from admin to member",
cath <## "#jokes: alice changed your role from admin to member"
]
+1 -1
View File
@@ -773,7 +773,7 @@ testBusinessUpdateProfiles = withTestOutput $ testChat4 businessProfile alicePro
biz <# "#alisa alisa_1> hello again"
-- customer can invite members too, if business allows
biz ##> "/mr alisa alisa_1 admin"
biz <## "#alisa: you changed the role of alisa_1 from member to admin"
biz <## "#alisa: you changed the role of alisa_1 to admin"
alice <## "#biz: biz_1 changed your role from member to admin"
connectUsers alice bob
alice ##> "/a #biz bob"