feat(admin): Activity log and Failed jobs pages #144

Merged
amiryahaya merged 14 commits from feat/admin-system-logs into main 2026-11-02 15:30:05 +01:00
Owner

Adds two read-only admin portal pages from the system logs, backup and restore design (docs/superpowers/specs/2026-11-02-system-logs-backup-restore-design.md). This is PR 1 of 3. Backups (PR 2) and restore (PR 3) wait for the production server setup (#57).

What it adds

  • Activity log at /system/activity, from GET /v1/admin/audit-log. It lists every recorded change to the audited config, catalogue and access tables, newest first: the time, who made it ("System" when no person did), the table, the record key, the operation, and the changed columns with old and new values. Filters are from/to (Nairobi days), table, actor id and record id. A record id needs a table, and it matches any key column, so link tables work.
  • Failed jobs at /system/failed-jobs, from GET /v1/admin/dead-jobs. It lists dead-lettered jobs with the time, kind, attempts, the subject id (sale, payment, log, invitation or attempt id) and the job id. last_error and the payload are never returned, because they can hold personal data or tokens.
  • Both pages need admin_portal.administration.manage at platform scope (rbac.PlatformOnly) and use the default rate class. Reads run in readTx (REPEATABLE READ READ ONLY, 3 s) with keyset paging (next_before, 1..200 per page). Date filters use uuidv7 id bounds, so the id index is used, and boundary tests cover 20:59:59Z and 21:00Z.
  • The OpenAPI operations are listAuditLog and listDeadJobs, and the live contract test covers them, including a check that no token or error text leaks. CLAUDE.md gains a "System logs" section.

Checks

  • make lint: 0 issues
  • make cover: 91.6% (minimum 80%). reports is at 99.0% and reports/pgstore at 82.5%.
  • make contract: OK
  • make clients: OK
  • pnpm -r typecheck and pnpm -r test: all pass (admin 292, ticket 304, ui 47, auth 45)
  • Web e2e (scripts/web-e2e.sh): passed before main was merged in. On macOS it needs COPYFILE_DISABLE=1.
  • Dual review: ponytail-review, then superpowers code review. Every finding was fixed with a test that failed first (row_id on link tables; Heavy class changed to default).

Owner question ([verify])

The Activity log shows recorded values to administration.manage holders, including organizations contact details and organization_invitations.email. staff_invitations already excludes its email from the audit. Should these be hidden? This is open question 3 in the design.

Rulings (with their cost if wrong)

  • There is no default date range; the admin types from/to, as in Transactions. Cost: two dates to type each time.
  • A record id without a table is a field error, not a disabled input. Cost: none.
  • Changed values show inline, not behind an expand control. Cost: a large insert makes a tall row.
  • One shared LogPage component, and the date and error helpers moved to reports/filters.ts. Cost: one extra layer to read.
  • Flat menu entries, with no System group. Cost: none.
  • Store tests insert their own audit_log rows with 2020 ids, and the contract test covers the trigger's real output. Cost: none.

Deferred minors

  • An upper-case record id finds nothing.
  • pageLimit and normalizeLimit duplicate the inline limit code in the other reports (about -16 lines to merge).
  • An as never cast in fetchAuditPage.
  • .UTC() is applied twice, in the handler and the stores.
  • A transaction that crosses Nairobi midnight can be listed under the next day (the id's day differs from occurred_at).
  • The audited table list is kept in three places (Go, spec enum, web). Only the Go list is checked against the triggers.

🤖 Generated with Claude Code

Adds two read-only admin portal pages from the system logs, backup and restore design (`docs/superpowers/specs/2026-11-02-system-logs-backup-restore-design.md`). This is PR 1 of 3. Backups (PR 2) and restore (PR 3) wait for the production server setup (#57). ## What it adds - **Activity log** at `/system/activity`, from `GET /v1/admin/audit-log`. It lists every recorded change to the audited config, catalogue and access tables, newest first: the time, who made it ("System" when no person did), the table, the record key, the operation, and the changed columns with old and new values. Filters are from/to (Nairobi days), table, actor id and record id. A record id needs a table, and it matches any key column, so link tables work. - **Failed jobs** at `/system/failed-jobs`, from `GET /v1/admin/dead-jobs`. It lists dead-lettered jobs with the time, kind, attempts, the subject id (sale, payment, log, invitation or attempt id) and the job id. `last_error` and the payload are never returned, because they can hold personal data or tokens. - Both pages need `admin_portal.administration.manage` at platform scope (`rbac.PlatformOnly`) and use the `default` rate class. Reads run in `readTx` (REPEATABLE READ READ ONLY, 3 s) with keyset paging (`next_before`, 1..200 per page). Date filters use uuidv7 id bounds, so the id index is used, and boundary tests cover 20:59:59Z and 21:00Z. - The OpenAPI operations are `listAuditLog` and `listDeadJobs`, and the live contract test covers them, including a check that no token or error text leaks. CLAUDE.md gains a "System logs" section. ## Checks - `make lint`: 0 issues - **`make cover`: 91.6%** (minimum 80%). `reports` is at 99.0% and `reports/pgstore` at 82.5%. - `make contract`: OK - `make clients`: OK - `pnpm -r typecheck` and `pnpm -r test`: all pass (admin 292, ticket 304, ui 47, auth 45) - Web e2e (`scripts/web-e2e.sh`): passed before `main` was merged in. On macOS it needs `COPYFILE_DISABLE=1`. - Dual review: ponytail-review, then superpowers code review. Every finding was fixed with a test that failed first (row_id on link tables; Heavy class changed to default). ## Owner question ([verify]) The Activity log shows recorded values to `administration.manage` holders, including `organizations` contact details and `organization_invitations.email`. `staff_invitations` already excludes its email from the audit. Should these be hidden? This is open question 3 in the design. ## Rulings (with their cost if wrong) - There is no default date range; the admin types from/to, as in Transactions. Cost: two dates to type each time. - A record id without a table is a field error, not a disabled input. Cost: none. - Changed values show inline, not behind an expand control. Cost: a large insert makes a tall row. - One shared `LogPage` component, and the date and error helpers moved to `reports/filters.ts`. Cost: one extra layer to read. - Flat menu entries, with no System group. Cost: none. - Store tests insert their own `audit_log` rows with 2020 ids, and the contract test covers the trigger's real output. Cost: none. ## Deferred minors - An upper-case record id finds nothing. - `pageLimit` and `normalizeLimit` duplicate the inline limit code in the other reports (about -16 lines to merge). - An `as never` cast in `fetchAuditPage`. - `.UTC()` is applied twice, in the handler and the stores. - A transaction that crosses Nairobi midnight can be listed under the next day (the id's day differs from `occurred_at`). - The audited table list is kept in three places (Go, spec enum, web). Only the Go list is checked against the triggers. 🤖 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>
Merge remote-tracking branch 'origin/main' into feat/admin-system-logs
Some checks failed
ci / changes (pull_request) Successful in 46s
ci / clients (pull_request) Successful in 4m7s
ci / web (pull_request) Failing after 6m36s
ci / api (pull_request) Successful in 11m48s
ci / ci-gate (pull_request) Failing after 11s
5419a431ae
Merge branch 'main' into feat/admin-system-logs
All checks were successful
ci / changes (pull_request) Successful in 1m15s
ci / clients (pull_request) Successful in 2m4s
ci / api (pull_request) Successful in 19m49s
ci / web (pull_request) Successful in 6m29s
ci / ci-gate (pull_request) Successful in 4s
794c7faa15
Merge remote-tracking branch 'origin/main' into feat/admin-system-logs
All checks were successful
ci / changes (pull_request) Successful in 12s
ci / clients (pull_request) Successful in 3m5s
ci / api (pull_request) Successful in 9m23s
ci / web (pull_request) Successful in 12m56s
ci / ci-gate (pull_request) Successful in 3s
f5534341cb
# Conflicts:
#	CLAUDE.md
#	web/apps/admin/src/access.test.ts
#	web/apps/admin/src/menu.ts
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!144
No description provided.