diff --git a/app/Enums/Auth/SpecialPermission.php b/app/Enums/Auth/SpecialPermission.php index c1cc9825b..c230eb524 100644 --- a/app/Enums/Auth/SpecialPermission.php +++ b/app/Enums/Auth/SpecialPermission.php @@ -13,6 +13,8 @@ enum SpecialPermission: string case BYPASS_FEATURE_FLAGS = 'bypass feature flags'; + case VIEW_FILAMENT = 'view filament'; + case VIEW_HORIZON = 'view horizon'; case VIEW_NOVA = 'view nova'; diff --git a/app/Models/Auth/User.php b/app/Models/Auth/User.php index fa8ac7cef..996eb6ff9 100644 --- a/app/Models/Auth/User.php +++ b/app/Models/Auth/User.php @@ -5,12 +5,15 @@ namespace App\Models\Auth; use App\Contracts\Models\Nameable; +use App\Enums\Auth\SpecialPermission; use App\Events\Auth\User\UserCreated; use App\Events\Auth\User\UserDeleted; use App\Events\Auth\User\UserRestored; use App\Events\Auth\User\UserUpdated; use App\Models\List\Playlist; use Database\Factories\Auth\UserFactory; +use Filament\Models\Contracts\FilamentUser; +use Filament\Panel; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -46,7 +49,7 @@ * * @method static UserFactory factory(...$parameters) */ -class User extends Authenticatable implements MustVerifyEmail, Nameable +class User extends Authenticatable implements MustVerifyEmail, Nameable, FilamentUser { use Actionable; use HasApiTokens; @@ -176,6 +179,17 @@ public function restore(): ?bool return $result; } + /** + * Determine if the user can access the filament panel. + * + * @param Panel $panel + * @return bool + */ + public function canAccessPanel(Panel $panel): bool + { + return $this->hasVerifiedEmail() && $this->hasAnyPermission(SpecialPermission::VIEW_FILAMENT->value); + } + /** * Get the playlists that belong to the user. * diff --git a/database/seeders/Auth/Role/DeveloperRoleSeeder.php b/database/seeders/Auth/Role/DeveloperRoleSeeder.php index f3c8e2b16..bc5294c9a 100644 --- a/database/seeders/Auth/Role/DeveloperRoleSeeder.php +++ b/database/seeders/Auth/Role/DeveloperRoleSeeder.php @@ -68,7 +68,13 @@ public function run(): void $this->configureResource($role, VideoScript::class, [CrudPermission::VIEW]); // Special Permissions - $this->configureAbilities($role, [SpecialPermission::VIEW_NOVA->value]); + $this->configureAbilities( + $role, + [ + SpecialPermission::VIEW_NOVA->value, + SpecialPermission::VIEW_FILAMENT->value, + ] + ); $role->color = '#FF69B4'; $role->priority = 125000; diff --git a/database/seeders/Auth/Role/EncoderRoleSeeder.php b/database/seeders/Auth/Role/EncoderRoleSeeder.php index 2e8ca7c44..7fc2083db 100644 --- a/database/seeders/Auth/Role/EncoderRoleSeeder.php +++ b/database/seeders/Auth/Role/EncoderRoleSeeder.php @@ -75,7 +75,13 @@ public function run(): void $this->configureResource($role, VideoScript::class, $extendedCrudPermissions); // Special Permissions - $this->configureAbilities($role, [SpecialPermission::VIEW_NOVA->value]); + $this->configureAbilities( + $role, + [ + SpecialPermission::VIEW_NOVA->value, + SpecialPermission::VIEW_FILAMENT->value, + ] + ); $role->color = '#FFC107'; $role->priority = 150000; diff --git a/database/seeders/Auth/Role/PatronRoleSeeder.php b/database/seeders/Auth/Role/PatronRoleSeeder.php index ead2a17d0..620fc18a0 100644 --- a/database/seeders/Auth/Role/PatronRoleSeeder.php +++ b/database/seeders/Auth/Role/PatronRoleSeeder.php @@ -73,6 +73,7 @@ public function run(): void [ SpecialPermission::BYPASS_FEATURE_FLAGS->value, SpecialPermission::VIEW_NOVA->value, + SpecialPermission::VIEW_FILAMENT->value, ] ); diff --git a/database/seeders/Auth/Role/WikiEditorRoleSeeder.php b/database/seeders/Auth/Role/WikiEditorRoleSeeder.php index ca9cb106a..e64886f25 100644 --- a/database/seeders/Auth/Role/WikiEditorRoleSeeder.php +++ b/database/seeders/Auth/Role/WikiEditorRoleSeeder.php @@ -75,7 +75,13 @@ public function run(): void $this->configureResource($role, VideoScript::class, [CrudPermission::VIEW]); // Special Permissions - $this->configureAbilities($role, [SpecialPermission::VIEW_NOVA->value]); + $this->configureAbilities( + $role, + [ + SpecialPermission::VIEW_NOVA->value, + SpecialPermission::VIEW_FILAMENT->value, + ] + ); $role->color = '#2E5A88'; $role->priority = 100000; diff --git a/database/seeders/Auth/Role/WikiViewerRoleSeeder.php b/database/seeders/Auth/Role/WikiViewerRoleSeeder.php index c9d3e6336..521295e35 100644 --- a/database/seeders/Auth/Role/WikiViewerRoleSeeder.php +++ b/database/seeders/Auth/Role/WikiViewerRoleSeeder.php @@ -68,7 +68,13 @@ public function run(): void $this->configureResource($role, VideoScript::class, [CrudPermission::VIEW]); // Special Permissions - $this->configureAbilities($role, [SpecialPermission::VIEW_NOVA->value]); + $this->configureAbilities( + $role, + [ + SpecialPermission::VIEW_NOVA->value, + SpecialPermission::VIEW_FILAMENT->value, + ] + ); $role->color = '#2596D1'; $role->priority = 25000;