Skip to content

Commit

Permalink
feat: view filament permission (#656)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrch authored Apr 18, 2024
1 parent 7b55289 commit 1ce7d7c
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/Enums/Auth/SpecialPermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
16 changes: 15 additions & 1 deletion app/Models/Auth/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
8 changes: 7 additions & 1 deletion database/seeders/Auth/Role/DeveloperRoleSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion database/seeders/Auth/Role/EncoderRoleSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions database/seeders/Auth/Role/PatronRoleSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function run(): void
[
SpecialPermission::BYPASS_FEATURE_FLAGS->value,
SpecialPermission::VIEW_NOVA->value,
SpecialPermission::VIEW_FILAMENT->value,
]
);

Expand Down
8 changes: 7 additions & 1 deletion database/seeders/Auth/Role/WikiEditorRoleSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion database/seeders/Auth/Role/WikiViewerRoleSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1ce7d7c

Please sign in to comment.