feat(api): org-owner-gated self-serve workspace deletion (#265)#266
Conversation
DELETE /v1/workspaces/:name and POST /v1/workspaces/:name/restore now authorize the record creator OR the org owner (not admin) of that workspace, so an owner who didn't personally create the workspace can still delete/restore it. Session-only (workspace:manage bearer tokens still cannot reach this path), selfServe===true is still required, and all #248/#260 guards are untouched.
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
uploads-api | 96fc312 | Commit Preview URL Branch Preview URL |
Jul 18 2026, 09:58 PM |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughSelf-serve workspace deletion and restoration now allow either the record creator or the workspace organization’s ChangesSelf-serve authorization
Sequence Diagram(s)sequenceDiagram
participant Session
participant WorkspaceRoute
participant isWorkspaceOwner
participant myWorkspaces
Session->>WorkspaceRoute: DELETE or restore workspace
WorkspaceRoute->>isWorkspaceOwner: check organization owner role
isWorkspaceOwner->>myWorkspaces: resolve workspace memberships
myWorkspaces-->>isWorkspaceOwner: workspace role
isWorkspaceOwner-->>WorkspaceRoute: owner status
WorkspaceRoute-->>Session: authorize or return not_owner
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Implements #265: extends the self-serve workspace deletion/restore gate from creator-only to creator OR org
owner, closing the gap where an org owner couldn't delete a workspace whose creator had left or handed over ownership.What changed
loadOwnedSelfServeRecord(apps/api/src/routes/workspaces.ts) now authorizesDELETE /v1/workspaces/:nameandPOST /v1/workspaces/:name/restore(same helper, identical gating) when the session user is the record creator or holds org roleownerin that workspace's org — resolved via the same per-workspace membership lookup as the Workspace-governance token scopes for the org-admin tier (workspace:invite / workspace:manage) #262 gates.owneronly, notadmin: deletion is the most destructive governance action, so it sits above the invite/token powers the admin role gained in feat(api): workspace-governance token scopes for the org-admin tier (#262) #264.docs/deletion.mdupdated from creator-only to creator-or-owner language.Deliberately unchanged
workspace:managebearer tokens still cannot delete (pinned by a real-token 401 test) — soft deletion stays an interactive, attributable action.selfServe === truestill required; non-self-serve workspaces stay undeletable on this surface regardless of role./admin/workspaces/:namesurface).apps/authuntouched.Testing
pnpm --filter api test: 51 files / 572 tests passing;tsc --noEmitclean. New coverage: owner (non-creator) delete + restore, org admin 403, plain member 403, platform admin without org role 403, creator unchanged, non-self-serve blocked even for owner,workspace:managetoken 401.Closes #265
Summary by CodeRabbit
New Features
Bug Fixes
Documentation