From 68864b399755760a5708ba4da22db56af4408e63 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 22 Dec 2025 10:04:11 +0100 Subject: [PATCH] Correct organization display logic --- assets/controllers/organization_controller.js | 2 +- src/Controller/OrganizationController.php | 33 ++----------------- templates/organization/index.html.twig | 21 ++++-------- 3 files changed, 9 insertions(+), 47 deletions(-) diff --git a/assets/controllers/organization_controller.js b/assets/controllers/organization_controller.js index 21a2eea..063d069 100644 --- a/assets/controllers/organization_controller.js +++ b/assets/controllers/organization_controller.js @@ -28,7 +28,7 @@ export default class extends Controller { const table = new Tabulator("#tabulator-org", { // Register locales here langs: TABULATOR_FR_LANG, - + placeholder: "Aucun résultat trouvé pour cette recherche", locale: "fr", //'en' for English, 'fr' for French (en is default, no need to include it) ajaxURL: "/organization/data", diff --git a/src/Controller/OrganizationController.php b/src/Controller/OrganizationController.php index 45fadef..2988072 100644 --- a/src/Controller/OrganizationController.php +++ b/src/Controller/OrganizationController.php @@ -48,40 +48,11 @@ class OrganizationController extends AbstractController public function index(): Response { $this->denyAccessUnlessGranted('ROLE_ADMIN'); - $user = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); - if ($this->isGranted("ROLE_SUPER_ADMIN")) { - $organizations = $this->organizationsRepository->findBy(['isDeleted' => false]); + $orgCount = $this->organizationsRepository->count(['isDeleted' => false]); - } else { - //get all the UO of the user - $uos = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['users' => $user]); - $organizations = []; - $roleAdmin = $this->entityManager->getRepository(Roles::class)->findOneBy(['name' => 'ADMIN']); - foreach ($uos as $uo) { - $uoaAdmin = $this->entityManager->getRepository(UserOrganizatonApp::class)->findOneBy(['userOrganization' => $uo, 'role' => $roleAdmin]); - if ($uoaAdmin) { - $organizations[] = $uo->getOrganization(); - } - } - if (count($organizations) === 1 && $organizations[0]->isActive() === true) { - return $this->redirectToRoute('organization_show', ['id' => $organizations[0]->getId()]); - } - - } - // Map the entities for tabulator - $organizationsData = array_map(function ($org) { - return [ - 'id' => $org->getId(), - 'name' => $org->getName(), - 'email' => $org->getEmail(), - 'logoUrl' => $org->getLogoUrl() ? $org->getLogoUrl() : null, - 'active' => $org->isActive(), - 'showUrl' => $this->generateUrl('organization_show', ['id' => $org->getId()]), - ]; - }, $organizations); return $this->render('organization/index.html.twig', [ - 'organizationsData' => $organizationsData, + 'hasOrganizations' => $orgCount > 0 ]); } diff --git a/templates/organization/index.html.twig b/templates/organization/index.html.twig index 3e09ad9..19bf1fc 100644 --- a/templates/organization/index.html.twig +++ b/templates/organization/index.html.twig @@ -16,33 +16,24 @@ -
- {% if organizationsData|length == 0 %} - {% if is_granted('ROLE_SUPER_ADMIN') %} +
+ {% if is_granted('ROLE_SUPER_ADMIN') and not hasOrganizations %} -{# style présent juste pour créer de l'espace #}

Aucune organisation trouvée.

Créer une organisation
- {% else %} -
-

Aucune organisation trouvée. Merci de contacter votre administrateur

-
- {% endif %} - {% else %} -
- + data-organization-aws-value="{{ aws_url }}"> +
{% endif %}
-