feat(staff): roles, users and role assignment API (#133 slice A) #135
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
primatekuntech/kws!135
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/133-staff-access-api"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Slice A of #133: the admin API for roles, users and role assignment (ADR 0029). Platform scope only; permissions
admin_portal.administration.manage.GET /v1/admin/permissions; roles CRUD/v1/admin/roles[/{id}](caller must hold every permission they grant; create is idempotent; version on update/delete).GET /v1/admin/users[/{id}],PUT /v1/admin/users/{id}/roles(admin_portal only; API-key service users excluded; last Super Admin guard under one advisory lock → 409last_super_admin).POST /v1/admin/users/{id}/deactivate|reactivate(idempotent). Migration 0033:users.deactivated_at/by; audit ofusersexcludes email, display name and last login.Not in this PR: staff invitations by email (slice B) and the admin pages (#134).
Reviews
Per-task reviews, then a whole-branch dual pass (Pass 1 ponytail, Pass 2 correctness) and a re-check of the fix wave. Pass 2 found two Important issues, fixed with failing tests first: a deactivated actor could reactivate themselves inside the cache window, and an org invitation from a deactivated inviter could still be accepted (also: last-administrator count now skips deactivated users). Ponytail Must fix list: clear.
Checks
make cover: 91.5% total (staff 99.1, staff/pgstore 88.5, orgs 93.3, orgs/pgstore 89.9, rbac/pgstore 85.1);go test ./...,make contract,make lint(0 issues) pass;scripts/generate-clients.shran (TS + Dart generate and check).Rulings
version(users.versionchanges on every sign-in); they are idempotent.Known limits (ADR 0029)
orgs.Inviter/orgs.Membersstill use the plain role check inside that window.🤖 Generated with Claude Code
GET /v1/admin/users (staff list: search, status, keyset paging), GET /v1/admin/users/{id} (platform memberships with roles) and PUT /v1/admin/users/{id}/roles (replace one application's platform roles; empty removes the membership and re-defaults another). The caller must hold every permission of an added role, only a Super Admin touches the Super Admin role, and rbac/pgstore.LockSuperAdmins (the one advisory lock, now also used by GrantFirstSuperAdmin) serialises assignments so the last active Super Admin stays (409 last_super_admin). PUT is in the sensitive rate-limit class. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>POST /v1/admin/users/{id}/deactivate|reactivate (platform scope, administration.manage, sensitive rate class): idempotent, no version, no write on a repeat. Deactivation takes the Super Admin lock first and refuses (409 last_super_admin) to leave no active Super Admin, including a self-deactivation. Upsert reports Deactivated; the Authenticator answers 403 for a deactivated user's valid token without spending the failure budget; Grants is empty for them. The handler evicts the login from the Provisioner and invalidates the authorizer after commit. Roles are kept, so reactivation restores access. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>