-
Notifications
You must be signed in to change notification settings - Fork 334
WPB-19712: Allow team admin to update the channels to user-group association #4783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
WPB-19712: Allow team admin to update the channels to user-group association #4783
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just my comments, not all of them might be correct. Otherwise looks good and easy to read and understand.
|
||
type instance MapError 'UserGroupNotATeamAdmin = 'StaticError 403 "user-group-write-forbidden" "Only team admins can create, update, or delete user groups." | ||
|
||
type instance MapError 'UserGroupChannelNotFound = 'StaticError 400 "user-group-channel-not-found" "Specified Channel does not exists or belongs to the team" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this could be a 404.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed, thanks.
lmap | ||
(bimap toUUID (fmap toUUID)) | ||
$ [resultlessStatement| | ||
delete from user_group_channel where user_group_id = ($1 :: uuid) and conv_id <> any($2 :: uuid[]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, testing on postgres console SELECT 1 <> ANY(ARRAY[1, 2, 3]);
gives me true
, so if an existing conversation is in the new set (part of the array) it would be deleted, but it's the other way around we want, don't we? (Unless I'm mistaken on what the logic should be.) Perhaps add this to the test to make sure.
Also, to my brain ... conv_id NOT IN (..new_conv_ids..)
would be easier to read, rather than ... <> any(...)
(but that may be just habit).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's also how my brain works... but not how hasql
encoders work.
I guess it works because there is also an upsert operation following it.
I've tried something else.
); | ||
|
||
|
||
ALTER TABLE public.user_group_member OWNER TO "wire-server"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this row need to be deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped by mistake, thanks.
AddUser gid uid -> addUserImpl gid uid | ||
UpdateUsers gid uids -> updateUsersImpl gid uids | ||
RemoveUser gid uid -> removeUserImpl gid uid | ||
UpdateUserGroupChannels _ gid convIds -> updateUserGroupChannelsImpl gid convIds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe remove the TeamId field as it doesn't seem to be used (?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's used in the Mock
interpreter (it's not a good idea though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is not a good reason to have it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dropped, I was thinking of the subsystem.
AddUser gid uid -> addUserImpl gid uid | ||
UpdateUsers gid uids -> updateUsersImpl gid uids | ||
RemoveUser gid uid -> removeUserImpl gid uid | ||
UpdateUserGroupChannels _ gid convIds -> updateUserGroupChannelsImpl gid convIds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is not a good reason to have it here.
session :: Session () | ||
session = do | ||
statement (gid, convIds) deleteStatement | ||
forM_ convIds $ \convId -> | ||
statement (gid, convId) insertStatement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a transaction.
And maybe it is more efficient to add them with a single insert statement like in insertGroupMembersStatement
? Not sure if it is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aaaah, I have looked for it for so long, thanks, done.
|
||
type instance MapError 'UserGroupNotATeamAdmin = 'StaticError 403 "user-group-write-forbidden" "Only team admins can create, update, or delete user groups." | ||
|
||
type instance MapError 'UserGroupChannelNotFound = 'StaticError 404 "user-group-channel-not-found" "Specified Channel does not exists or belongs to the team" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type instance MapError 'UserGroupChannelNotFound = 'StaticError 404 "user-group-channel-not-found" "Specified Channel does not exists or belongs to the team" | |
type instance MapError 'UserGroupChannelNotFound = 'StaticError 404 "user-group-channel-not-found" "Specified Channel does not exists or does not belong to the team" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
applied (manually)
:<|> Named | ||
"update-user-group-channels" | ||
( Summary "[STUB] Update user group channels. Replaces the channels with the given list." | ||
( Summary "Replaces the channels with the given list." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the possible errors here with CanThrow
decorators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
testUserGroupUpdateChannels :: (HasCallStack) => App () | ||
testUserGroupUpdateChannels = do | ||
(alice, tid, _) <- createTeam OwnDomain 1 | ||
|
||
ug <- | ||
createUserGroup alice (object ["name" .= "none", "members" .= (mempty :: [String])]) | ||
>>= getJSON 200 | ||
gid <- ug %. "id" & asString | ||
|
||
convId <- | ||
postConversation alice (defProteus {team = Just tid}) | ||
>>= getJSON 201 | ||
>>= objConvId | ||
updateUserGroupChannels alice gid [convId.id_] >>= assertSuccess | ||
|
||
bindResponse (getUserGroup alice gid) $ \resp -> do | ||
resp.status `shouldMatchInt` 200 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check that non-admins can't update
non existing user group return 404
check non existing (other team) conversations return error
check maybe also that an empty list removes all users
leave FUTUREWORK to check the actual assiciated channels, once the get feature is implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check maybe also that an empty list removes all users
I'm not sure how to do this: should we track why users have been added to a channel?
Done:
check that non-admins can't update
non existing user group return 404
check non existing (other team) conversations return error
leave FUTUREWORK to check the actual assiciated channels, once the get feature is implemented.
:<|> Named | ||
"update-user-group-channels" | ||
( Summary "[STUB] Update user group channels. Replaces the channels with the given list." | ||
( Summary "Replaces the channels with the given list." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we double check that the payload contains a list of unqualified conv_ids is ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with someone specifically? because we changed back the RFC
updateChannels performer groupId channelIds = do | ||
void $ getUserGroup performer groupId >>= note UserGroupNotFound | ||
teamId <- getTeamAsAdmin performer >>= note UserGroupNotATeamAdmin | ||
traverse_ (getTeamConv performer teamId >=> note UserGroupChannelNotFound) channelIds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
4ed864c
to
909912b
Compare
https://wearezeta.atlassian.net/browse/WPB-19712
Checklist
changelog.d
WIP