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 %}