Benutzerrollen (Administrator, Vermietung, Inhalte) und Benutzerverwaltung
- Rollenbasierte Policies, Navigationsgruppen - Media Library (Spatie) für die kommende Bildverwaltung installiert Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
08b6582fa1
commit
27ea12901e
25 files changed
+1341
-81
No files matched your search
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
use App\Models\User;
|
||||
|
||||
/**
|
||||
* Grants every ability to the roles listed in roles(). Administrators always have access.
|
||||
*/
|
||||
abstract class RolePolicy
|
||||
{
|
||||
/**
|
||||
* @return list<UserRole>
|
||||
*/
|
||||
abstract protected function roles(): array;
|
||||
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $this->allows($user);
|
||||
}
|
||||
|
||||
public function view(User $user): bool
|
||||
{
|
||||
return $this->allows($user);
|
||||
}
|
||||
|
||||
public function create(User $user): bool
|
||||
{
|
||||
return $this->allows($user);
|
||||
}
|
||||
|
||||
public function update(User $user): bool
|
||||
{
|
||||
return $this->allows($user);
|
||||
}
|
||||
|
||||
public function delete(User $user): bool
|
||||
{
|
||||
return $this->allows($user);
|
||||
}
|
||||
|
||||
public function deleteAny(User $user): bool
|
||||
{
|
||||
return $this->allows($user);
|
||||
}
|
||||
|
||||
public function reorder(User $user): bool
|
||||
{
|
||||
return $this->allows($user);
|
||||
}
|
||||
|
||||
protected function allows(User $user): bool
|
||||
{
|
||||
return $user->hasRole(UserRole::Admin, ...$this->roles());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user