Extend the remove-member-from-group API (DELETE /groups/{id}/members/{user}) to allow group members to remove other members (not just themselves) from groups, assuming the authenticated member has the necessary role in the group.
Currently the only valid call to this API is DELETE /groups/{id}/members/me (i.e. {user} is the literal string me) to remove yourself from a group.
While keeping the me alias this PR also enables {user} to be either your own or someone else's userid, and will allow or deny the request according to these rules:
Any group member can remove themselves from a group with either me or their own userid
Only owners can remove other owners and admins
Only owners and admins can remove moderators
Owners, admins and moderators can remove plain members
Plain members, people who aren't members of the group at all, and unauthenticated requests can't remove anyone
Also, it'll 404 if either the group or the target user doesn't exist, or if the target user isn't a member of the group
There's also a separate code path for when the userid is invalid (can't be parsed in acct:{username}@{authority} format), 404s
Extend the remove-member-from-group API (
DELETE /groups/{id}/members/{user}
) to allow group members to remove other members (not just themselves) from groups, assuming the authenticated member has the necessary role in the group.Currently the only valid call to this API is
DELETE /groups/{id}/members/me
(i.e.{user}
is the literal stringme
) to remove yourself from a group.While keeping the
me
alias this PR also enables{user}
to be either your own or someone else's userid, and will allow or deny the request according to these rules:me
or their own useridacct:{username}@{authority}
format), 404sTesting
Test removing yourself
Log in (http://localhost:5000/login)
Generate an API token (http://localhost:5000/account/developer)
Create a group (http://localhost:5000/groups/new)
Remove yourself from the group:
Or with the "me" alias:
If you repeat the same request again you should get a 404 because the membership doesn't exist.
Test an owner removing a plain member
Test that plain members can't remove owners
Test that non-members can't remove members from groups
Test that unauthenticated requests can't remove members from groups