58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\IntegrationRequest;
|
|
use App\Models\User;
|
|
use Illuminate\Auth\Access\Response;
|
|
|
|
class IntegrationRequestPolicy
|
|
{
|
|
/**
|
|
* Determine whether the user can view any models.
|
|
*/
|
|
public function viewAny(User $user): bool
|
|
{
|
|
return $user->hasAnyRole(['Admin', 'RH', 'DSI', 'Batiment', 'ParcAuto']);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can view the model.
|
|
*/
|
|
public function view(User $user, IntegrationRequest $integrationRequest): bool
|
|
{
|
|
if ($user->hasRole('Admin') || $user->hasRole('RH')) {
|
|
return true;
|
|
}
|
|
|
|
// Check if user belongs to a service that has a task in this request
|
|
return $integrationRequest->serviceTasks()
|
|
->whereIn('service_id', $user->roles()->where('name', '!=', 'Prescripteur')->pluck('id'))
|
|
->exists();
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can create models.
|
|
*/
|
|
public function create(User $user): bool
|
|
{
|
|
return $user->hasAnyRole(['Admin', 'RH', 'Prescripteur', 'DSI', 'Batiment', 'ParcAuto']);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can update the model.
|
|
*/
|
|
public function update(User $user, IntegrationRequest $integrationRequest): bool
|
|
{
|
|
return $user->hasAnyRole(['Admin', 'RH']);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can delete the model.
|
|
*/
|
|
public function delete(User $user, IntegrationRequest $integrationRequest): bool
|
|
{
|
|
return $user->hasRole('Admin');
|
|
}
|
|
}
|