<?php//------------------------------------------------------------------------------// src/Security/IkeaKitchenPlannerVoter.php//------------------------------------------------------------------------------namespace App\Security;use Doctrine\Persistence\ManagerRegistry;use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;use Symfony\Component\Security\Core\Authorization\Voter\Voter;use App\Entity\Access;use App\Entity\APIRest\AccessAPI;use App\Entity\Config\Module;use App\Entity\HR\AccessFunction;use App\Entity\Ikea\KitchenPlannerProject;use App\Entity\Security\Acl;use App\Entity\Security\AclPermission;use App\Services\Config\ModuleTools;class IkeaKitchenPlannerVoter extends Voter{ const IS_ACTIVE = "ikea_kitchen_planner_is_active"; const IS_GRANTED_CONSTANTS = array( self::IS_ACTIVE, ); //-------------------------------------------------------------------------------- // acl constants (matrix_acl.yml lines 3354-3390) - Removed //-------------------------------------------------------------------------------- public function __construct(ManagerRegistry $doctrine, ModuleTools $moduleTools) { $this->em = $doctrine->getManager(); $this->moduleTools = $moduleTools; $this->aclRepository = $this->em->getRepository(Acl::class); $this->aclPermissionRepository = $this->em->getRepository(AclPermission::class); } public function supportsAttribute(string $attribute): bool { return in_array($attribute, self::IS_GRANTED_CONSTANTS, true); } protected function supports(string $attribute, $subject): bool { if (!in_array($attribute, self::IS_GRANTED_CONSTANTS)) { return false; } if ($subject !== null && !$subject instanceof KitchenPlannerProject) { return false; } return true; } protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool { $user = $token->getUser(); if ($user instanceof AccessAPI) { if ($user->getAccess() === null) { return false; } $user = $user->getAccess(); } if (!$user instanceof Access) { return false; } $function = $user->getFunction(); if ($function === null) { return false; } $currentGroup = $user->getSocietyGroup(); if ($currentGroup === null) { return false; } if ($this->moduleTools->isInactiveByCode($currentGroup, Module::MODULE_IKEA_KITCHEN_PLANNER)) { return false; } if ($subject !== null) { /** @var KitchenPlannerProject $project */ $project = $subject; $projectGroupId = $project->getSocietyGroupId(); if ($projectGroupId === null) { return false; } if ($currentGroup->getId() !== $projectGroupId) { return false; } } switch ($attribute) { case self::IS_ACTIVE: return true; } throw new \LogicException('This code should not be reached!'); }}