fix organization not loading

This commit is contained in:
Charles 2026-02-02 09:10:30 +01:00
parent 281e58c4a7
commit 0a88ad0bde
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');
@ -324,15 +324,24 @@ class OrganizationController extends AbstractController
$qb->andWhere('o.email LIKE :email')
->setParameter('email', '%' . $filters['email'] . '%');
}
if(!$this->isGranted('ROLE_SUPER_ADMIN')) {
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());
if ($this->userService->isAdminOfOrganization($item->getOrganization())) {
$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);
}
}