Update role logic for action display
This commit is contained in:
parent
4fc059b2a5
commit
d089815069
|
|
@ -5,6 +5,7 @@ namespace App\Controller;
|
||||||
use App\Entity\Actions;
|
use App\Entity\Actions;
|
||||||
use App\Entity\Organizations;
|
use App\Entity\Organizations;
|
||||||
use App\Service\ActionService;
|
use App\Service\ActionService;
|
||||||
|
use App\Service\UserService;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
|
@ -15,21 +16,24 @@ class ActionController extends AbstractController
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private EntityManagerInterface $entityManager,
|
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'])]
|
#[Route('/organization/{id}/activities-ajax', name: 'app_organization_activities_ajax', methods: ['GET'])]
|
||||||
public function fetchActivitiesAjax(Organizations $organization): JsonResponse
|
public function fetchActivitiesAjax(Organizations $organization): JsonResponse
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('ROLE_ADMIN');
|
$this->denyAccessUnlessGranted('ROLE_USER');
|
||||||
$actions = $this->entityManager->getRepository(Actions::class)->findBy(
|
if($this->userService->isAdminOfOrganization($organization)){
|
||||||
['Organization' => $organization],
|
$actions = $this->entityManager->getRepository(Actions::class)->findBy(
|
||||||
['date' => 'DESC'],
|
['Organization' => $organization],
|
||||||
10
|
['date' => 'DESC'],
|
||||||
);
|
10
|
||||||
$formattedActivities = $this->actionService->formatActivities($actions);
|
);
|
||||||
|
$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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue