From 446f585cc9e43a314d1dc98e18d5dacf9aa73022 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 28 Aug 2025 15:44:51 +0200 Subject: [PATCH] activate a user from organization --- src/Controller/UserController.php | 38 ++++++++++++++++++++++-- templates/user/userInformation.html.twig | 26 +++++++++++----- 2 files changed, 54 insertions(+), 10 deletions(-) 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 @@
- user + user

{{ user.surname|capitalize }} {{ user.name|capitalize }}

{% if organizationId is not null %} -
- - -
+ {% if uoActive %} +
+ + +
+ {% else %} +
+ + +
+ {% endif %} {% endif %} Modifier
-

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é' }}