update access logic
This commit is contained in:
parent
a3f993b858
commit
cde6c529a9
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Roles;
|
||||||
use App\Entity\UsersOrganizations;
|
use App\Entity\UsersOrganizations;
|
||||||
use App\Service\OrganizationsService;
|
use App\Service\OrganizationsService;
|
||||||
use App\Service\UserOrganizationService;
|
use App\Service\UserOrganizationService;
|
||||||
|
|
@ -52,35 +53,29 @@ class OrganizationController extends AbstractController
|
||||||
#[Route(path: '/{id}', name: 'show', methods: ['GET'])]
|
#[Route(path: '/{id}', name: 'show', methods: ['GET'])]
|
||||||
public function show(int $id): Response
|
public function show(int $id): Response
|
||||||
{
|
{
|
||||||
if (!$this->isGranted('ROLE_ADMIN')) {
|
if ($this->isGranted('ROLE_ADMIN')) {
|
||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
return $this->redirectToRoute('app_login');
|
return $this->redirectToRoute('app_login');
|
||||||
}
|
}
|
||||||
$userIdentifier = $user->getUserIdentifier();
|
$roleAdmin = $this->entityManager->getRepository(Roles::class)->findOneBy(['name' => 'ADMIN']);
|
||||||
|
$uo = $this->entityManager->getRepository(UsersOrganizations::class)->findOneBy([
|
||||||
$organization = $this->entityManager->getRepository(UsersOrganizations::class)->findOneBy([
|
'users' => $user,
|
||||||
'userEmail' => $userIdentifier,
|
|
||||||
'organization' => $id,
|
'organization' => $id,
|
||||||
'roleName' => 'ADMIN'
|
'role' => $roleAdmin
|
||||||
]);
|
]);
|
||||||
|
if (!$uo) {
|
||||||
if (!$organization) {
|
|
||||||
throw $this->createNotFoundException(self::ACCESS_DENIED);
|
throw $this->createNotFoundException(self::ACCESS_DENIED);
|
||||||
}
|
}
|
||||||
}
|
//Don't care about the null pointer because if no UO found, it won't pass the previous check
|
||||||
$organization = $this->entityManager->getRepository(Organizations::class)->find($id);
|
$organization = $this->entityManager->getRepository(Organizations::class)->find($id);
|
||||||
if (!$organization) {
|
|
||||||
throw $this->createNotFoundException(self::NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
$newUsers = $this->entityManager->getRepository(UsersOrganizations::class)->getLastNewActiveUsersByOrganization($organization);
|
$newUsers = $this->entityManager->getRepository(UsersOrganizations::class)->getLastNewActiveUsersByOrganization($organization);
|
||||||
$adminUsers = $this->entityManager->getRepository(UsersOrganizations::class)->getAdminUsersByOrganization($organization);
|
$adminUsers = $this->entityManager->getRepository(UsersOrganizations::class)->getAdminUsersByOrganization($organization);
|
||||||
// reusing the method to avoid code duplication even though it returns an array of UsersOrganizations
|
// reusing the method to avoid code duplication even though it returns an array of UsersOrganizations
|
||||||
$org = $this->usersOrganizationService->findActiveUsersByOrganizations([$organization]);
|
$org = $this->usersOrganizationService->findActiveUsersByOrganizations([$organization]);
|
||||||
|
}else{
|
||||||
|
throw $this->createNotFoundException(self::ACCESS_DENIED);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->render('organization/show.html.twig', [
|
return $this->render('organization/show.html.twig', [
|
||||||
'organization' => $organization,
|
'organization' => $organization,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue