Authorization Architecture
Authentication identifies a caller. Authorization evaluates the action and the team, project, record and page context that apply to it. This reference covers the current administrator permission service and policy wiring, with the separate principal paths and their known limitations. Use Roles and Permissions for task-oriented examples.
Principal paths
| Principal | Authorization path |
|---|---|
| Administrator | Gate/policy, configured permission and effective team/project role/direct grants |
| Project token | Base policy's scoped token abilities; current project-owner/list/field limitations apply |
| Portal page or attendee with page context | Active/login/audience gates, installed resources and compiled permission plan, then endpoint checks |
| Reader | Owning-project checks and operation allowlist; page-bound calls also need supported page enforcement |
| Plugin API token | Explicit plugin-management mappings; rejected by the generic resource policy |
| Widget token | No independent page authority; rejected by the generic resource policy |
Explicit policy methods and endpoint middleware can add rules. A generic base policy, valid bearer or allowed navigation item does not certify the entire returned dataset.
Administrator request flow
AuthServiceProvider uses a Gate::before callback that returns true for a caller with isSuperAdmin() and a valid global grant; otherwise it returns null so normal checks continue. Non-admin tokenable models without that method skip the hook. Policy discovery is supplemented by explicit mappings, including ModelBulkActionPolicy and the credential-scan mapping to AccessPointScanPolicy; it is not universally automatic.
SetTeamScope resolves the dashboard team from the route or supported current/last-team context, sets the lifecycle-scoped PermissionsService team and writes currentTeam. Project/API routes have their own context middleware. Confirm the context at the endpoint rather than assuming that every route uses an identical stack.
Base policy configuration
Generic policies such as AttendeePolicy extend BaseDashboardPolicy. The base implementation derives the model name from the policy class (or $model override), converts it to snake case, then reads config('permissions.rules.{modelKey}.{action}'). viewAny, view, create, update, delete and restore map directly; the forceDelete method maps to the force_delete config action.
For example, AttendeePolicy::view uses permissions.rules.attendee.view, currently view_attendees. The route parameter's name does not determine that config key. $modelOverrides is keyed by the mapped action, so a per-action override changes the resource permission lookup, while $model changes the base model name.
Missing action mapping or configured permission is denied. An explicit method takes precedence over the generic handler: ProjectPolicy::manageApiTokens requires an Admin and update_projects for the selected project/team. Check actual policies before describing a resource as an empty subclass or giving every method the same behavior.
Resource authorization and route parameters
authorizeResource(Model::class, 'parameter') registers Laravel authorization middleware for the controller's standard resource actions. Class-level actions such as collection/create authorization use the model class; instance actions resolve the named route parameter to a bound model.
| Route | Instance parameter | Matching second argument |
|---|---|---|
Route::resource('pages', ...) | page | page |
Nested pages.versions | version | version |
Nested pages.versions.assets | asset | asset |
Resource with explicit parameters(['external-apps' => 'external_app']) | external_app | external_app |
Verify the actual route definition and binding, including custom parameter mappings. If an instance parameter is missing, Gate receives no qualifying model and an ordinary caller can be denied even though direct policy invocation would succeed. Super-admin fixtures can mask this mismatch by bypassing the policy before model resolution.
A local check exercised Laravel's Authorize middleware with an ordinary Admin, a bound dashboard project and attendee. The correct attendee parameter was allowed; an absent parameter raised AuthorizationException. This checks the middleware contract, not every controller's registered route stack.
Effective team and project grants
HasRolesAndPermissions::hasPermissionTo($name, $projectId, $teamId) resolves the configured permission by guard group, sets the intended team context and delegates to PermissionsService. Admin's guard group is admin; it is a logical role/permission catalog group rather than the name of each session/OAuth guard.
For ordinary team-scoped checks, the service combines role-derived permissions and applicable direct grants. A project check includes matching project assignments and team-wide assignments. A check without a project includes team-wide effective grants, not every project-specific grant. Global direct grants can also be considered where the direct-permission query permits them; global super_admin has its separate Gate behavior.
Role catalogs belong to a team. Role assignments carry their project scope in model_has_roles; direct assignments carry team/project context in model_has_permissions. The models use morph relations for the owning model and ID. Do not confuse a role/permission catalog ID with an assignment row ID or assume every pivot has the same columns.
getDirectPermissions() is an assignment-oriented listing and can include several projects. getApplicableDirectPermissions() filters those grants for effective checks. Raw relationship presence is not proof that a specific action is granted in another project. Likewise, project-list visibility uses assignment queries separately from ProjectPolicy; see Managing Projects and Administrator Access.
Scope changes and low-level mutations
Permission helpers are application internals, not operator authorization endpoints. Resolve the intended team, member, project and catalog IDs through an authorized workflow before changing assignments. The dashboard's normal assignment handler adds some membership/project validation; that is not an ownership guarantee for every low-level helper or endpoint.
The current withTeamScope helper restores the previous ID only after a normal callback return. It has no try/finally; exceptions leave the temporary scope active. In jobs, nested work and error paths, save and explicitly restore the previous ID in finally. Setting a team ID establishes lookup context; it does not itself verify the caller's membership or authority.
Synthetic checks also reproduced these current mutation limits:
removeRolesandremovePermissionsdelete supplied assignment IDs without restricting them to the model argument. Select and validate an owned assignment first; these methods are not an authorization boundary.- Project-specific
syncRolesandsyncPermissionscan detach the same role/permission from another project. Null-project sync is not proven to preserve all project assignments. Require a scope-preserving fix before treating these replacement operations as isolated project updates. revokePermissionToresolves assignments by model and permission IDs without team/project predicates; it is not a project-only revoke helper.
The cookbook shows explicit context restoration and a specific-assignment selection/removal example. The retained tests include successful scoped permission checks and removal as well as reproductions of the gaps. A passing reproduction means the unsafe behavior was observed, not that it is corrected or accepted.
Caching and invalidation
AppServiceProvider registers PermissionsService as scoped. Its in-memory requestCache avoids repeated lookups during that lifecycle. A second tagged-cache layer uses permissions.cache.expiration_time (default 300 seconds), including team/guard and model tags. Configure a tag-capable backend; these methods do not promise a particular cache deployment.
flushModelCache clears the model tag and the service's local cache. flushRoleCache clears affected team/guard role and model-role tags; flushPermissionCache clears the guard tag. Role and Permission observers call the matching invalidation helper on relevant model events, and assignment/role-permission service methods flush after changes.
Direct pivot SQL or relationship mutations outside those supported service paths can bypass invalidation. Broad mutations/removals can also affect models beyond the one whose cache was flushed; inspect the actual affected set. UI permission props are a snapshot, so refresh them after changing access.
Avoid bypassing the established team-scope API with PermissionsService::getDirectPermissions(..., $explicitTeamId): that override does not form a separate cache key from the service's current team. Use the intended scope through the supported flow and check cross-team behavior.
Catalog generation and default roles
Default team roles are admin, billing, member, viewer and developer, with configured sets. Team creation/default seeding and updating existing role definitions are different operations. The configured admin set excludes top-level permissions; global super-admin access is not a normal team-role assignment.
| Maintainer operation | Current effect |
|---|---|
app:generate-permissions-from-config | Dispatches the generation action; creates missing configured permissions and adds configured grants to existing default roles without detaching older grants |
app:resync-role-permissions --team=TEAM_ID | Replaces the permission set of existing default roles for that team from config; leaves model role assignments and direct grants in place |
seedTeamRolesAndPermissions | Seeds roles for a specified team under an explicitly set/restored service scope |
The resync command without --team targets every team. These are maintainer operations that change effective access; use the established repository deployment/change process. Adding a permission to config does not prove a deployed job ran, and additive generation does not remove obsolete grants. Detailed production procedures stay in separate runbooks.
Add or change a policy
- Identify the model, actual controller abilities and registered route parameters; check whether an explicit policy method or special principal path is required.
- Add the model/action entries inside the existing
rulesarray inconfig/permissions.php, preserving other entries. Use the base map'sforce_deleteconfig spelling when applicable. - Add appropriate defaults to the role configuration; inspect effects on existing teams and any additive-versus-replacement update.
- Implement/register the policy through discovery or an explicit mapping. Pair resource authorization with the route's actual instance parameter.
- Generate the catalog through the supported maintainer flow and verify job completion in the intended test environment. There is no documented
permissions:generatecommand in this source snapshot. - Test an ordinary allowed Admin and an ordinary denied Admin, correct/wrong team and project, class and instance actions, and the full HTTP binding path. Add principal/record/query/field checks for the endpoint's actual data flow.
Do not validate policy wiring solely with $admin->can(...) unit calls or super-admin fixtures. Test expected denial as well as allowed behavior, and verify nested resources, searches and exports when those are part of the endpoint.
Project-token enforcement limits
Project-owned API tokens use a separate path from administrator role checks. Current synthetic source checks found that selected record/field constraints were recorded but not consumed by the common attendee list/serializer, and that the tested project-token route/policy path accepted another same-team project's context and record under a model-wide ability. The excluded individual-record check did deny a selected-ID token.
See Project API Keys for the exact scope and limits. These findings do not establish the behavior of every live HTTP endpoint. Token ownership, client-selected slugs and selected field/record controls are not verified isolation guarantees; require endpoint enforcement and negative acceptance checks before relying on them.
Implementation evidence
Reviewed on 2026-10-13 against experience-portal a010092b9c: BaseDashboardPolicy, ProjectPolicy, AuthServiceProvider, AppServiceProvider, team-context middleware, HasRolesAndPermissions, PermissionsService, permission helpers, related models/observers, GeneratePermissionsFromConfig and its command, the resync command, assignment controllers, and project visibility queries. Retained local fixtures check representative contracts and reproduce known gaps; full HTTP/deployed authorization acceptance remains separate.