Skip to content

feat(api): add endpoint to list current user's workspaces - #9503

Open
Syed-Ali-Abbas-Zaidi wants to merge 2 commits into
makeplane:previewfrom
Syed-Ali-Abbas-Zaidi:feat/9427-list-user-workspaces
Open

feat(api): add endpoint to list current user's workspaces#9503
Syed-Ali-Abbas-Zaidi wants to merge 2 commits into
makeplane:previewfrom
Syed-Ali-Abbas-Zaidi:feat/9427-list-user-workspaces

Conversation

@Syed-Ali-Abbas-Zaidi

@Syed-Ali-Abbas-Zaidi Syed-Ali-Abbas-Zaidi commented Jul 29, 2026

Copy link
Copy Markdown

Description

Adds GET /api/v1/users/me/workspaces/, returning the id, name, and slug of every workspace the authenticated token's user is an active member of, ordered by name.

Today an API token holder has no way to discover their workspace slug programmatically — GET /api/v1/users/me/ returns the profile but nothing lists workspaces, while every other v1 endpoint requires the slug in the path. Integrations, scripts, and MCP servers therefore cannot bootstrap from a token alone and the slug has to be read out of the browser address bar by hand.

Implementation notes:

  • UserWorkspacesEndpoint extends BaseAPIView, so it inherits APIKeyAuthentication + IsAuthenticated; unauthenticated requests are rejected.
  • Scoped to WorkspaceMember rows with is_active=True for request.user, so deactivated memberships and workspaces the user does not belong to are never returned.
  • Reuses the existing WorkspaceLiteSerializer (id, name, slug) — no new serializer, no heavy computed fields.
  • Reads go to the read replica (use_read_replica = True).
  • Documented for OpenAPI via the existing user_docs decorator, so it shows up under the Users tag in the generated schema.

The response is a plain array rather than the cursor-paginated envelope used by the larger list endpoints, matching the other small-collection endpoints in the v1 API. Happy to switch it to self.paginate(...) if maintainers prefer consistency with projects-lite and friends — better to settle that before release than after, since it is a breaking response-shape change.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

N/A — API only.

$ curl -s -H "X-Api-Key: $PLANE_API_KEY" https://api.plane.so/api/v1/users/me/workspaces/
[
  {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "My Workspace",
    "slug": "my-workspace"
  }
]

Test Scenarios

Contract tests added in apps/api/plane/tests/contract/api/test_user_workspaces.py, run via the docker-compose-test.yml stack (docker compose -f docker-compose-test.yml run --rm api-tests pytest plane/tests/contract/api/test_user_workspaces.py) — 6 passed:

  • Returns the workspaces the token's user is an active member of.
  • Returns only the lite fields (id, name, slug) and nothing else.
  • Excludes workspaces the user is not a member of.
  • Excludes workspaces where the user's membership has is_active=False.
  • Excludes soft deleted workspaces even when an active membership row survives.
  • Rejects unauthenticated requests.

Also verified the OpenAPI schema generates cleanly with ENABLE_DRF_SPECTACULAR=1: list_current_user_workspaces appears under the Users tag with the WorkspaceLite array response and the shared 401, and no new generator warnings are introduced.

References

Closes #9427

Summary by CodeRabbit

  • New Features
    • Added GET /api/v1/users/me/workspaces/ to list the authenticated user’s workspaces.
    • Returns only workspaces where the user has an active membership; ordered by name.
    • Excludes workspaces the user isn’t a member of and omits soft-deleted workspaces; returns lite fields (id, name, slug).
    • Added OpenAPI documentation for the new endpoint.
  • Tests
    • Added contract tests covering filtering rules, lite fields, soft-delete behavior, and unauthenticated/unauthorized access (401/403).

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e6481696-68e3-4c99-af06-723934bbbc51

📥 Commits

Reviewing files that changed from the base of the PR and between 204c71f and 10919ec.

📒 Files selected for processing (1)
  • apps/api/plane/tests/contract/api/test_user_workspaces.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/api/plane/tests/contract/api/test_user_workspaces.py

📝 Walkthrough

Walkthrough

Adds GET /api/v1/users/me/workspaces/, returning the authenticated user’s active workspaces with lite fields, ordered by name. The route, view export, OpenAPI documentation, and contract tests are included.

Changes

User workspaces listing

Layer / File(s) Summary
Endpoint implementation and routing
apps/api/plane/api/views/user.py, apps/api/plane/api/views/__init__.py, apps/api/plane/api/urls/user.py
Adds UserWorkspacesEndpoint, filters active memberships, returns serialized workspaces ordered by name, documents the response, and registers the GET route.
Endpoint contract validation
apps/api/plane/tests/contract/api/test_user_workspaces.py
Tests authenticated access, active membership filtering, exclusion of non-members, inactive memberships, and soft-deleted workspaces, plus lite response fields.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant UserWorkspacesEndpoint
  participant WorkspaceMember
  participant Workspace
  Client->>UserWorkspacesEndpoint: GET /api/v1/users/me/workspaces/
  UserWorkspacesEndpoint->>WorkspaceMember: Query active memberships
  WorkspaceMember-->>UserWorkspacesEndpoint: Workspace IDs
  UserWorkspacesEndpoint->>Workspace: Fetch workspaces ordered by name
  Workspace-->>UserWorkspacesEndpoint: Workspace records
  UserWorkspacesEndpoint-->>Client: Return lite workspace list
Loading

Suggested reviewers: dheeru0198

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main change: adding an endpoint for the current user's workspaces.
Description check ✅ Passed The PR description follows the template and fills all required sections with concrete details, tests, and references.
Linked Issues check ✅ Passed #9427 is satisfied: the PR adds a read-only current-user workspaces endpoint returning id, name, and slug.
Out of Scope Changes check ✅ Passed The changes stay focused on the new endpoint, its exports, and contract tests, with no unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/api/plane/api/views/user.py`:
- Around line 83-86: Update the workspace query in the user view to filter
Workspace records with is_active=True in addition to the existing workspace ID
constraint. Keep the active WorkspaceMember filtering and name ordering
unchanged so deactivated workspaces are excluded from the results.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: addc35c4-6c5b-49fb-9545-5c15c7046083

📥 Commits

Reviewing files that changed from the base of the PR and between 15e8357 and 4e3258a.

📒 Files selected for processing (4)
  • apps/api/plane/api/urls/user.py
  • apps/api/plane/api/views/__init__.py
  • apps/api/plane/api/views/user.py
  • apps/api/plane/tests/contract/api/test_user_workspaces.py

Comment thread apps/api/plane/api/views/user.py
@Syed-Ali-Abbas-Zaidi
Syed-Ali-Abbas-Zaidi force-pushed the feat/9427-list-user-workspaces branch from 204c71f to 10919ec Compare July 29, 2026 08:41
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.

[feature]: API endpoint to list workspaces accessible to the current token

1 participant