feat: Initialize core application structure including authentication, role-based dashboards, service task management, and integration workflows.
This commit is contained in:
57
app/Policies/IntegrationRequestPolicy.php
Normal file
57
app/Policies/IntegrationRequestPolicy.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user