Initial commit with contrats and domaines modules
This commit is contained in:
44
app/Policies/DomainePolicy.php
Normal file
44
app/Policies/DomainePolicy.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Domaine;
|
||||
use App\Models\User;
|
||||
|
||||
class DomainePolicy
|
||||
{
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function view(User $user, Domaine $domaine): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private function canManage(User $user): bool
|
||||
{
|
||||
if ($user->hasRole('admin')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Must belong to "Infrastructure" service
|
||||
return $user->service && $user->service->nom === 'Infrastructure';
|
||||
}
|
||||
|
||||
public function create(User $user): bool
|
||||
{
|
||||
return $this->canManage($user);
|
||||
}
|
||||
|
||||
public function update(User $user, Domaine $domaine): bool
|
||||
{
|
||||
return $this->canManage($user);
|
||||
}
|
||||
|
||||
public function delete(User $user, Domaine $domaine): bool
|
||||
{
|
||||
return $this->canManage($user);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user