From 2b9b030d9aa674c598571dc695af644ec6f81b8f Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 21 Oct 2025 16:45:02 +0200 Subject: [PATCH] gestion droit d'access --- src/Controller/UserController.php | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 29bd112..28bdd08 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -57,15 +57,6 @@ class UserController extends AbstractController //Log action $this->actionService->createAction("View all users", $user, null, "All"); - } elseif ($this->isGranted('ROLE_ADMIN')) { - $orgIds = $this->userService->getAdminOrganizationsIds($user); - if (empty($orgIds)) { - $usersByOrganization = []; - } else { - $uo = $this->entityManager->getRepository(UsersOrganizations::class)->findUsersWithOrganization($orgIds); - $usersByOrganization = $this->userService->groupByOrganization($uo); - $this->actionService->createAction("View all users for organizations", $user, null, implode(", ", $orgIds)); - } } else { $usersByOrganization = []; } @@ -433,10 +424,14 @@ class UserController extends AbstractController #[Route(path: '/indexTest', name: 'indexTest', methods: ['GET'])] public function indexTest(): Response { - $totalUsers = $this->entityManager->getRepository(User::class)->count(['isDeleted' => false, 'isActive' => true]); - return $this->render('user/indexTest.html.twig', [ - 'users' => $totalUsers - ]); + $actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); + if ($this->userService->hasAccessTo($actingUser, true) && $this->isGranted("ROLE_ADMIN")) { + $totalUsers = $this->entityManager->getRepository(User::class)->count(['isDeleted' => false, 'isActive' => true]); + return $this->render('user/indexTest.html.twig', [ + 'users' => $totalUsers + ]); + } + throw $this->createAccessDeniedException(self::ACCESS_DENIED); } /*