Update role logic for action display

This commit is contained in:
Charles 2026-02-11 15:13:47 +01:00
parent 4fc059b2a5
commit d089815069
1 changed files with 13 additions and 9 deletions

View File

@ -5,6 +5,7 @@ namespace App\Controller;
use App\Entity\Actions;
use App\Entity\Organizations;
use App\Service\ActionService;
use App\Service\UserService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
@ -15,21 +16,24 @@ class ActionController extends AbstractController
{
public function __construct(
private EntityManagerInterface $entityManager,
private ActionService $actionService
private ActionService $actionService, private readonly UserService $userService
) {
}
#[Route('/organization/{id}/activities-ajax', name: 'app_organization_activities_ajax', methods: ['GET'])]
public function fetchActivitiesAjax(Organizations $organization): JsonResponse
{
$this->denyAccessUnlessGranted('ROLE_ADMIN');
$actions = $this->entityManager->getRepository(Actions::class)->findBy(
['Organization' => $organization],
['date' => 'DESC'],
10
);
$formattedActivities = $this->actionService->formatActivities($actions);
$this->denyAccessUnlessGranted('ROLE_USER');
if($this->userService->isAdminOfOrganization($organization)){
$actions = $this->entityManager->getRepository(Actions::class)->findBy(
['Organization' => $organization],
['date' => 'DESC'],
10
);
$formattedActivities = $this->actionService->formatActivities($actions);
return new JsonResponse($formattedActivities);
return new JsonResponse($formattedActivities);
}
return new JsonResponse(['error' => 'You are not authorized to access this page.'], 403);
}
}