From 943752a00297eab53a102ce381686e364796e05f Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 28 Jul 2025 11:38:16 +0200 Subject: [PATCH] Display all organizations --- assets/icons/bi/building.svg | 1 + assets/icons/bi/buildings.svg | 1 + src/Controller/OrganizationController.php | 49 ++++++++++++++++++- templates/elements/menu.html.twig | 19 ++++++- templates/organization/index.html.twig | 47 ++++++++++++++++++ templates/organization/show.html.twig | 10 ++++ .../{profile.html.twig => show.html.twig} | 0 7 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 assets/icons/bi/building.svg create mode 100644 assets/icons/bi/buildings.svg create mode 100644 templates/organization/index.html.twig create mode 100644 templates/organization/show.html.twig rename templates/user/{profile.html.twig => show.html.twig} (100%) diff --git a/assets/icons/bi/building.svg b/assets/icons/bi/building.svg new file mode 100644 index 0000000..ec01f90 --- /dev/null +++ b/assets/icons/bi/building.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/icons/bi/buildings.svg b/assets/icons/bi/buildings.svg new file mode 100644 index 0000000..9d60dbe --- /dev/null +++ b/assets/icons/bi/buildings.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/Controller/OrganizationController.php b/src/Controller/OrganizationController.php index f725dd7..9bb7fd5 100644 --- a/src/Controller/OrganizationController.php +++ b/src/Controller/OrganizationController.php @@ -2,14 +2,61 @@ namespace App\Controller; +use App\Entity\UsersOrganizations; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Routing\Attribute\Route; +use App\Entity\Organizations; +use Symfony\Component\HttpFoundation\Response; #[Route(path: '/organization', name: 'organization_')] class OrganizationController extends AbstractController { + private const NOT_FOUND = 'Entity not found'; + private const ACCESS_DENIED = 'Access denied'; + public function __construct(private readonly EntityManagerInterface $entityManager) + { + } + #[Route(path: '/' , name: 'index', methods: ['GET'])] + public function index():Response + { + if($this->isGranted('ROLE_SUPER_ADMIN')) + { + $organizations = $this->entityManager->getRepository(Organizations::class)->findBy(['isActive' => true]); + } else{ + $user = $this->getUser(); + if (!$user) { + return $this->redirectToRoute('app_login'); + } + $userIdentifier = $user->getUserIdentifier(); -} \ No newline at end of file + $organizations = $this->entityManager->getRepository(UsersOrganizations::class)->findOrganizationsByUserEmailAndRoleName($userIdentifier, 'ADMIN'); + if(!$organizations) { +// if user is not admin in any organization, throw access denied + throw $this->createNotFoundException(self::ACCESS_DENIED); + } + } + + return $this->render('organization/index.html.twig', [ + 'organizations' => $organizations, + ]); + } + + #[Route(path: '/{id}', name: 'show', methods: ['GET'])] + public function show(int $id): Response + { + $organization = $this->entityManager->getRepository(Organizations::class)->find($id); + + if (!$organization) { + throw $this->createNotFoundException(self::NOT_FOUND); + } + + return $this->render('organization/show.html.twig', [ + 'organization' => $organization, + ]); + } + +} diff --git a/templates/elements/menu.html.twig b/templates/elements/menu.html.twig index dfbfbed..261f795 100644 --- a/templates/elements/menu.html.twig +++ b/templates/elements/menu.html.twig @@ -26,10 +26,27 @@ {% if is_granted('ROLE_ADMIN') %} + {% endif %} \ No newline at end of file diff --git a/templates/organization/index.html.twig b/templates/organization/index.html.twig new file mode 100644 index 0000000..b19df11 --- /dev/null +++ b/templates/organization/index.html.twig @@ -0,0 +1,47 @@ +{% extends 'base.html.twig' %} + +{% block title %} Gestion des organisations {% endblock %} + +{% block body %} +
+
+

Gestion des organisations

+{# Ajouter une organisation#} +
+ {% if organizations|length == 0 %} + + Aucune organisation trouvée. + + {% else %} + + + + + + + + + + + {% for organization in organizations %} + + + + + + + {% endfor %} + +
LogoNomEmailVisualiser
+ {% if organization.logoUrl %} + Organization logo + {% endif %} + {{ organization.name }}{{ organization.email }} + + {{ ux_icon('fa6-regular:eye', {height: '30px', width: '30px'}) }} + +
+ {% endif %} + +
+{% endblock %} \ No newline at end of file diff --git a/templates/organization/show.html.twig b/templates/organization/show.html.twig new file mode 100644 index 0000000..90bf331 --- /dev/null +++ b/templates/organization/show.html.twig @@ -0,0 +1,10 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +{% endblock %} + +{% block title %} + {{ organization.name|title }} - Dashboard +{% endblock %} + diff --git a/templates/user/profile.html.twig b/templates/user/show.html.twig similarity index 100% rename from templates/user/profile.html.twig rename to templates/user/show.html.twig