feat: Implement initial agent integration management system with role-based dashboards, status tracking, and activity timelines.
This commit is contained in:
@@ -24,7 +24,7 @@ class DashboardController extends Controller
|
||||
}
|
||||
|
||||
// If user has a service role
|
||||
$serviceRoles = ['DSI', 'Batiment', 'ParcAuto'];
|
||||
$serviceRoles = ['DSI', 'Batiment', 'Parc Auto'];
|
||||
foreach ($serviceRoles as $role) {
|
||||
if ($user->hasRole($role)) {
|
||||
return $this->serviceDashboard($role);
|
||||
@@ -103,6 +103,15 @@ class DashboardController extends Controller
|
||||
})
|
||||
->with(['integrationRequest.agent', 'taskItems'])
|
||||
->get(),
|
||||
'processed_integrations' => IntegrationRequest::whereHas('serviceTasks', function ($query) use ($role) {
|
||||
$query->whereHas('service', function ($q) use ($role) {
|
||||
$q->where('name', $role);
|
||||
})->where('status', ServiceTaskStatus::Completed);
|
||||
})
|
||||
->with(['agent', 'template'])
|
||||
->latest('updated_at')
|
||||
->take(10)
|
||||
->get(),
|
||||
'completed_tasks' => ServiceTask::where('status', ServiceTaskStatus::Completed)
|
||||
->whereHas('service', function ($query) use ($role) {
|
||||
$query->where('name', $role);
|
||||
|
||||
@@ -43,10 +43,23 @@ class IntegrationController extends Controller
|
||||
|
||||
public function show(IntegrationRequest $integration)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$serviceTaskConstraint = function ($query) use ($user) {
|
||||
// Admin, RH, and Prescripteur can see all tasks (global progress)
|
||||
if (!$user->hasRole(['Admin', 'RH', 'Prescripteur'])) {
|
||||
$query->whereHas('service', function ($q) use ($user) {
|
||||
$q->whereIn('name', $user->getRoleNames());
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$integration->load([
|
||||
'agent',
|
||||
'template',
|
||||
'serviceTasks.service',
|
||||
'serviceTasks' => $serviceTaskConstraint,
|
||||
'serviceTasks.service',
|
||||
'serviceTasks.integrationRequest',
|
||||
'serviceTasks.taskItems',
|
||||
'serviceTasks.comments.user',
|
||||
'serviceTasks.attachments',
|
||||
@@ -77,6 +90,10 @@ class IntegrationController extends Controller
|
||||
|
||||
public function downloadPdf(IntegrationRequest $integration)
|
||||
{
|
||||
if ($integration->status !== \App\Enums\IntegrationStatus::Completed) {
|
||||
abort(403, 'Le téléchargement de la fiche agent n\'est possible que lorsque le processus est terminé.');
|
||||
}
|
||||
|
||||
// Load relationships needed for the PDF
|
||||
$integration->load([
|
||||
'agent',
|
||||
|
||||
100
app/Http/Controllers/RoleController.php
Normal file
100
app/Http/Controllers/RoleController.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
|
||||
class RoleController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if (!auth()->user()->hasRole('Admin')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
return Inertia::render('Role/Index', [
|
||||
'roles' => Role::with('permissions')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
if (!auth()->user()->hasRole('Admin')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
return Inertia::render('Role/Create', [
|
||||
'permissions' => Permission::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!auth()->user()->hasRole('Admin')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|unique:roles,name',
|
||||
'permissions' => 'array',
|
||||
]);
|
||||
|
||||
$role = Role::create(['name' => $validated['name']]);
|
||||
|
||||
if (!empty($validated['permissions'])) {
|
||||
$role->syncPermissions($validated['permissions']);
|
||||
}
|
||||
|
||||
return redirect()->route('roles.index')->with('success', 'Rôle créé avec succès.');
|
||||
}
|
||||
|
||||
public function edit(Role $role)
|
||||
{
|
||||
if (!auth()->user()->hasRole('Admin')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
return Inertia::render('Role/Edit', [
|
||||
'role' => $role->load('permissions'),
|
||||
'permissions' => Permission::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, Role $role)
|
||||
{
|
||||
if (!auth()->user()->hasRole('Admin')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|unique:roles,name,' . $role->id,
|
||||
'permissions' => 'array',
|
||||
]);
|
||||
|
||||
$role->update(['name' => $validated['name']]);
|
||||
|
||||
if (isset($validated['permissions'])) {
|
||||
$role->syncPermissions($validated['permissions']);
|
||||
}
|
||||
|
||||
return redirect()->route('roles.index')->with('success', 'Rôle mis à jour avec succès.');
|
||||
}
|
||||
|
||||
public function destroy(Role $role)
|
||||
{
|
||||
if (!auth()->user()->hasRole('Admin')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
if ($role->name === 'Admin') {
|
||||
return back()->with('error', 'Le rôle Admin ne peut pas être supprimé.');
|
||||
}
|
||||
|
||||
$role->delete();
|
||||
|
||||
return redirect()->route('roles.index')->with('success', 'Rôle supprimé avec succès.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user