Skip to content

feat(web): Rules page with admin-only enable/disable toggle - #71

Merged
vianbas merged 3 commits into
mainfrom
feat/70-rules-page
Nov 19, 2026
Merged

vianbas merged 3 commits into
mainfrom
feat/70-rules-page

Conversation

@vianbas

@vianbas vianbas commented Oct 8, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #67 for the shared frontend data helpers, so the diff shows only this work. It also needs #69 at runtime for GET /rules and PATCH /rules/{id}.

Suggested merge order: #65 → #67 → #69 → this PR. GitHub retargets this PR automatically when the #67 branch is deleted after merging.

Summary

This adds a Rules page in the web app, a UI for the endpoints in #69:

  • Every signed-in user can see the rules.
  • Only admins see the Enable/Disable controls.
  • Operators get a read-only table and a note that only admins can change rules.

The server stays the enforcement point. The UI only hides the controls and still handles a 403.

Closes #70

Architecture summary

  • Data:
    • features/rules/useRules is a useQuery on queryKeys.rules.
    • useRuleToggle PATCHes {"enabled": next} with a JSON content type, then invalidates queryKeys.rules on success and on error, so a 404 also refreshes a stale list.
    • All requests go through useApiFetch and requestJson (from feat(web): Dashboard and Alerts pages backed by live data #67).
  • Condition text comes from describeCondition, a pure function:
    • amount_minor gte 500000 is shown as "Amount ≥ 500,000 minor units". Rules carry no currency, so thresholds stay in integer minor units, grouped through BigInt and string handling with no float math.
    • currency/direction eq rules read "Currency = GBP" and "Direction = debit".
    • Anything unrecognised falls back to the raw text.
  • Page:
    • A semantic table with a caption showing name, condition, severity, status (text) and created time. An Actions column appears for admins only.
    • Each row has its own RuleToggle, with aria-label "Disable rule " or "Enable rule " and a pending state per row.
    • Failures show a dismissible role="alert" message: one for 403, one for 404, and a generic one otherwise.
    • Loading, empty and error states reuse DataStates.
  • Navigation: a Rules nav item (ListChecks) and the /rules route.

Security considerations

  • The role used for rendering comes from the login response that AuthContext keeps in memory. It is a UX hint only: authorization is enforced by the API (feat(api): enforce RBAC with admin-only rule management #69). A tampered client still gets 403, and the page handles it.
  • No new dependencies and no secrets. Test fixtures use synthetic @example.com accounts and generated ids.

Testing evidence

$ cd apps/web && npm run lint && npm run typecheck && npm test && npm run build
 Test Files  15 passed (15)
      Tests  95 passed (95)
✓ built in 1.22s
$ git diff --check origin/feat/66-dashboard-alerts-pages   # clean
  • Unit and component tests cover:
    • The condition formatter: all fields and operators, a value beyond Number.MAX_SAFE_INTEGER, and the fallbacks.
    • Admin sees toggles; operator sees none and gets the note.
    • Admin disable sends PATCH with {"enabled":false} and then refetches.
    • The 403 and 404 messages, plus the empty and error states.
  • Manual end-to-end in headless Chromium against the real API (feat: transactional outbox relay and in-process WebSocket hub #65 + feat(api): enforce RBAC with admin-only rule management #69 merged locally, not pushed), PostgreSQL and the Vite dev server:
    • Operator: 0 toggle buttons, and the "Only admins…" note is visible.
    • Admin: "Disable rule gbp-currency" changed the row to Disabled and the button to Enable. Re-enabling worked too.
    • The API logged two rule updated entries with rule_id, enabled and user_id.
    • No failed HTTP requests.

Known limitations

  • Rule toggles do not emit a realtime event, so other open sessions see the change on their next refetch, not live.
  • Only the enabled flag can be changed. Creating, deleting or editing rules is out of scope.
  • CI does not run on stacked PRs: the workflow only triggers for PRs into main. It will run once this PR is retargeted to main.

Follow-up issues

  • Optionally, a rule.updated realtime event (an AsyncAPI change) so open sessions update live.

Checklist

claude added 2 commits October 8, 2026 02:04
Add the Rule API type, the rules query key, useRules, useRuleToggle (PATCH {"enabled"} then invalidate) and a pure describeCondition helper that keeps amounts in grouped integer minor units without float math.

Refs #70

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xzt3HRqVzoHnEyEUbTT3h9
Add /rules and a Rules nav item for all signed-in users. Admins get an Actions column with per-row Enable/Disable buttons; operators see a note instead. Toggle failures show a dismissible inline alert. Extend the test helpers with makeRule and role sign-in.

Refs #70

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xzt3HRqVzoHnEyEUbTT3h9
Base automatically changed from feat/66-dashboard-alerts-pages to main November 19, 2026 00:30
@vianbas
vianbas merged commit 5397c09 into main Nov 19, 2026
7 checks passed
@vianbas
vianbas deleted the feat/70-rules-page branch November 19, 2026 00:34
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.

feat(web): Rules page with admin-only enable/disable toggle

2 participants