Skip to content

Gate dashboard API routes with guard-aware route permissions - #26

Merged
AbdelrhmanSaid merged 2 commits into
masterfrom
claude/api-route-permissions-gating-wr55ny
Aug 27, 2026
Merged

Gate dashboard API routes with guard-aware route permissions#26
AbdelrhmanSaid merged 2 commits into
masterfrom
claude/api-route-permissions-gating-wr55ny

Conversation

@AbdelrhmanSaid

Copy link
Copy Markdown
Contributor

Summary

Dashboard API routes were only authenticated (auth:admins-api), never authorized — any admin, regardless of role, could reach every dashboard API endpoint. This PR applies the RoutePermission gate to the dashboard API route group and makes the permission machinery guard-aware so it works beyond the session admins guard.

  • Application.php applies RoutePermission to the routes/api/dashboard.php group, mirroring the web dashboard middleware group.
  • route_allowed() / url_allowed() now take ?string $guard = null; when omitted, the guard is guessed from the route's auth middleware via the new route_guard() helper (falling back to admins). Passing a guard explicitly still overrides, so existing callers (e.g. the sidebar) are unaffected.
  • permissions:sync stamps permissions with the guard provider's first configured guard, so guards sharing a provider (session admins + admins-api) share one permission row instead of syncing a dead per-guard duplicate.
  • Docs updated (foundation/middleware.md, foundation/helpers.md): API gating, guard guessing, and the convention of aliasing API routes to their web permission with usePermission().

Consumer impact

Apps registering dashboard API routes should opt public/auth/profile endpoints out with withoutMiddleware(RoutePermission::class) and alias gated endpoints to their web permission with usePermission(). Companion change: redot-src/dashboard#claude/api-route-permissions-gating-wr55ny.

Testing

  • New tests: authorization resolves the route's API guard (middleware and route_allowed() string form), denial without a grant, and permissions:sync deduplicating a permission shared across guards.
  • Full suite green: 271 passed (576 assertions); Pint clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GxRW8HBNUEzmPKPmGpxWQL


Generated by Claude Code

claude added 2 commits August 27, 2026 08:34
Apply the RoutePermission middleware to the dashboard API route group and
resolve the guard from the route's auth middleware instead of assuming the
session guard:

- route_allowed()/url_allowed() now accept a nullable guard and guess it
  from the route's auth middleware (falling back to admins) when omitted.
- Add a route_guard() helper to resolve the guard a route authenticates
  against, shared by route_allowed() and permissions:sync.
- permissions:sync stamps permissions with the provider's first configured
  guard so guards sharing a provider (session + API) share one permission
  row instead of duplicating it per guard.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GxRW8HBNUEzmPKPmGpxWQL
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GxRW8HBNUEzmPKPmGpxWQL
@AbdelrhmanSaid
AbdelrhmanSaid merged commit 1c692a2 into master Aug 27, 2026
2 checks passed
@AbdelrhmanSaid
AbdelrhmanSaid deleted the claude/api-route-permissions-gating-wr55ny branch August 27, 2026 11:27
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.

2 participants