feat(api): add endpoint to list current user's workspaces - #9503
feat(api): add endpoint to list current user's workspaces#9503Syed-Ali-Abbas-Zaidi wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds ChangesUser workspaces listing
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
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
apps/api/plane/api/urls/user.pyapps/api/plane/api/views/__init__.pyapps/api/plane/api/views/user.pyapps/api/plane/tests/contract/api/test_user_workspaces.py
204c71f to
10919ec
Compare
Description
Adds
GET /api/v1/users/me/workspaces/, returning theid,name, andslugof 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:
UserWorkspacesEndpointextendsBaseAPIView, so it inheritsAPIKeyAuthentication+IsAuthenticated; unauthenticated requests are rejected.WorkspaceMemberrows withis_active=Trueforrequest.user, so deactivated memberships and workspaces the user does not belong to are never returned.WorkspaceLiteSerializer(id,name,slug) — no new serializer, no heavy computed fields.use_read_replica = True).user_docsdecorator, 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 withprojects-liteand friends — better to settle that before release than after, since it is a breaking response-shape change.Type of Change
Screenshots and Media (if applicable)
N/A — API only.
Test Scenarios
Contract tests added in
apps/api/plane/tests/contract/api/test_user_workspaces.py, run via thedocker-compose-test.ymlstack (docker compose -f docker-compose-test.yml run --rm api-tests pytest plane/tests/contract/api/test_user_workspaces.py) — 6 passed:id,name,slug) and nothing else.is_active=False.Also verified the OpenAPI schema generates cleanly with
ENABLE_DRF_SPECTACULAR=1:list_current_user_workspacesappears under the Users tag with theWorkspaceLitearray response and the shared 401, and no new generator warnings are introduced.References
Closes #9427
Summary by CodeRabbit
GET /api/v1/users/me/workspaces/to list the authenticated user’s workspaces.id,name,slug).