diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 80428a3..fbe7274 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -79,10 +79,11 @@ class UserController extends AbstractController $orgId = $request->query->get('organizationId'); if ($orgId) { $orgs = $this->entityManager->getRepository(Organizations::class)->findBy(['id' => $orgId]); - $uo = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['users' => $user, 'organization' => $orgs, 'isActive' => true]); + $uo = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['users' => $user, 'organization' => $orgs]); if (!$uo) { throw $this->createNotFoundException(self::NOT_FOUND); } + $uoActive = $uo[0]->isActive(); } else { $uo = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['users' => $user, 'isActive' => true]); foreach ($uo as $u) { @@ -103,7 +104,8 @@ class UserController extends AbstractController 'user' => $user, 'uoas' => $uoa ?? null, 'orgs' => $orgs ?? null, - 'organizationId' => $orgId ?? null, // specific for single organization context and deactivate user from said org + 'organizationId' => $orgId ?? null, + 'uoActive' => $uoActive ?? null// specific for single organization context and deactivate user from said org ]); } @@ -245,4 +247,36 @@ class UserController extends AbstractController throw $this->createAccessDeniedException(self::ACCESS_DENIED); } + + #[Route('/organization/activate/{id}', name: 'activate_organization', methods: ['GET', 'POST'])] + public function activateUserInOrganization(int $id, Request $request): Response + { + $this->denyAccessUnlessGranted('ROLE_ADMIN'); + $actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); + if ($this->userService->hasAccessTo($actingUser, true)) { + $orgId = $request->get('organizationId'); + $org = $this->entityManager->getRepository(Organizations::class)->find($orgId); + if (!$org) { + throw $this->createNotFoundException(self::NOT_FOUND); + } + $user = $this->entityManager->getRepository(User::class)->find($id); + if (!$user) { + throw $this->createNotFoundException(self::NOT_FOUND); + } + $uo = $this->entityManager->getRepository(UsersOrganizations::class)->findOneBy(['users' => $user, + 'organization' => $org, + 'isActive' => false]); + if (!$uo) { + throw $this->createNotFoundException(self::NOT_FOUND); + } + $uo->setIsActive(true); + $this->entityManager->persist($uo); + $this->entityManager->flush(); + $this->actionService->createAction("Activate user in organization", $actingUser, $org, $org->getName()." for user ".$user->getUserIdentifier()); + + return $this->redirectToRoute('user_index'); + } + + throw $this->createAccessDeniedException(self::ACCESS_DENIED); + } } diff --git a/templates/user/userInformation.html.twig b/templates/user/userInformation.html.twig index 5fafac5..dc5bd2d 100644 --- a/templates/user/userInformation.html.twig +++ b/templates/user/userInformation.html.twig @@ -3,24 +3,34 @@
Email: {{ user.email }}
-Dernière connection: {{ user.lastConnection|date('d/m/Y') }} à {{ user.lastConnection|date('H:m:s') }}
+Email: {{ user.email }}
+Dernière connection: {{ user.lastConnection|date('d/m/Y') }} + à {{ user.lastConnection|date('H:m:s') }}
Compte crée le: {{ user.createdAt|date('d/m/Y') }}
Numéro de téléphone: {{ user.phoneNumber ? user.phoneNumber : 'Non renseigné' }}