Files
ficheagent/app/Policies/IntegrationRequestPolicy.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->hasRole('Admin') || $user->can('view dashboard');
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, IntegrationRequest $integrationRequest): bool
{
if ($user->hasRole('Admin') || $user->can('validate 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->hasRole('Admin') || $user->can('create integration');
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, IntegrationRequest $integrationRequest): bool
{
return $user->hasRole('Admin') || $user->can('validate rh');
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, IntegrationRequest $integrationRequest): bool
{
return $user->hasRole('Admin');
}
}