Merge branch 'dev/organization/bugfix-1' into 'develop'

fix organization not loading

See merge request easy-solutions/apps/easyportal!21
This commit is contained in:
Charles-Edouard MARGUERITE 2026-02-02 08:23:55 +00:00
commit e7206d09e3
2 changed files with 16 additions and 6 deletions

View File

@ -42,7 +42,8 @@ export default class extends Controller {
ajaxResponse: (url, params, response) => response,
paginationDataSent: { page: "page", size: "size" },
paginationDataReceived: { last_page: "last_page" },
paginationDataReceived: { last_page: "last_page",
data: "data"},
filterMode: "remote",
ajaxURLGenerator: function(url, config, params) {

View File

@ -302,7 +302,7 @@ class OrganizationController extends AbstractController
// API endpoint to fetch organization data for Tabulator
#[Route(path: '/data/{id}', name: 'data', methods: ['GET'])]
public function data(Request $request): JsonResponse
public function data(Request $request, int $id): JsonResponse
{
$this->denyAccessUnlessGranted('ROLE_ADMIN');
@ -327,12 +327,21 @@ class OrganizationController extends AbstractController
if (!$this->isGranted('ROLE_SUPER_ADMIN')) {
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
$uo = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['users' => $actingUser]);
$allowedOrgIds = [];
foreach ($uo as $item) {
if ($this->userService->isAdminOfOrganization($item->getOrganization())) {
$qb->andWhere('o.id = :orgId')
->setParameter('orgId', $item->getOrganization()->getId());
$allowedOrgIds[] = $item->getOrganization()->getId();
}
}
// If user has no organizations, ensure query returns nothing (or handle typically)
if (empty($allowedOrgIds)) {
$qb->andWhere('1 = 0'); // Force empty result
} else {
$qb->andWhere('o.id IN (:orgIds)')
->setParameter('orgIds', $allowedOrgIds);
}
}