Skip to content

Commit

Permalink
Merge pull request #380 from bezhanSalleh/fix/cluster-page
Browse files Browse the repository at this point in the history
[Fix] Cluster Page
  • Loading branch information
bezhanSalleh committed May 14, 2024
2 parents aef5b92 + 32b8d31 commit 2e30ae1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
14 changes: 13 additions & 1 deletion src/FilamentShield.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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());
}
Expand Down
13 changes: 4 additions & 9 deletions src/Traits/HasPageShield.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function booted(): void
{
$this->beforeBooted();

if (! static::canView()) {
if (! static::canAccess()) {

Notification::make()
->title(__('filament-shield::filament-shield.forbidden'))
Expand Down Expand Up @@ -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))
Expand All @@ -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());
}
}

0 comments on commit 2e30ae1

Please sign in to comment.