Skip to content

fix(dashboard): gate background queries on the permission their endpoint requires - #1445

Merged
iammukeshm merged 4 commits into
fullstackhero:mainfrom
marcelo-maciel:fix/dashboard-permission-gated-queries
Nov 3, 2026
Merged

iammukeshm merged 4 commits into
fullstackhero:mainfrom
marcelo-maciel:fix/dashboard-permission-gated-queries

Conversation

@marcelo-maciel

Copy link
Copy Markdown
Contributor

Fixes #1444

What

The dashboard queried three endpoints for every signed-in user, whatever their permissions. A role without the permission got a 403 on each poll, and the API logged an error line for each one. This gates each query on the permission its endpoint enforces:

Query Permission (from the endpoint's RequirePermission) Without it
Notification bell, GET /notifications/unread-count Permissions.Notifications.Inbox.View bell hidden
Chat unread pill, GET /chat/channels Permissions.Chat.Channels.View pill hidden (the nav already hides /chat)
Overview usage card, GET /billing/usage Permissions.Billing.View "No access to usage" state, Resources stat card reads "No access"

It follows the pattern already used for /audits on the overview and activity pages: enabled: permissionsHydrated && user.permissions.includes(...). The overview's refresh button calls refetch(), which ignores enabled, so that call carries the same gate.

Not changed on purpose: the page-local callers of the same endpoints (/chat rail and page, /subscription). They sit behind nav items gated on the same permission, and the dashboard has no per-route guards by design (frontend/dashboard.md).

Tests

  • New tests/layout/permission-gated-queries.spec.ts: without the permissions, none of the three endpoints is requested (counted after the page proves permissions hydrated) and the UI pieces are hidden or show no-access; with them, each endpoint is requested and its UI renders.
  • installShellMocks used to grant no permissions, so after this change the shell's own queries would have silently stopped firing in every spec. It now grants SHELL_PERMISSIONS (the three Basic-role grants above), which keeps the existing overview, chat and billing specs on the real query path. Specs that test a missing permission already re-mock /identity/permissions.

Mutation gate: with the src/ change reverted, the "without the permissions" test fails with each endpoint requested once ("/api/v1/billing/usage": 1, "/api/v1/chat/channels": 1, "/api/v1/notifications/unread-count": 1); with it, both tests pass.

Local runs: npx tsc -b --noEmit clean, npm run lint 0 errors (12 existing warnings, none in touched files), full dashboard suite 163 passed and 2 failed. The 2 failures are the first test of each chat.spec.ts describe on a cold Vite server. They fail the same way with this change reverted (tests/chat --repeat-each=4: 3 failed and 17 passed on both trees), and they pass on a re-run.

Also updates .agents/rules/frontend/dashboard.md with the rule for queries mounted outside their own page.

…int requires

The notification bell, the chat unread pill and the overview usage card
queried their endpoints for every user, so a role without the permission
got a 403 per poll and an error line in the API log. Gate each query on
the endpoint's permission, hide the topbar pieces without it and show a
no-access state on the overview usage card.

Fixes fullstackhero#1444
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-14T21:49:49.346849Z 4879aa6 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@iammukeshm iammukeshm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right pattern, and documenting it in dashboard.md means new topbar or overview queries will follow it. Good catch on refetch() ignoring enabled, and I like that the spec proves no request fires instead of only checking the UI. Thanks!

@iammukeshm
iammukeshm merged commit 7e568ba into fullstackhero:main Nov 3, 2026
18 checks passed
iammukeshm added a commit to fullstackhero/docs that referenced this pull request Nov 3, 2026
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.

Dashboard polls endpoints the user has no permission for, logging a 403 per poll

2 participants