Skip to content

Conversation

@scottgrayson
Copy link
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
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