openwisp / openwisp/openwisp-users

[feature] Add dedicated REST API endpoints for managing user organization memberships

Open
#543 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
179
Forks
96
Avg merge
13h 40m
Merged PRs (30d)
16

Description

Is your feature request related to a problem? Please describe.

Currently, there is no dedicated REST API endpoint to manage organization memberships (add, remove, or modify). Users must be added/modified through the superuser user detail endpoint (PUT /api/v1/users/user/{id}/), and removal requires changing the is_admin value in a way that is undocumented and unintuitive.

Describe the solution you'd like

Add dedicated REST API endpoints to manage organization membership:

  • GET /api/v1/users/user/{user_id}/organization-membership/
  • POST /api/v1/users/user/{user_id}/organization-membership/
  • PUT/PATCH /api/v1/users/user/{user_id}/organization-membership/{org_id}/
  • DELETE /api/v1/users/user/{user_id}/organization-membership/{org_id}/

Both approaches should support proper permission checks (organization managers, superusers only).

Describe alternatives you've considered

  1. Continue using the indirect approach via the user detail endpoint with undocumented behavior
  2. Document the existing behavior (changing is_admin to same value deletes membership) and consider it sufficient

Additional context

Current Issues:

  • No clear way to remove a user from an organization via REST API
  • The workaround (sending same is_admin value to delete) is undocumented and counter-intuitive
  • Only superusers can manage memberships through the current endpoint
  • Missing organization manager permissions checks for membership management
  • The OrganizationUserSerializer exists in the codebase but is only used internally in the superuser serializer

Benefits:

  • Clearer, more intuitive API for organization membership management
  • Better permission control (allow org managers to manage memberships)
  • Improved documentation and discoverability
  • Consistency with REST API best practices
  • Enables programmatic management of organization memberships

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the existing superuser user detail endpoint and the OrganizationUserSerializer, which currently is used internally in the superuser serializer. Define the GET, POST, PUT/PATCH, and DELETE organization-membership endpoints and their organization-manager and superuser permission behavior. Done means memberships can be listed, added, modified, and removed through the documented REST API.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
api, authorization, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.