diff --git a/src/FilamentShield.php b/src/FilamentShield.php index a4c73c9..a0b9b77 100755 --- a/src/FilamentShield.php +++ b/src/FilamentShield.php @@ -187,6 +187,7 @@ public static function getLocalizedResourcePermissionLabel(string $permission): public static function getPages(): ?array { $pages = Filament::getPages(); + if (Utils::discoverAllPages()) { $pages = []; foreach (Filament::getPanels() as $panel) { @@ -195,8 +196,19 @@ public static function getPages(): ?array $pages = array_unique($pages); } + $clusters = collect($pages) + ->map(fn($page) => $page::getCluster()) + ->reject(fn($cluster) => is_null($cluster)) + ->unique() + ->values() + ->toArray(); + return collect($pages) - ->reject(function ($page) { + ->reject(function ($page) use($clusters) { + if (in_array($page, $clusters)) { + return true; + } + if (Utils::isGeneralExcludeEnabled()) { return in_array(Str::afterLast($page, '\\'), Utils::getExcludedPages()); } @@ -372,4 +384,4 @@ protected function getEntitiesPermissions(): ?array ->unique() ->toArray(); } -} +} \ No newline at end of file diff --git a/src/Traits/HasPageShield.php b/src/Traits/HasPageShield.php index dd3dc22..a2758c6 100644 --- a/src/Traits/HasPageShield.php +++ b/src/Traits/HasPageShield.php @@ -13,7 +13,7 @@ public function booted(): void { $this->beforeBooted(); - if (! static::canView()) { + if (! static::canAccess()) { Notification::make() ->title(__('filament-shield::filament-shield.forbidden')) @@ -51,11 +51,6 @@ protected function getShieldRedirectPath(): string return Filament::getUrl(); } - public static function canView(): bool - { - return Filament::auth()->user()->can(static::getPermissionName()) || Filament::auth()->user()->hasRole(Utils::getSuperAdminName()); - } - protected static function getPermissionName(): string { return Str::of(class_basename(static::class)) @@ -67,13 +62,13 @@ protected static function getPermissionName(): string ->toString(); } - public static function shouldRegisterNavigation(array $parameters = []): bool + public static function shouldRegisterNavigation(): bool { - return static::canView() && parent::shouldRegisterNavigation(); + return static::canAccess() && parent::shouldRegisterNavigation(); } public static function canAccess(): bool { - return static::canView(); + return Filament::auth()->user()->can(static::getPermissionName()); } -} +} \ No newline at end of file