diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index f69cbb4..f10e193 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -215,6 +215,28 @@ class UserController extends AbstractController throw $this->createAccessDeniedException(self::ACCESS_DENIED); } + #[Route('/activate/{id}', name: 'activate', methods: ['GET', 'POST'])] + public function activate(int $id): Response + { + $this->denyAccessUnlessGranted('ROLE_ADMIN'); + $actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); + if ($this->userService->hasAccessTo($actingUser, true)) { + $user = $this->entityManager->getRepository(User::class)->find($id); + if (!$user) { + throw $this->createNotFoundException(self::NOT_FOUND); + } + $user->setIsActive(true); + $user->setModifiedAt(new \DateTimeImmutable('now')); + $this->entityManager->persist($user); + $this->entityManager->flush(); + $this->actionService->createAction("Activate user", $actingUser, null, $user->getUserIdentifier()); + + return $this->redirectToRoute('user_index'); + } + + throw $this->createAccessDeniedException(self::ACCESS_DENIED); + } + #[Route('/organization/deactivate/{id}', name: 'deactivate_organization', methods: ['GET', 'POST'])] public function deactivateUserInOrganization(int $id, Request $request): Response { diff --git a/templates/user/show.html.twig b/templates/user/show.html.twig index 6f80ce7..dfecaf2 100644 --- a/templates/user/show.html.twig +++ b/templates/user/show.html.twig @@ -12,7 +12,11 @@ {% if is_granted("ROLE_SUPER_ADMIN") %} Supprimer {% endif %} + {% if user.active %} Désactiver + {% else %} + Activer + {% endif %} diff --git a/templates/user/userInformation.html.twig b/templates/user/userInformation.html.twig index dc5bd2d..f16ae22 100644 --- a/templates/user/userInformation.html.twig +++ b/templates/user/userInformation.html.twig @@ -20,7 +20,7 @@
{% endif %} {% endif %}