Skip to content

feat(dashboard): list the API keys that stop working when you deactivate a user - #2078

Open
amarkanday wants to merge 2 commits into
mainfrom
feat/657-deactivate-keys
Open

amarkanday wants to merge 2 commits into
mainfrom
feat/657-deactivate-keys

Conversation

@amarkanday

Copy link
Copy Markdown
Contributor

Part of #657

What and why

When an administrator cleared Active in the Edit user dialog, the dialog said that "API keys they created stop working" and nothing more. Nowhere in the dashboard could they see which keys. Now the dialog names them, before they save.

  • Clearing Active on someone else's account asks GET /api/v1/api-keys?all=true (never on open, never for a role-only change), keeps the rows whose user_id is this user's and that are still active, and lists each key as name · scopes · last used <date-time> (or no scopes, never used). A success is kept while the dialog stays open; a failure shows the reason and a Try again button.
  • Save stays enabled in every state, while the list loads and after it fails, and still sends exactly {is_active: false}: an emergency deactivation never needs the list.
  • No backend change. Any superuser may call the route whatever their role (check_permission returns early for a superuser), and the Users page is superuser-only, so every account that can open the dialog can make the call. No file under backend/app changes, and make openapi leaves the tree clean.
  • Screen readers: one polite role="status" region, mounted empty and filled once when the request settles; Save and Active are described by the general warning and the summary; focus stays on Active and moves to the summary only after Try again succeeds.
  • The delete confirm now adds "Their API keys are deleted too, and applications using them stop working." (the cascade already existed).
  • Docs: auth-user-guide.md, api/endpoints.md and security/api-keys.md say how to find a user's keys, to switch an application to a key of an account that stays before deactivating, and that reactivating the user makes their keys work again unless they expired. "An ADMIN can add ?all=true" now says "or any superuser". The claims registries follow; one exempt:baseline line leaves _frozen.tsv.

Not in this change (0.49.0, #657 proper): keys owned by the organisation, listing keys in the delete confirm, and the role-change effect on sdk:ruleset keys (to be noted on #657).

Verification

Run in a clean clone of main, a Python 3.11 venv, a scratch PostgreSQL 14 on 127.0.0.1 for the integration tests.

Gate Result
jest: EditUserModal, admin-users, UserTable, query-params, three runs 142 passed, 142 passed, 142 passed
jest, whole suite (full profile) 246 suites, 5599 tests passed
jest as the core profile (the pr-qa-gate command) 221 suites, 5095 tests passed
npx tsc --noEmit, npm run lint rc 0, rc 0
backend: new tests plus the two account-removal cascade tests 14 passed
doc_claims.py check problems: 0
doc_examples.py --check, test_docs_only_gate.py, backend/tests/unit/docs contract holds, 47 passed, 3270 passed
mkdocs build --strict, make openapi rc 0, tree unchanged
ruff check and format on the two backend test files clean

Each plant was applied to the product file, the named tests ran red, and the file was put back byte for byte (unstaged diff empty after):

  • asks on open: 12 red, the first being "does not ask on open or for a role-only change"
  • no cache: "asks once on clearing Active, keeps a success" (2 calls, expected 1)
  • failure cached: "does not keep a failure" (1 call, expected 2)
  • no reset on open, and no opening guard: "asks again after the dialog was closed and opened again", "ignores an answer that settles after the dialog was closed and opened again"
  • user filter dropped, expiry filter dropped: "lists only the keys of this user that are active" (2 items, expected 1), plus the page test with carol's key
  • "1 API keys", "The 0 API keys": the one-key, none and axe-with-no-keys cases
  • Save disabled while loading, floor sentence hidden on error, no focus move after Try again, Try again unmounted while busy, no aria-describedby on Save, status region mounted with its text, summary focus on first load, status region on your own row, div children in the ul (axe list rule)
  • service call without all, with include_inactive: both fail the page test on ?all=true
  • delete confirm sentence dropped: "shows confirmation before delete"
  • ? in the path literal: the query-parameter guard refuses it
  • backend: has_permission(user.role, ...) in _may_act_on_others_keys turns both superuser-not-ADMIN cases to 403; deactivation setting the keys inactive fails "the owner's key is 401 while they are inactive and works again"
  • docs: the page test (which reads docs) in a by list, the removed ledger line back, and a doc sentence edited away from its unit each fail doc_claims.py check

NOT VERIFIED

  • The journey (dialog-focus.journey.spec.ts, a real key listed and axe run on it, wcag2aa colour contrast included) was type-checked and linted but not run: it needs the real API and a browser, which only the required browser-e2e gate has. It makes the first raw POST /auth/login in the journeys project and retries a 429 the way the two-step journey does.
  • Colour contrast of the loading, none and error states, what a screen reader says, and what Chrome does with focus on an aria-disabled button: jsdom does not compute or speak them.
  • ?all=true is not paginated; its size on a site with thousands of keys was not measured.
  • Cognito sessions and the full profile's rbac module were not run; the route's superuser path does not depend on either.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NpxPyav9uBxNuiXsDvD8qn

amarkanday and others added 2 commits November 19, 2026 16:32
…ate a user

Clearing Active in the Edit user dialog now names the keys that will stop
working, instead of only saying that some will (#657).

- The dialog asks GET /api/v1/api-keys?all=true when Active is cleared on
  someone else's account (never on open, never for a role-only change), keeps
  the rows whose user_id is this user's and that are still active, and lists
  each key with its scopes and when it was last used. A success is kept while
  the dialog stays open; a failure shows the reason and a Try again button.
  Save is never held up by the request and still sends exactly
  {is_active: false}. Any superuser may call the route, whatever their role,
  so no backend change is needed.
- Screen readers: one polite status region, empty until the request settles;
  Save and Active are described by the general warning and the summary; focus
  stays on Active, and moves to the summary only after Try again succeeds.
- The delete confirm says that the account's API keys are deleted too.
- Docs: auth-user-guide, endpoints and security/api-keys say how to find a
  user's keys, what to switch before deactivating, and that reactivating the
  user makes unexpired keys work again; the claims registries follow.
- Tests: the dialog (26 cases), the real page against the request on the
  wire, the query-parameter guard (one more call), the delete confirm, the
  dialog-focus journey (a real key listed, axe on it), a superuser who is not
  an ADMIN listing every key, and a deactivated owner's key answering 401 and
  working again after reactivation unless it expired.

No file under backend/app changes, so the OpenAPI snapshots do not move.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NpxPyav9uBxNuiXsDvD8qn
Signed-off-by: amarkanday <a.markanday@gmail.com>
Brings the deactivate dialog's key list up to main 7105479.
The merge was clean, but query-params.test.ts's call count was wrong after
it: this branch and #2006 each added one dashboard call and each moved
EXPECTED_COUNT from 16 to 17 (15 to 16 in the core profile), so the merged
line still said 17 while 18 calls are made. It now says 18 (17 in core).
Both calls stay listed in EXPECTED_CALLS, as the merge left them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NpxPyav9uBxNuiXsDvD8qn
Signed-off-by: amarkanday <a.markanday@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant