Repository navigation
feat(frontend): staff console and impersonation banner - #416
Conversation
users.is_staff hides an account from every user-facing query; the two impersonation tables record each staff switch-in and every write made while switched in. No FKs on the audit tables so the trail outlives the users it names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every pool but donors' hardcoded 5432, so a suite could only ever run against the shared dev database. Reading DB_PORT (default unchanged) lets a run point at a throwaway Postgres instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A staff account lands on /staff, the only page it can open as itself, and picks a user to view as (read-only) or act as (full, behind a confirm). The server's session id lives in sessionStorage, so a switch-in is per tab, and authedFetch sends it as X-Impersonate-Session. /auth/me then reports the target, so every page and permission is theirs with no other changes. - ImpersonationBanner, mounted in providers.tsx, names whose data is on screen, the mode and expiry, and exits back to the console. - Starting, stopping and logging out clear the whole query cache: every entry was fetched as the previous identity. - An ended session (IMPERSONATION_EXPIRED) drops the id; a GET is retried as the staff account, a write never is, and no token refresh is tried. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A hidden staff account (users.is_staff) holds no rights of its own: the RBAC gate denies it everything but impersonation:*. It starts a session against any non-staff user, then sends X-Impersonate-Session beside its own Bearer token. authenticateRequest swaps in the target's identity and memberships, so policy, scoping and entered_by all see only the target. - read_only sessions get a 403 on every non-GET; full sessions act as the target. Every non-GET impersonated request, refused or not, is recorded in branch.impersonation_actions. - MFA routes are blocked while impersonating: they act on the caller's own Cognito session, which is then the staff account's. - Staff are filtered from every user list, count, roster, picker and member validation, and the column is never returned. A staff id answers like a missing one. - make create-staff provisions one (AdminCreateUser + createStaffUser); no route can set is_staff. - X-Impersonate-Session added to CORS in the lambdas and API Gateway. 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>
This PR contains a database migration(no newly added migration files in this PR) It will be applied to the production database automatically when this PR merges, before the new lambda code is deployed. Please confirm before requesting review:
This PR also changes 39 files outside |
|
Database Types Check Complete The database schema files were modified, but the regenerated TypeScript types are identical to the existing ones. No changes were needed and the type definitions are already up to date. |
1 similar comment
|
Database Types Check Complete The database schema files were modified, but the regenerated TypeScript types are identical to the existing ones. No changes were needed and the type definitions are already up to date. |
RbacSubject.isStaff is required as of this PR; the frontend fixture builder failed typecheck without it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…' into feat/staff-impersonation-frontend # Conflicts: # apps/frontend/src/context/AuthContext.tsx # apps/frontend/src/lib/authClient.ts
…d' into feat/staff-impersonation-frontend
Part 3 of 3, stacked on the backend PR. Its diff here will show the backend comment trims until that PR merges and this one is rebased.
What
/staff(staff console): a staff account lands here, and it's the only page that account can open as itself. It has a search box and a user table with View as (read-only) and Act as (full access, behind a confirm dialog warning that changes are real). It has its own Sign out button because the page has no navbar.authTokens.ts), so each tab switches on its own.authedFetchsends it asX-Impersonate-Session. Calls the console must make as itself useasSelf: true./auth/mereports the target, so every page, permission and nav item is the target's with no further changes.ImpersonationBanner(inproviders.tsx): shows "Viewing as Name (email) · Read-only / Full access: changes are real · ends 14:32 · Exit". It's red in full mode.logoutalso clears it now, because before this it left the previous user's data cached.IMPERSONATION_EXPIRED): the stored id is dropped, a GET is retried as the staff account (so a reload lands on the console instead of signing staff out), a write is never re-sent, and no token refresh is attempted.Verification
landingPathFor(staff)rule, the banner, and the staff page. When run with full parallelism, a few existing slow suites time out on this machine; with-w 2they all pass.tscand eslint are clean, andnpm run buildexports/staffas a static page.🤖 Generated with Claude Code