Correct organization display logic

This commit is contained in:
Charles 2025-12-22 10:04:11 +01:00
parent 08ed90a7dc
commit 68864b3997
3 changed files with 9 additions and 47 deletions

View File

@ -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",

View File

@ -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
]);
}

View File

@ -17,32 +17,23 @@
<div class="card-body">
{% 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 #}
<div class="div text-center my-5 py-5">
<h1 class="my-5 ty-5"> Aucune organisation trouvée. </h1>
<a href="{{ path('organization_new') }}" class="btn btn-primary">Créer une organisation</a>
</div>
{% else %}
<div class="div text-center my-5 py-5">
<h1 class="my-5 ty-5"> Aucune organisation trouvée. Merci de contacter votre administrateur </h1>
</div>
{% endif %}
{% else %}
<div id="tabulator-org" data-controller="organization"
<div id="tabulator-org"
data-controller="organization"
data-organization-table-value="true"
data-organization-data-value="{{ organizationsData|json_encode(constant("JSON_UNESCAPED_UNICODE"))|e("html_attr") }}"
data-organization-aws-value="{{ aws_url }}"></div>
data-organization-aws-value="{{ aws_url }}">
</div>
{% endif %}
</div>
</div>
</div>