diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml index cbf19560..a4afb882 100644 --- a/.github/workflows/fix-php-code-style-issues.yml +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -1,10 +1,8 @@ name: Fix PHP code style issues on: - push: - branches: [ main ] - pull_request_target: - branches: [ main ] + pull_request: + branches: [ develop ] jobs: php-code-styling: diff --git a/README.md b/README.md index b09a3ccf..9b5ef49a 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,21 @@ class UserResource extends Resource use ContextualResource; } ``` +## Access, Roles and Permissions +For Access Control, this package is designed to work hand in hand with +**[Shield (Roles & Permissions)](https://github.com/bezhanSalleh/filament-shield)** by [Bezhan Salleh](https://github.com/bezhanSalleh), which is a wrapper around +**[spatie/laravel-permission](https://github.com/spatie/laravel-permission)**. + +If you don't have the two packages above installed, then Modules will ignore access control and by default allow access to anyone logged in. + +With Shield, the package adds two more functionalities: +1. Generates permissions to allow access to the module. These are prefixed with `module_`. For example, if a user doesn't have the permission `module_Blog` then they won't be able to access any contexts under the `Blog` module. + ![img_6.png](img_6.png) +2. Enables shield to scan for resources and pages registered under the contexts in `Modules` in addition to the default Filament installation and generate permissions for them. If the policies generation option is enabled, the Policy classes are also generated under `Modules\ModuleName\Policies\`. + ![img_5.png](img_5.png) + +### WIP +Currently, the permissions for all pages in the various modules are named as page_{BaseClassName}. This brings challenges in case there are pages named similarly but in different contexts. The plan is to override the naming as is in `Shield` so that it can also capture the full path of the page class. ## Testing diff --git a/img_5.png b/img_5.png new file mode 100644 index 00000000..ae1f25ab Binary files /dev/null and b/img_5.png differ diff --git a/img_6.png b/img_6.png new file mode 100644 index 00000000..b779bf1e Binary files /dev/null and b/img_6.png differ diff --git a/src/FilamentModules.php b/src/FilamentModules.php index a854a31e..5edbbacb 100644 --- a/src/FilamentModules.php +++ b/src/FilamentModules.php @@ -134,7 +134,7 @@ public static function registerFilamentNavigationItem($module, $context): void public static function hasAuthorizedAccess(string $context) { - if (! app()->has('filament-shield')) { + if (! (app()->has('filament-shield') && \DB::table(config('permission.table_names.permissions'))->exists())) { return true; } $module = Str::of($context)->before('-')->lower();