From d8cdc7dd73f10212c5df0982ca822cfc8faba3cd Mon Sep 17 00:00:00 2001 From: sermandm Date: Thu, 8 May 2025 15:34:12 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=A8=E2=80=8D=F0=9F=94=A7=20Ajout=20acc?= =?UTF-8?q?=C3=A8s=20interventions=20pour=20chauffagiste=20+=20bouton=20re?= =?UTF-8?q?marque=20+=20s=C3=A9curisation=20route=20show?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/InterventionController.php | 24 +++++++++++- templates/base.html.twig | 3 +- .../intervention/indexChauffagiste.html.twig | 38 +++++++++++++++++++ templates/intervention/show.html.twig | 11 +++--- 4 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 templates/intervention/indexChauffagiste.html.twig diff --git a/src/Controller/InterventionController.php b/src/Controller/InterventionController.php index da1f290..1cd6c26 100644 --- a/src/Controller/InterventionController.php +++ b/src/Controller/InterventionController.php @@ -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 { - $this->denyUnlessAdminOrSecretaire(); + // ✅ 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, ]); diff --git a/templates/base.html.twig b/templates/base.html.twig index 900a8e7..7a2b121 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -117,8 +117,7 @@ {% if is_granted('ROLE_CHAUFFAGISTE') %}
  • Dashboard Chauffagiste
  • -
  • Mes interventions
  • -
  • Pièces détachées
  • +
  • Mes interventions
  • Mon planning
  • {% endif %} diff --git a/templates/intervention/indexChauffagiste.html.twig b/templates/intervention/indexChauffagiste.html.twig new file mode 100644 index 0000000..397dc13 --- /dev/null +++ b/templates/intervention/indexChauffagiste.html.twig @@ -0,0 +1,38 @@ +{% extends 'base.html.twig' %} + +{% block title %}Mes interventions{% endblock %} + +{% block body %} +

    📋 Mes interventions

    + + {% if interventions is not empty %} + + + + + + + + + + + + {% for intervention in interventions %} + + + + + + + + {% endfor %} + +
    DateDescriptionAdresseStatut
    {{ intervention.Timestamp ? intervention.Timestamp|date('d/m/Y H:i') : '' }}{{ intervention.Description }}{{ intervention.Address }}{{ intervention.Status }} + + Voir + +
    + {% else %} +

    Vous n’avez aucune intervention assignée.

    + {% endif %} +{% endblock %} diff --git a/templates/intervention/show.html.twig b/templates/intervention/show.html.twig index d118dff..fe4dcc2 100644 --- a/templates/intervention/show.html.twig +++ b/templates/intervention/show.html.twig @@ -63,14 +63,13 @@ {% endif %} - {% if is_granted('ROLE_CHAUFFAGISTE') and intervention.user == app.user %} - - 📝 Ajouter une remarque - - {% endif %} - + {% if is_granted('ROLE_CHAUFFAGISTE') and intervention.user == app.user %} + + 📝 Ajouter une remarque + + {% endif %} Retour à la liste Modifier