diff --git a/config/packages/security.yaml b/config/packages/security.yaml index c4e3033..542c62f 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -11,9 +11,8 @@ security: property: email role_hierarchy: - ROLE_SUDALYS: ROLE_USER ROLE_ADMIN: ROLE_USER - ROLE_SUDALYS_ADMIN: [ROLE_SUDALYS, ROLE_ALLOWED_TO_SWITCH, ROLE_ADMIN] + ROLE_SUPER_ADMIN: [ROLE_ALLOWED_TO_SWITCH, ROLE_ADMIN] firewalls: diff --git a/src/Controller/OrganizationController.php b/src/Controller/OrganizationController.php new file mode 100644 index 0000000..f725dd7 --- /dev/null +++ b/src/Controller/OrganizationController.php @@ -0,0 +1,15 @@ +isGranted('ROLE_SUDALYS_ADMIN')) { + if ($this->isGranted('ROLE_SUPER_ADMIN')) { $users = $entityManager->getRepository(User::class)->getAllActiveUsers(); } else { $users = 'Not Super Admin'; @@ -46,7 +46,7 @@ class UserController extends AbstractController #[Route('/{id}', name: 'show', requirements: ['id' => '\d+'], methods: ['GET'])] public function show(int $id, EntityManagerInterface $entityManager): Response { - if (!$this->isGranted('ROLE_SUDALYS_ADMIN')) { + if (!$this->isGranted('ROLE_SUPER_ADMIN')) { throw $this->createAccessDeniedException('Access denied'); } @@ -102,7 +102,7 @@ class UserController extends AbstractController public function edit(int $id, EntityManagerInterface $entityManager, Request $request): Response { //Handle access control - if (!$this->isGranted('ROLE_SUDALYS_ADMIN')) { + if (!$this->isGranted('ROLE_SUPER_ADMIN')) { throw $this->createAccessDeniedException('Access denied'); } @@ -142,7 +142,7 @@ class UserController extends AbstractController //This method is used to set a user as deleted without actually removing them from the database. //Handle access control - if (!$this->isGranted('ROLE_SUDALYS_ADMIN')) { + if (!$this->isGranted('ROLE_SUPER_ADMIN')) { throw $this->createAccessDeniedException('Access denied'); } //Fetch user by ID and handle not found case @@ -165,7 +165,7 @@ class UserController extends AbstractController #[Route('/{id}', name: 'delete', requirements: ['id' => '\d+'], methods: ['DELETE'])] public function delete(int $id, EntityManagerInterface $entityManager): Response { - if (!$this->isGranted('ROLE_SUDALYS_ADMIN')) { + if (!$this->isGranted('ROLE_SUPER_ADMIN')) { throw $this->createAccessDeniedException('Access denied'); } @@ -183,9 +183,9 @@ class UserController extends AbstractController #[Route('/deactivate/{id}', name: 'deactivate', methods: ['GET'])] - public function userDeactivate(Request $request, EntityManagerInterface $entityManager): Response + public function deactivate(Request $request, EntityManagerInterface $entityManager): Response { - if ($this->isGranted('ROLE_SUDALYS_ADMIN')) { + if ($this->isGranted('ROLE_SUPER_ADMIN')) { $userId = $request->attributes->get('id'); $user = $entityManager->getRepository(User::class)->find($userId); if (!$user) { @@ -199,6 +199,23 @@ class UserController extends AbstractController return new Response('Unauthorized', Response::HTTP_UNAUTHORIZED); } + #Route('/organizationsUserEdit/{id}', name: 'organization_user_edit', requirements: ['id' => '\d+'], methods: ['POST'])] + public function organizationUserEdit(int $id, Request $request, EntityManagerInterface $entityManager): Response + { + if (!$this->isGranted('ROLE_SUPER_ADMIN')) { + throw $this->createAccessDeniedException('Access denied'); + } + + $user = $entityManager->getRepository(User::class)->find($id); + if (!$user) { + throw $this->createNotFoundException(self::NOT_FOUND); + } + + // Handle organization user edit logic here + + return $this->redirectToRoute('user_show', ['id' => $user->getId()]); + } + } diff --git a/templates/elements/menu.html.twig b/templates/elements/menu.html.twig index 7ce9f8c..1a1ffb2 100644 --- a/templates/elements/menu.html.twig +++ b/templates/elements/menu.html.twig @@ -23,7 +23,7 @@ {# if user is Super Admin#} - {% if is_granted('ROLE_SUDALYS_ADMIN') %} + {% if is_granted('ROLE_SUPER_ADMIN') %}
Role: {% if roles|length > 0 %} {% set firstRole = roles[0] %} - {% if firstRole.name == "ROLE ADMIN SUDALYS" or firstRole.name == "ROLE ADMIN" %} + {% if firstRole.name == "SUPER ADMIN" or firstRole.name == "ADMIN" %} {{ firstRole.name|capitalize }} - {% elseif firstRole.name == "ROLE USER" %} - {{ firstRole.name|capitalize }} {% else %} - {{ firstRole.name|capitalize }} + {{ firstRole.name|capitalize }} {% endif %} {% else %} Aucun rôle @@ -50,12 +51,10 @@ {% if roles|length > 1 %}
Autres rôles: {% for role in roles|slice(1) %} - {% if role.name == "ROLE ADMIN SUDALYS" or role.name == "ROLE ADMIN" %} + {% if role.name == "SUPER ADMIN" or role.name == "ADMIN" %} {{ role.name|capitalize }} - {% elseif role.name == "ROLE USER" %} - {{ role.name|capitalize }} {% else %} - {{ role.name|capitalize }} + {{ role.name|capitalize }} {% endif %} {% if not loop.last %} - {% endif %} {% endfor %}