mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
core: initial group member role when joining via link (#1975)
* core: initial group member role when joining via link * fix tests * set role when joining group via link, enable observer test * show group link when role changes * amend test * check role is member or observer when creating a link
This commit is contained in:
+97
-31
@@ -46,6 +46,7 @@ chatGroupTests = do
|
||||
it "create group link, join via group link - incognito membership" testGroupLinkIncognitoMembership
|
||||
it "unused host contact is deleted after all groups with it are deleted" testGroupLinkUnusedHostContactDeleted
|
||||
it "leaving groups with unused host contacts deletes incognito profiles" testGroupLinkIncognitoUnusedHostContactsDeleted
|
||||
it "group link member role" testGroupLinkMemberRole
|
||||
|
||||
testGroup :: HasCallStack => SpecWith FilePath
|
||||
testGroup = versionTestMatrix3 runTestGroup
|
||||
@@ -127,28 +128,27 @@ testGroupShared alice bob cath checkMessages = do
|
||||
alice <## "bob (Bob)"
|
||||
alice <## "cath (Catherine)"
|
||||
-- test observer role
|
||||
-- to be enabled once the role is enabled in parser
|
||||
-- alice ##> "/mr team bob observer"
|
||||
-- concurrentlyN_
|
||||
-- [ alice <## "#team: you changed the role of bob from admin to observer",
|
||||
-- bob <## "#team: alice changed your role from admin to observer",
|
||||
-- cath <## "#team: alice changed the role of bob from admin to observer"
|
||||
-- ]
|
||||
-- bob ##> "#team hello"
|
||||
-- bob <## "#team: you don't have permission to send messages to this group"
|
||||
-- bob ##> "/rm team cath"
|
||||
-- bob <## "#team: you have insufficient permissions for this action, the required role is admin"
|
||||
-- cath #> "#team hello"
|
||||
-- concurrentlyN_
|
||||
-- [ alice <# "#team cath> hello",
|
||||
-- bob <# "#team cath> hello"
|
||||
-- ]
|
||||
-- alice ##> "/mr team bob admin"
|
||||
-- concurrentlyN_
|
||||
-- [ alice <## "#team: you changed the role of bob from observer to admin",
|
||||
-- bob <## "#team: alice changed your role from observer to admin",
|
||||
-- cath <## "#team: alice changed the role of bob from observer to admin"
|
||||
-- ]
|
||||
alice ##> "/mr team bob observer"
|
||||
concurrentlyN_
|
||||
[ alice <## "#team: you changed the role of bob from admin to observer",
|
||||
bob <## "#team: alice changed your role from admin to observer",
|
||||
cath <## "#team: alice changed the role of bob from admin to observer"
|
||||
]
|
||||
bob ##> "#team hello"
|
||||
bob <## "#team: you don't have permission to send messages"
|
||||
bob ##> "/rm team cath"
|
||||
bob <## "#team: you have insufficient permissions for this action, the required role is admin"
|
||||
cath #> "#team hello"
|
||||
concurrentlyN_
|
||||
[ alice <# "#team cath> hello",
|
||||
bob <# "#team cath> hello"
|
||||
]
|
||||
alice ##> "/mr team bob admin"
|
||||
concurrentlyN_
|
||||
[ alice <## "#team: you changed the role of bob from observer to admin",
|
||||
bob <## "#team: alice changed your role from observer to admin",
|
||||
cath <## "#team: alice changed the role of bob from observer to admin"
|
||||
]
|
||||
-- remove member
|
||||
bob ##> "/rm team cath"
|
||||
concurrentlyN_
|
||||
@@ -1423,14 +1423,14 @@ testGroupLink =
|
||||
alice ##> "/show link #team"
|
||||
alice <## "no group link, to create: /create link #team"
|
||||
alice ##> "/create link #team"
|
||||
_ <- getGroupLink alice "team" True
|
||||
_ <- getGroupLink alice "team" GRMember True
|
||||
alice ##> "/delete link #team"
|
||||
alice <## "Group link is deleted - joined members will remain connected."
|
||||
alice <## "To create a new group link use /create link #team"
|
||||
alice ##> "/create link #team"
|
||||
gLink <- getGroupLink alice "team" True
|
||||
gLink <- getGroupLink alice "team" GRMember True
|
||||
alice ##> "/show link #team"
|
||||
_ <- getGroupLink alice "team" False
|
||||
_ <- getGroupLink alice "team" GRMember False
|
||||
alice ##> "/create link #team"
|
||||
alice <## "you already have link for this group, to show: /show link #team"
|
||||
bob ##> ("/c " <> gLink)
|
||||
@@ -1522,7 +1522,7 @@ testGroupLinkDeleteGroupRejoin =
|
||||
alice <## "group #team is created"
|
||||
alice <## "to add members use /a team <name> or /create link #team"
|
||||
alice ##> "/create link #team"
|
||||
gLink <- getGroupLink alice "team" True
|
||||
gLink <- getGroupLink alice "team" GRMember True
|
||||
bob ##> ("/c " <> gLink)
|
||||
bob <## "connection request sent!"
|
||||
alice <## "bob (Bob): accepting request to join group #team..."
|
||||
@@ -1578,7 +1578,7 @@ testGroupLinkContactUsed =
|
||||
alice <## "group #team is created"
|
||||
alice <## "to add members use /a team <name> or /create link #team"
|
||||
alice ##> "/create link #team"
|
||||
gLink <- getGroupLink alice "team" True
|
||||
gLink <- getGroupLink alice "team" GRMember True
|
||||
bob ##> ("/c " <> gLink)
|
||||
bob <## "connection request sent!"
|
||||
alice <## "bob (Bob): accepting request to join group #team..."
|
||||
@@ -1638,7 +1638,7 @@ testGroupLinkIncognitoMembership =
|
||||
(bob <## ("#team: you joined the group incognito as " <> bobIncognito))
|
||||
-- bob creates group link, cath joins
|
||||
bob ##> "/create link #team"
|
||||
gLink <- getGroupLink bob "team" True
|
||||
gLink <- getGroupLink bob "team" GRMember True
|
||||
cath ##> ("/c " <> gLink)
|
||||
cath <## "connection request sent!"
|
||||
bob <## "cath (Catherine): accepting request to join group #team..."
|
||||
@@ -1729,7 +1729,7 @@ testGroupLinkUnusedHostContactDeleted =
|
||||
alice <## "group #team is created"
|
||||
alice <## "to add members use /a team <name> or /create link #team"
|
||||
alice ##> "/create link #team"
|
||||
gLinkTeam <- getGroupLink alice "team" True
|
||||
gLinkTeam <- getGroupLink alice "team" GRMember True
|
||||
bob ##> ("/c " <> gLinkTeam)
|
||||
bob <## "connection request sent!"
|
||||
alice <## "bob (Bob): accepting request to join group #team..."
|
||||
@@ -1747,7 +1747,7 @@ testGroupLinkUnusedHostContactDeleted =
|
||||
alice <## "group #club is created"
|
||||
alice <## "to add members use /a club <name> or /create link #club"
|
||||
alice ##> "/create link #club"
|
||||
gLinkClub <- getGroupLink alice "club" True
|
||||
gLinkClub <- getGroupLink alice "club" GRMember True
|
||||
bob ##> ("/c " <> gLinkClub)
|
||||
bob <## "connection request sent!"
|
||||
alice <## "bob_1 (Bob): accepting request to join group #club..."
|
||||
@@ -1822,7 +1822,7 @@ testGroupLinkIncognitoUnusedHostContactsDeleted =
|
||||
alice <## ("group #" <> group <> " is created")
|
||||
alice <## ("to add members use /a " <> group <> " <name> or /create link #" <> group)
|
||||
alice ##> ("/create link #" <> group)
|
||||
gLinkTeam <- getGroupLink alice group True
|
||||
gLinkTeam <- getGroupLink alice group GRMember True
|
||||
bob ##> ("/c " <> gLinkTeam)
|
||||
bobIncognito <- getTermLine bob
|
||||
bob <## "connection request sent incognito!"
|
||||
@@ -1850,3 +1850,69 @@ testGroupLinkIncognitoUnusedHostContactsDeleted =
|
||||
]
|
||||
bob ##> ("/d #" <> group)
|
||||
bob <## ("#" <> group <> ": you deleted the group")
|
||||
|
||||
testGroupLinkMemberRole :: HasCallStack => FilePath -> IO ()
|
||||
testGroupLinkMemberRole =
|
||||
testChat3 aliceProfile bobProfile cathProfile $
|
||||
\alice bob cath -> do
|
||||
alice ##> "/g team"
|
||||
alice <## "group #team is created"
|
||||
alice <## "to add members use /a team <name> or /create link #team"
|
||||
alice ##> "/create link #team admin"
|
||||
alice <## "#team: initial role for group member cannot be admin, use member or observer"
|
||||
alice ##> "/create link #team observer"
|
||||
gLink <- getGroupLink alice "team" GRObserver True
|
||||
bob ##> ("/c " <> gLink)
|
||||
bob <## "connection request sent!"
|
||||
alice <## "bob (Bob): accepting request to join group #team..."
|
||||
concurrentlyN_
|
||||
[ do
|
||||
alice <## "bob (Bob): contact is connected"
|
||||
alice <## "bob invited to group #team via your group link"
|
||||
alice <## "#team: bob joined the group",
|
||||
do
|
||||
bob <## "alice (Alice): contact is connected"
|
||||
bob <## "#team: you joined the group"
|
||||
]
|
||||
alice ##> "/set link role #team admin"
|
||||
alice <## "#team: initial role for group member cannot be admin, use member or observer"
|
||||
alice ##> "/set link role #team member"
|
||||
_ <- getGroupLink alice "team" GRMember False
|
||||
cath ##> ("/c " <> gLink)
|
||||
cath <## "connection request sent!"
|
||||
alice <## "cath (Catherine): accepting request to join group #team..."
|
||||
-- if contact existed it is merged
|
||||
concurrentlyN_
|
||||
[ alice
|
||||
<### [ "cath (Catherine): contact is connected",
|
||||
EndsWith "invited to group #team via your group link",
|
||||
EndsWith "joined the group"
|
||||
],
|
||||
cath
|
||||
<### [ "alice (Alice): contact is connected",
|
||||
"#team: you joined the group",
|
||||
"#team: member bob (Bob) is connected"
|
||||
],
|
||||
do
|
||||
bob <## "#team: alice added cath (Catherine) to the group (connecting...)"
|
||||
bob <## "#team: new member cath is connected"
|
||||
]
|
||||
alice #> "#team hello"
|
||||
concurrently_
|
||||
(bob <# "#team alice> hello")
|
||||
(cath <# "#team alice> hello")
|
||||
cath #> "#team hello too"
|
||||
concurrently_
|
||||
(alice <# "#team cath> hello too")
|
||||
(bob <# "#team cath> hello too")
|
||||
bob ##> "#team hey"
|
||||
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"
|
||||
concurrently_
|
||||
(bob <## "#team: alice changed your role from observer to member")
|
||||
(cath <## "#team: alice changed the role of bob from observer to member")
|
||||
bob #> "#team hey now"
|
||||
concurrently_
|
||||
(alice <# "#team bob> hey now")
|
||||
(cath <# "#team bob> hey now")
|
||||
|
||||
@@ -323,13 +323,13 @@ getContactLink cc created = do
|
||||
cc <## "to delete it: /da (accepted contacts will remain connected)"
|
||||
pure link
|
||||
|
||||
getGroupLink :: HasCallStack => TestCC -> String -> Bool -> IO String
|
||||
getGroupLink cc gName created = do
|
||||
getGroupLink :: HasCallStack => TestCC -> String -> GroupMemberRole -> Bool -> IO String
|
||||
getGroupLink cc gName mRole created = do
|
||||
cc <## if created then "Group link is created!" else "Group link:"
|
||||
cc <## ""
|
||||
link <- getTermLine cc
|
||||
cc <## ""
|
||||
cc <## "Anybody can connect to you and join group with: /c <group_link_above>"
|
||||
cc <## ("Anybody can connect to you and join group as " <> B.unpack (strEncode mRole) <> " with: /c <group_link_above>")
|
||||
cc <## ("to show it again: /show link #" <> gName)
|
||||
cc <## ("to delete it: /delete link #" <> gName <> " (joined members will remain connected to you)")
|
||||
pure link
|
||||
|
||||
Reference in New Issue
Block a user