hypothesis / h

Annotate with anyone, anywhere.
https://hypothes.is/
BSD 2-Clause "Simplified" License
2.96k stars 427 forks source link

Allow group members to remove other members from groups #9076

Open seanh opened 1 week ago

seanh commented 1 week ago

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:

Testing

Test removing yourself

  1. Log in (http://localhost:5000/login)

  2. Generate an API token (http://localhost:5000/account/developer)

  3. Create a group (http://localhost:5000/groups/new)

  4. Remove yourself from the group:

    httpx http://localhost:5000/api/groups/{pubid}/members/acct:{username}@localhost --method DELETE --headers Authorization 'Bearer {apitoken}'

    Or with the "me" alias:

    httpx http://localhost:5000/api/groups/{pubid}/members/me --method DELETE --headers Authorization 'Bearer {apitoken}'

    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

  1. Log in
  2. Generate an API token
  3. Create a group
  4. Log in as a different user
  5. Join the group
  6. Make an API request as the first user to remove the second user from the group

Test that plain members can't remove owners

  1. Log in
  2. Generate an API token
  3. Create a group
  4. Log in as a different user
  5. Join the group
  6. Make an API request as the second user to remove the first user from the group. You should get a 404

Test that non-members can't remove members from groups

  1. Log in
  2. Generate an API token
  3. Create a group
  4. Make an API request as a different user to remove the user from the group. You should get a 404

Test that unauthenticated requests can't remove members from groups

  1. Log in
  2. Generate an API token
  3. Create a group
  4. Make an API request without an Authorization headerto remove the user from the group. You should get a 404