From 371c511ecfa0256c9db93d0de0bed9d7ff5c6512 Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 6 Aug 2025 14:48:41 +0200 Subject: [PATCH] deactivate organization --- src/Controller/OrganizationController.php | 20 ++++++++++++++++++++ templates/organization/show.html.twig | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/src/Controller/OrganizationController.php b/src/Controller/OrganizationController.php index 4320576..c17216e 100644 --- a/src/Controller/OrganizationController.php +++ b/src/Controller/OrganizationController.php @@ -178,5 +178,25 @@ class OrganizationController extends AbstractController ]); } + #[Route('/deactivate/{id}', name: 'deactivate', requirements: ['id' => '\d+'], methods: ['GET', 'POST'])] + public function deactivate(Request $request): Response + { + $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN'); + $id = $request->attributes->get('id'); + $organization = $this->entityManager->getRepository(Organizations::class)->find($id); + if (!$organization) { + throw $this->createNotFoundException(self::NOT_FOUND); + } + if ($organization->isActive() === false) { + $this->addFlash('error', 'Organization is already deactivated'); + return $this->redirectToRoute('organization_index'); + } + + $organization->setIsActive(false); + $this->entityManager->persist($organization); + $this->entityManager->flush(); + $this->addFlash('success', 'Organization deactivated successfully'); + return $this->redirectToRoute('organization_index'); + } } diff --git a/templates/organization/show.html.twig b/templates/organization/show.html.twig index a60df7d..920ceef 100644 --- a/templates/organization/show.html.twig +++ b/templates/organization/show.html.twig @@ -10,6 +10,10 @@ {% endif %} {{ organization.name|title }} - Dashboard {% if is_granted("ROLE_SUPER_ADMIN") %} + Gérer l'organisation + Désactiver l'organisation + {% elseif is_granted("ROLE_ADMIN") %} Gérer mon organisation {% endif %}