Skip to content

Add role-based folder access control#7

Closed
scottgrayson wants to merge 2 commits into
mainfrom
feature/role-based-folder-access
Closed

Add role-based folder access control#7
scottgrayson wants to merge 2 commits into
mainfrom
feature/role-based-folder-access

Conversation

@scottgrayson

Copy link
Copy Markdown
Contributor

Summary

This PR adds role-based folder access control to the library package while keeping it decoupled from Spatie Permission.

Changes

  • Add role checker callback pattern to FilamentLibraryPlugin (similar to libraryAdminCallback)
  • Create library_item_role_permissions table migration
  • Add LibraryItemRolePermission model
  • Extend LibraryItem with role-based permission checks:
    • hasRoleRestrictions() - Check if item/parent has role restrictions
    • getRequiredRoleNames() - Get all required roles (including inherited)
    • hasRoleAccess() - Check if user has required role
    • Updated getEffectiveRole() and hasPermission() to check role restrictions first
  • Add role permissions UI fields to CreateFolder and EditFolder pages
  • Support role restrictions that inherit from parent folders

Architecture

The package uses callback patterns to remain decoupled from Spatie Permission:

  • setRoleCheckerCallback() - Projects implement role checking
  • setAvailableRolesCallback() - Projects provide available roles for UI

Testing

  • Test folder access with role restrictions
  • Test role restriction inheritance from parent folders
  • Test that users without required roles cannot access folders
  • Test that library admins bypass role restrictions

scott grayson and others added 2 commits November 13, 2025 12:47
- Add role checker callback pattern to FilamentLibraryPlugin
- Create library_item_role_permissions table migration
- Add LibraryItemRolePermission model
- Extend LibraryItem with role-based permission checks
- Add role permissions UI fields to CreateFolder and EditFolder pages
- Support role restrictions that inherit from parent folders
- Keep package decoupled from Spatie Permission via callbacks
@scottgrayson
scottgrayson marked this pull request as draft November 13, 2025 17:48
@scottgrayson

Copy link
Copy Markdown
Contributor Author

Closing as superseded by the per-user permission model shipped in v1.3.5/v1.3.7 (#32, #34).

The resource library contract uses explicit library_item_permissions per user, with roles only as assignment filters via the host-owned assignment.filter_provider — not role-gated folder visibility.

If role-based folder restrictions are needed in the future, they should be redesigned from main rather than revived from this branch.

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.

1 participant