Roles adjustment

This commit is contained in:
Charles 2025-07-17 15:55:09 +02:00
parent 3271da59fa
commit 1d2debf364
5 changed files with 53 additions and 23 deletions

View File

@ -11,9 +11,8 @@ security:
property: email property: email
role_hierarchy: role_hierarchy:
ROLE_SUDALYS: ROLE_USER
ROLE_ADMIN: 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: firewalls:

View File

@ -0,0 +1,15 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Attribute\Route;
#[Route(path: '/organization', name: 'organization_')]
class OrganizationController extends AbstractController
{
}

View File

@ -29,7 +29,7 @@ class UserController extends AbstractController
#[Route('/', name: 'index', methods: ['GET'])] #[Route('/', name: 'index', methods: ['GET'])]
public function index(EntityManagerInterface $entityManager): Response public function index(EntityManagerInterface $entityManager): Response
{ {
if ($this->isGranted('ROLE_SUDALYS_ADMIN')) { if ($this->isGranted('ROLE_SUPER_ADMIN')) {
$users = $entityManager->getRepository(User::class)->getAllActiveUsers(); $users = $entityManager->getRepository(User::class)->getAllActiveUsers();
} else { } else {
$users = 'Not Super Admin'; $users = 'Not Super Admin';
@ -46,7 +46,7 @@ class UserController extends AbstractController
#[Route('/{id}', name: 'show', requirements: ['id' => '\d+'], methods: ['GET'])] #[Route('/{id}', name: 'show', requirements: ['id' => '\d+'], methods: ['GET'])]
public function show(int $id, EntityManagerInterface $entityManager): Response 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'); throw $this->createAccessDeniedException('Access denied');
} }
@ -102,7 +102,7 @@ class UserController extends AbstractController
public function edit(int $id, EntityManagerInterface $entityManager, Request $request): Response public function edit(int $id, EntityManagerInterface $entityManager, Request $request): Response
{ {
//Handle access control //Handle access control
if (!$this->isGranted('ROLE_SUDALYS_ADMIN')) { if (!$this->isGranted('ROLE_SUPER_ADMIN')) {
throw $this->createAccessDeniedException('Access denied'); 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. //This method is used to set a user as deleted without actually removing them from the database.
//Handle access control //Handle access control
if (!$this->isGranted('ROLE_SUDALYS_ADMIN')) { if (!$this->isGranted('ROLE_SUPER_ADMIN')) {
throw $this->createAccessDeniedException('Access denied'); throw $this->createAccessDeniedException('Access denied');
} }
//Fetch user by ID and handle not found case //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'])] #[Route('/{id}', name: 'delete', requirements: ['id' => '\d+'], methods: ['DELETE'])]
public function delete(int $id, EntityManagerInterface $entityManager): Response 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'); throw $this->createAccessDeniedException('Access denied');
} }
@ -183,9 +183,9 @@ class UserController extends AbstractController
#[Route('/deactivate/{id}', name: 'deactivate', methods: ['GET'])] #[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'); $userId = $request->attributes->get('id');
$user = $entityManager->getRepository(User::class)->find($userId); $user = $entityManager->getRepository(User::class)->find($userId);
if (!$user) { if (!$user) {
@ -199,6 +199,23 @@ class UserController extends AbstractController
return new Response('Unauthorized', Response::HTTP_UNAUTHORIZED); 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()]);
}
} }

View File

@ -23,7 +23,7 @@
</div> </div>
</li> </li>
{# if user is Super Admin#} {# if user is Super Admin#}
{% if is_granted('ROLE_SUDALYS_ADMIN') %} {% if is_granted('ROLE_SUPER_ADMIN') %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{{ path('user_index') }}"> <a class="nav-link" href="{{ path('user_index') }}">
<i class="icon-grid menu-icon">{{ ux_icon('bi:menu-up', {height: '15px', width: '15px'}) }}</i> <i class="icon-grid menu-icon">{{ ux_icon('bi:menu-up', {height: '15px', width: '15px'}) }}</i>

View File

@ -4,13 +4,16 @@
<div class="card col-4 mt-3 me-3 user-org-card" style="cursor:pointer;" data-bs-toggle="collapse" <div class="card col-4 mt-3 me-3 user-org-card" style="cursor:pointer;" data-bs-toggle="collapse"
data-bs-target="#org-details-{{ organization.id }}" aria-expanded="false" data-bs-target="#org-details-{{ organization.id }}" aria-expanded="false"
aria-controls="org-details-{{ organization.id }}"> aria-controls="org-details-{{ organization.id }}">
<div class="card-title shadow-sm p-3 ">
<div class="card-title shadow-sm p-3 d-flex "> <div class="d-flex ">
<h2 class=" pe-2">{{ organization.name|capitalize }}</h2> <h2 class=" pe-2">{{ organization.name|capitalize }}</h2>
<i class="pt-2" id="arrow-icon-{{ organization.id }}"> <i class="pt-2" id="arrow-icon-{{ organization.id }}">
{{ ux_icon('fa6-regular:circle-down', {height: '25px', width: '25px'}) }} {{ ux_icon('fa6-regular:circle-down', {height: '25px', width: '25px'}) }}
</i> </i>
</div> </div>
{# <a href="{{ path('user_organization_edit', {'id': user.id}) }}" class="btn btn-primary">Modifier</a>#}
</div>
{# Information principale sur l'utilisateur dans l'organisation#} {# Information principale sur l'utilisateur dans l'organisation#}
<div class="card-body"> <div class="card-body">
@ -18,12 +21,10 @@
<p><b>Role:</b> <p><b>Role:</b>
{% if roles|length > 0 %} {% if roles|length > 0 %}
{% set firstRole = roles[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" %}
<span class="badge bg-danger">{{ firstRole.name|capitalize }}</span> <span class="badge bg-danger">{{ firstRole.name|capitalize }}</span>
{% elseif firstRole.name == "ROLE USER" %}
<span class="badge bg-primary">{{ firstRole.name|capitalize }}</span>
{% else %} {% else %}
<span class="badge bg-success">{{ firstRole.name|capitalize }}</span> <span class="badge bg-primary">{{ firstRole.name|capitalize }}</span>
{% endif %} {% endif %}
{% else %} {% else %}
Aucun rôle Aucun rôle
@ -50,12 +51,10 @@
{% if roles|length > 1 %} {% if roles|length > 1 %}
<p><b>Autres rôles:</b> <p><b>Autres rôles:</b>
{% for role in roles|slice(1) %} {% 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" %}
<span class="badge bg-danger">{{ role.name|capitalize }}</span> <span class="badge bg-danger">{{ role.name|capitalize }}</span>
{% elseif role.name == "ROLE USER" %}
<span class="badge bg-primary">{{ role.name|capitalize }}</span>
{% else %} {% else %}
<span class="badge bg-success">{{ role.name|capitalize }}</span> <span class="badge bg-primary">{{ role.name|capitalize }}</span>
{% endif %} {% endif %}
{% if not loop.last %} - {% endif %} {% if not loop.last %} - {% endif %}
{% endfor %} {% endfor %}