feat(admin): staff pages, invitation accept and Operations role (#134) #141

Merged
amiryahaya merged 12 commits from feat/admin-staff-pages into main 2026-11-01 20:05:55 +01:00
Owner

Closes the admin side of #134: the Super Admin can now invite the operations team (and later finance) from the portal, and the invited person accepts from the email link.

Design: docs/superpowers/specs/2026-11-02-admin-staff-pages-design.md · Plan: docs/superpowers/plans/2026-11-02-admin-staff-pages.md

What changes

API

  • New built-in role Operations (admin_portal.access, reports.view, tickets.scan; no administration.manage). Applied by KWS_MODE=migrate. Dictionaries and the catalogue stay with Admin.
  • GET /v1/admin/users items are now StaffUser (with memberships[].roles), read in the same query (shared membershipsCol, no N+1). StaffUserSummary is removed from the spec; the contract test asserts memberships.

Admin portal (web/apps/admin/src/staff/)

  • /staff: search, status filter, Load more, Edit roles grouped by application (one PUT per changed application, a partial failure names the unsaved group), Deactivate / Reactivate with in-page confirmation.
  • /staff-invitations: invite by email with one or more roles (Idempotency-Key per open form, reused on retry), revoke; fixed texts for every 409 code and the "email not set up" 503.
  • /accept-invitation (outside RequireAccess): token read from the hash and removed from the address bar, carried through sign-in in the OIDC state, exactly one accept POST (StrictMode-safe); shows granted roles, links home only with admin access.
  • Both menu items need admin_portal.administration.manage at platform scope. No server text reaches the screen.

Dev

  • Mailpit (axllent/mailpit:v1.31.6, loopback ports 1025/8025) in compose.dev.yml; README explains the KWS_SMTP_* values for API and worker, and that admin_portal_url must be https (https://localhost:5173, open the emailed link with http).
  • Mock IdP: kws-admin-web tokens now get aud: kws-api (admin dev sign-in was 401).
  • Staging email via Resend works through SMTP; no code change.

Verification

  • make cover: 91.6 % total (minimum 80 %); make lint: 0 issues; make contract ok.
  • Admin unit tests 280/280, typecheck clean; scripts/web-e2e.sh: ticket 207, admin 113 passed (run before the final refactor commit, which touches no e2e file). On macOS run it with COPYFILE_DISABLE=1.
  • Real local run: Super Admin invited ops.one@example.test as Operations → Mailpit email → accept → roles shown, # cleared, menu = Transactions only, /staff = no permission, invitation used, token in no API/worker/dev-server log.
  • Review: per-task spec + quality reviews, final dual pass (Ponytail complexity: no must-fix; correctness: one Important fixed — the README https value).

Known and deferred

  • A failed revoke for a transient reason (429/503) closes the confirmation; click Revoke again.
  • Roles load failure in the invite/edit forms shows the save-failure text with no retry.
  • Accept page: a few rare branches (400, 429, access refetch error) untested; IdP-less "off" dev mode sticks on Loading after accept.
  • Not built (spec non-goals): custom role editor, staff detail page, resend. Catalogue/dictionary pages (#45) are the next project.
  • Dart client not generated locally; the CI clients job does it.

🤖 Generated with Claude Code

Closes the admin side of #134: the Super Admin can now invite the operations team (and later finance) from the portal, and the invited person accepts from the email link. Design: `docs/superpowers/specs/2026-11-02-admin-staff-pages-design.md` · Plan: `docs/superpowers/plans/2026-11-02-admin-staff-pages.md` ## What changes **API** - New built-in role **Operations** (`admin_portal.access`, `reports.view`, `tickets.scan`; no `administration.manage`). Applied by `KWS_MODE=migrate`. Dictionaries and the catalogue stay with Admin. - `GET /v1/admin/users` items are now `StaffUser` (with `memberships[].roles`), read in the same query (shared `membershipsCol`, no N+1). `StaffUserSummary` is removed from the spec; the contract test asserts memberships. **Admin portal** (`web/apps/admin/src/staff/`) - `/staff`: search, status filter, Load more, Edit roles grouped by application (one PUT per changed application, a partial failure names the unsaved group), Deactivate / Reactivate with in-page confirmation. - `/staff-invitations`: invite by email with one or more roles (`Idempotency-Key` per open form, reused on retry), revoke; fixed texts for every 409 code and the "email not set up" 503. - `/accept-invitation` (outside `RequireAccess`): token read from the hash and removed from the address bar, carried through sign-in in the OIDC `state`, exactly one accept POST (StrictMode-safe); shows granted roles, links home only with admin access. - Both menu items need `admin_portal.administration.manage` at platform scope. No server text reaches the screen. **Dev** - Mailpit (`axllent/mailpit:v1.31.6`, loopback ports 1025/8025) in `compose.dev.yml`; README explains the `KWS_SMTP_*` values for API and worker, and that `admin_portal_url` must be https (`https://localhost:5173`, open the emailed link with http). - Mock IdP: `kws-admin-web` tokens now get `aud: kws-api` (admin dev sign-in was 401). - Staging email via Resend works through SMTP; no code change. ## Verification - `make cover`: **91.6 %** total (minimum 80 %); `make lint`: 0 issues; `make contract` ok. - Admin unit tests 280/280, typecheck clean; `scripts/web-e2e.sh`: ticket 207, admin 113 passed (run before the final refactor commit, which touches no e2e file). On macOS run it with `COPYFILE_DISABLE=1`. - Real local run: Super Admin invited `ops.one@example.test` as Operations → Mailpit email → accept → roles shown, `#` cleared, menu = Transactions only, `/staff` = no permission, invitation `used`, token in no API/worker/dev-server log. - Review: per-task spec + quality reviews, final dual pass (Ponytail complexity: no must-fix; correctness: one Important fixed — the README https value). ## Known and deferred - A failed revoke for a transient reason (429/503) closes the confirmation; click Revoke again. - Roles load failure in the invite/edit forms shows the save-failure text with no retry. - Accept page: a few rare branches (400, 429, access refetch error) untested; IdP-less "off" dev mode sticks on Loading after accept. - Not built (spec non-goals): custom role editor, staff detail page, resend. Catalogue/dictionary pages (#45) are the next project. - Dart client not generated locally; the CI clients job does it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fix(admin): final review fixes for staff pages
All checks were successful
ci / changes (pull_request) Successful in 14s
ci / clients (pull_request) Successful in 1m17s
ci / web (pull_request) Successful in 8m49s
ci / api (pull_request) Successful in 12m26s
ci / ci-gate (pull_request) Successful in 3s
0c9f7ec078
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
primatekuntech/kws!141
No description provided.