permissions refactoring
This commit is contained in:
@@ -2,11 +2,17 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Actions\Permissions\PermissionService;
|
||||
use App\Enums\Permission;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Middleware;
|
||||
|
||||
class HandleInertiaRequests extends Middleware
|
||||
{
|
||||
public function __construct(
|
||||
private readonly PermissionService $permissionService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* The root template that's loaded on the first page visit.
|
||||
*
|
||||
@@ -35,11 +41,18 @@ class HandleInertiaRequests extends Middleware
|
||||
*/
|
||||
public function share(Request $request): array
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
return [
|
||||
...parent::share($request),
|
||||
'name' => config('app.name'),
|
||||
'auth' => [
|
||||
'user' => $request->user(),
|
||||
'permissions' => [
|
||||
'canManageTeams' => $user !== null && $this->permissionService->canManageAnyTeam($user),
|
||||
'globalAdmin' => $user !== null && $this->permissionService->allows($user, Permission::GlobalAdmin),
|
||||
'projectCreate' => $user !== null && $this->permissionService->allows($user, Permission::ProjectCreate),
|
||||
],
|
||||
'user' => $user,
|
||||
],
|
||||
'sidebarOpen' => ! $request->hasCookie('sidebar_state') || $request->cookie('sidebar_state') === 'true',
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user