👨‍🔧 Ajout accès interventions pour chauffagiste + bouton remarque + sécurisation route show

This commit is contained in:
sermandm 2025-05-08 15:34:12 +02:00
parent aaa66849be
commit d8cdc7dd73
4 changed files with 67 additions and 9 deletions

View File

@ -75,10 +75,32 @@ class InterventionController extends AbstractController
]);
}
#[Route('/mes-interventions', name: 'app_intervention_mes', methods: ['GET'])]
public function mesInterventions(InterventionRepository $interventionRepository): Response
{
$this->denyAccessUnlessGranted('ROLE_CHAUFFAGISTE');
$user = $this->getUser();
$interventions = $interventionRepository->findBy(['user' => $user]);
return $this->render('intervention/indexChauffagiste.html.twig', [
'interventions' => $interventions,
]);
}
#[Route('/{id}', name: 'app_intervention_show', methods: ['GET'])]
public function show(Intervention $intervention): Response
{
// ✅ Si l'utilisateur est un chauffagiste, il ne peut voir que ses interventions
if ($this->isGranted('ROLE_CHAUFFAGISTE')) {
if ($intervention->getUser() !== $this->getUser()) {
throw $this->createAccessDeniedException('Accès refusé à cette intervention.');
}
} else {
// ✅ Sinon, seuls admin/secrétaire peuvent accéder à tout
$this->denyUnlessAdminOrSecretaire();
}
return $this->render('intervention/show.html.twig', [
'intervention' => $intervention,
]);

View File

@ -117,8 +117,7 @@
{% if is_granted('ROLE_CHAUFFAGISTE') %}
<li><a href="{{ path('chauffagiste_dashboard') }}">Dashboard Chauffagiste</a></li>
<li><a href="{{ path('app_intervention_index') }}">Mes interventions</a></li>
<li><a href="{{ path('app_stock_index') }}">Pièces détachées</a></li>
<li><a href="{{ path('app_intervention_mes') }}">Mes interventions</a></li>
<li><a href="{{ path('app_calendrier_indexChauffagiste') }}">Mon planning</a></li>
{% endif %}
</ul>

View File

@ -0,0 +1,38 @@
{% extends 'base.html.twig' %}
{% block title %}Mes interventions{% endblock %}
{% block body %}
<h1>📋 Mes interventions</h1>
{% if interventions is not empty %}
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Description</th>
<th>Adresse</th>
<th>Statut</th>
<th></th>
</tr>
</thead>
<tbody>
{% for intervention in interventions %}
<tr>
<td>{{ intervention.Timestamp ? intervention.Timestamp|date('d/m/Y H:i') : '' }}</td>
<td>{{ intervention.Description }}</td>
<td>{{ intervention.Address }}</td>
<td>{{ intervention.Status }}</td>
<td>
<a href="{{ path('app_intervention_show', {'id': intervention.id}) }}" class="btn btn-primary btn-sm">
Voir
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>Vous navez aucune intervention assignée.</p>
{% endif %}
{% endblock %}

View File

@ -63,14 +63,13 @@
{% endif %}
</td>
</tr>
</tbody>
</table>
{% if is_granted('ROLE_CHAUFFAGISTE') and intervention.user == app.user %}
<a href="{{ path('app_intervention_remarque', {'id': intervention.id}) }}" class="btn btn-outline-primary">
📝 Ajouter une remarque
</a>
{% endif %}
</tbody>
</table>
<a href="{{ path('app_intervention_index') }}" class="btn btn-primary">Retour à la liste</a>
<a href="{{ path('app_intervention_edit', {'id': intervention.id}) }}" class="btn btn-warning">Modifier</a>