diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index e2ccf64..62f5d17 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -187,6 +187,11 @@ class UserController extends AbstractController } + /** + * GET /user/deactivate/{id} - Deactivate user + * This method is used to deactivate a user without deleting them. + * The user will still exist in the database but will not be active. + */ #[Route('/deactivate/{id}', name: 'deactivate', methods: ['GET'])] public function deactivate(Request $request, EntityManagerInterface $entityManager): Response { @@ -284,4 +289,22 @@ class UserController extends AbstractController 'selectedAppIds' => $selectedApps,]); } + /** + * GET /user/deactivateOrganization/{id} - Deactivate user + * This method is used to deactivate a user without deleting them in an organization. + * The user will still exist in the database but will not be active. + */ + #[Route('/organizationDeactivate/{id}', name: 'organization_deactivate', requirements: ['id' => '\d+'], methods: ['GET'])] + public function deactivateUserOrganization(int $id, Request $request, EntityManagerInterface $entityManager): Response + { + $this->denyAccessUnlessGranted('ROLE_ADMIN'); + $userOrganization = $entityManager->getRepository(UsersOrganizations::class)->find($id) ?? throw $this->createNotFoundException(self::NOT_FOUND); + $user = $userOrganization->getUsers() ?? throw $this->createNotFoundException(self::NOT_FOUND); + $organization = $userOrganization->getOrganization() ?? throw $this->createNotFoundException(self::NOT_FOUND); + + $this->userOrganizationService->deactivateAllUserRoles($user, $organization); + + return $this->redirectToRoute('user_show', ['id' => $user->getId()]); + } + } diff --git a/templates/user/organization/edit.html.twig b/templates/user/organization/edit.html.twig index 43e0880..410cb5e 100644 --- a/templates/user/organization/edit.html.twig +++ b/templates/user/organization/edit.html.twig @@ -12,10 +12,10 @@ Modification de : {{ user.name|capitalize }} {{ user.surname|capitalize }} chez {{ uo.organization.name }} - Supprimer + Supprimer
-