Skip to content

feat(frontend): staff console and impersonation banner - #416

Merged
nourshoreibah merged 13 commits into
mainfrom
feat/staff-impersonation-frontend
Oct 17, 2026
Merged

nourshoreibah merged 13 commits into
mainfrom
feat/staff-impersonation-frontend

Conversation

@nourshoreibah

Copy link
Copy Markdown
Collaborator

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.
  • Session id: stored in sessionStorage (authTokens.ts), so each tab switches on its own. authedFetch sends it as X-Impersonate-Session. Calls the console must make as itself use asSelf: true.
  • What the app shows: /auth/me reports the target, so every page, permission and nav item is the target's with no further changes.
  • ImpersonationBanner (in providers.tsx): shows "Viewing as Name (email) · Read-only / Full access: changes are real · ends 14:32 · Exit". It's red in full mode.
  • Cache: starting, stopping and logging out all clear the whole query cache. logout also clears it now, because before this it left the previous user's data cached.
  • When a session ends server-side (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

  • Jest: all 42 suites pass (397 tests). New: authClient impersonation cases, the 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 2 they all pass.
  • tsc and eslint are clean, and npm run build exports /staff as a static page.

🤖 Generated with Claude Code

nourshoreibah and others added 8 commits October 15, 2026 16:28
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>
@github-actions

Copy link
Copy Markdown
Contributor

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:

  • Applied and tested locally. cd apps/backend && make migrate, then run the affected lambda's tests (cd apps/backend/lambdas/<name> && npm test). make show-migrations shows what applied.
  • Safe for the code that is live right now. During the deploy window -- and indefinitely if the deploy fails -- the currently deployed lambdas run against your new schema. Additive changes (CREATE TABLE, nullable ADD COLUMN, CREATE INDEX) are fine in one PR. DROP COLUMN, renames, ADD COLUMN NOT NULL with no default, and new UNIQUE/CHECK/FOREIGN KEY constraints need two merged PRs -- see the expand/contract rules in apps/backend/db/README.md.
  • Kept separate from unrelated changes. A migration PR should ideally contain the migration, the code that needs it, and nothing else. It changes production state, it is the one thing here that redeploying cannot roll back, and a reviewer should be able to see the whole schema change without scrolling past unrelated work.
  • No already-merged migration was edited. Fix an old migration by adding a new one; there is no down.

shared/types/db-types.d.ts is regenerated and pushed to this branch automatically -- don't hand-edit it. Expect one red migrations-fresh check before that commit lands.

This PR also changes 39 files outside apps/backend/db/. If any are unrelated to this schema change, consider splitting them into a separate PR.

@github-actions

Copy link
Copy Markdown
Contributor

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
@github-actions

Copy link
Copy Markdown
Contributor

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.

nourshoreibah and others added 4 commits October 16, 2026 21:13
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
Base automatically changed from feat/staff-impersonation-backend to main October 17, 2026 01:24
@nourshoreibah nourshoreibah added the no-review The PR review bot won't run label Oct 17, 2026
@nourshoreibah
nourshoreibah marked this pull request as ready for review October 17, 2026 01:27
@nourshoreibah
nourshoreibah merged commit 4d8e124 into main Oct 17, 2026
20 checks passed
@nourshoreibah
nourshoreibah deleted the feat/staff-impersonation-frontend branch October 17, 2026 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-review The PR review bot won't run

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant