Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 14, 2025

Overview

This PR implements the ability for organization admins to remove non-admin members from organizations through both the API and the dashboard UI. Only the organization admin can perform member removals, and the admin themselves cannot be removed, ensuring that organizations always maintain at least one administrator.

Changes

Backend

New DELETE Endpoint

  • Added DELETE /v1/organizations/{id}/members/{user_id} endpoint
  • Requires OrganizationsWrite authentication (web_write or organizations_write scope)
  • Admin-only permission: Verifies that the authenticated user is the organization admin before allowing removal
  • Returns HTTP 204 on successful removal
  • Returns HTTP 403 if a non-admin attempts to remove a member
  • Leverages existing remove_member_safe service method with proper validation

Enhanced Member Schema

  • Added user_id field to OrganizationMember schema for member identification
  • Added is_admin boolean field to distinguish organization admins from regular members

Updated Members List Endpoint

  • Modified GET /v1/organizations/{id}/members to populate the is_admin field
  • Determines admin status by checking the organization's account admin

Error Handling

  • Returns 404 if organization not found
  • Returns 404 if user is not a member
  • Returns 403 if a non-admin attempts to remove members
  • Returns 403 if attempting to remove the organization admin

Frontend

UI Components

  • Added "(Admin)" label next to admin users in the members table
  • Added remove button (X icon) for non-admin members in a new actions column
  • Admin-only UI: Remove buttons are only visible to organization admins
  • Admin users do not have a remove button next to their name, providing clear visual indication of their protected status

Confirmation Modal

  • Implemented RemoveMemberModal component with clear warning message
  • Shows the member's email address for confirmation
  • Uses destructive button styling to emphasize the action

User Feedback

  • Toast notifications for successful removal
  • Error toast notifications with descriptive messages for failures (403, 404, network errors)
  • Loading states during async operations

API Integration

  • Created useRemoveOrganizationMember React hook
  • Automatically refreshes member list after successful removal
  • Uses useAuth hook to determine if current user is an admin

Testing

Added comprehensive test coverage in tests/organization/test_endpoints.py:

  • Anonymous user access (401)
  • Non-admin attempting to remove members (403)
  • Non-admin member cannot remove other members (403)
  • Admin can successfully remove members (204)
  • Admin attempting to remove themselves (403)
  • Organization not found (404)

All 41 organization endpoint tests pass successfully.

Screenshots

The UI now displays:

  • A clear "(Admin)" label next to admin users
  • Remove buttons only visible to admins, and only for non-admin members
  • A confirmation modal before removal

Notes

  • The TypeScript API client should be regenerated with pnpm run generate in clients/packages/client when the API server is running to update the generated types with the new user_id and is_admin fields.
  • This implementation restricts member removal to organization admins only, providing proper authorization controls.

This pull request was created as a result of the following prompt from Copilot chat.

Add the ability for organization members (excluding admins) to remove emails (i.e., remove non-admin members) from the organization via the dashboard and API.

Requirements:

  • Backend: Ensure that the endpoint for removing organization members (non-admins) is exposed and documented. The logic should check admin status and prevent the removal of admin users. Ensure appropriate error handling and messaging.
  • Frontend: In the organization members settings/dashboard page, add a "Remove" button next to each non-admin member email. When clicked, it should call the backend to remove the member and update the list in the UI. Provide user feedback (e.g., toast notifications) on success or error. Do not show the remove button for admin users.
  • Cover edge cases, including attempts to remove the admin and attempts to remove a user who is not a member. Ensure the UI reflects these restrictions.
  • Tests: Add/extend tests to verify this new ability in both backend and frontend.

Context from the repo indicates that the backend logic and endpoints exist, but they should be reviewed and exposed appropriately in the dashboard frontend.

Original prompt

Add the ability for organization members (excluding admins) to remove emails (i.e., remove non-admin members) from the organization via the dashboard and API.

Requirements:

  • Backend: Ensure that the endpoint for removing organization members (non-admins) is exposed and documented. The logic should check admin status and prevent the removal of admin users. Ensure appropriate error handling and messaging.
  • Frontend: In the organization members settings/dashboard page, add a "Remove" button next to each non-admin member email. When clicked, it should call the backend to remove the member and update the list in the UI. Provide user feedback (e.g., toast notifications) on success or error. Do not show the remove button for admin users.
  • Cover edge cases, including attempts to remove the admin and attempts to remove a user who is not a member. Ensure the UI reflects these restrictions.
  • Tests: Add/extend tests to verify this new ability in both backend and frontend.

Context from the repo indicates that the backend logic and endpoints exist, but they should be reviewed and exposed appropriately in the dashboard frontend.

This pull request was created as a result of the following prompt from Copilot chat.

Add the ability for organization members (excluding admins) to remove emails (i.e., remove non-admin members) from the organization via the dashboard and API.

Requirements:

  • Backend: Ensure that the endpoint for removing organization members (non-admins) is exposed and documented. The logic should check admin status and prevent the removal of admin users. Ensure appropriate error handling and messaging.
  • Frontend: In the organization members settings/dashboard page, add a "Remove" button next to each non-admin member email. When clicked, it should call the backend to remove the member and update the list in the UI. Provide user feedback (e.g., toast notifications) on success or error. Do not show the remove button for admin users.
  • Cover edge cases, including attempts to remove the admin and attempts to remove a user who is not a member. Ensure the UI reflects these restrictions.
  • Tests: Add/extend tests to verify this new ability in both backend and frontend.

Context from the repo indicates that the backend logic and endpoints exist, but they should be reviewed and exposed appropriately in the dashboard frontend.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@vercel
Copy link

vercel bot commented Oct 14, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
polar Ignored Ignored Preview Oct 15, 2025 8:45am
polar-sandbox Ignored Ignored Preview Oct 15, 2025 8:45am

Copilot AI and others added 4 commits October 14, 2025 09:58
Co-authored-by: rishi-raj-jain <46300090+rishi-raj-jain@users.noreply.github.com>
Co-authored-by: rishi-raj-jain <46300090+rishi-raj-jain@users.noreply.github.com>
Co-authored-by: rishi-raj-jain <46300090+rishi-raj-jain@users.noreply.github.com>
Co-authored-by: rishi-raj-jain <46300090+rishi-raj-jain@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ability for organization members to remove emails Add ability to remove non-admin organization members via dashboard and API Oct 14, 2025
Copilot AI requested a review from rishi-raj-jain October 14, 2025 10:09
Copilot finished work on behalf of rishi-raj-jain October 14, 2025 10:09
@rishi-raj-jain
Copy link
Member

@copilot have you ensured that the removal permission is only with the admin?

Copy link
Contributor Author

Copilot AI commented Oct 15, 2025

@copilot have you ensured that the removal permission is only with the admin?

Currently, any organization member with write permissions (web_write or organizations_write scope) can remove other non-admin members. This follows the same permission model as the existing invite_member endpoint.

The implementation prevents removing the organization admin (returns 403), but doesn't restrict removal to only admins.

Should I change this so that only the organization admin can remove members? Or is the current behavior (any member with write permissions can remove non-admins) acceptable?

Copilot finished work on behalf of rishi-raj-jain October 15, 2025 08:15
@rishi-raj-jain
Copy link
Member

@copilot

Should I change this so that only the organization admin can remove members?

Yes

Co-authored-by: rishi-raj-jain <46300090+rishi-raj-jain@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 15, 2025

@copilot

Should I change this so that only the organization admin can remove members?
...

Done. Changed the implementation so only organization admins can remove members.

Backend changes:

  • Added admin verification in the endpoint to check if the authenticated user is the organization admin
  • Returns 403 if a non-admin attempts to remove a member
  • Commit: f2d1299

Frontend changes:

  • Updated UI to only show remove buttons if the current user is the admin
  • Non-admin members will not see any remove buttons
  • Commit: f2d1299

Test updates:

  • Updated tests to verify non-admin members cannot remove others
  • Added test to verify admin can successfully remove members
  • All 41 organization endpoint tests pass

Copilot AI changed the title Add ability to remove non-admin organization members via dashboard and API Add ability for organization admins to remove non-admin members via dashboard and API Oct 15, 2025
Copilot finished work on behalf of rishi-raj-jain October 15, 2025 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants