permissions refactoring
This commit is contained in:
@@ -2,8 +2,13 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Actions\Permissions\PermissionService;
|
||||
use App\Enums\Permission;
|
||||
use App\Models\Project;
|
||||
use App\Models\Team;
|
||||
use App\Models\User;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
@@ -40,7 +45,18 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
protected function configureAuthorization(): void
|
||||
{
|
||||
Gate::define('access-admin', fn (User $user): bool => $user->is_admin);
|
||||
Relation::enforceMorphMap([
|
||||
'project' => Project::class,
|
||||
'team' => Team::class,
|
||||
'user' => User::class,
|
||||
]);
|
||||
|
||||
/** @var PermissionService $permissionService */
|
||||
$permissionService = $this->app->make(PermissionService::class);
|
||||
|
||||
Gate::define('access-admin', fn (User $user): bool => $permissionService->allows($user, Permission::GlobalAdmin));
|
||||
Gate::define('create-project', fn (User $user): bool => $permissionService->allows($user, Permission::ProjectCreate));
|
||||
Gate::define('manage-teams', fn (User $user): bool => $permissionService->canManageAnyTeam($user));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user