src/Voters/CompanySettingsVoter.php line 16
<?php/** @author Guerby Duval <info@tranzaksyon.com>* @link https://tranzaksyon.com* @copyright You are not allowed to remove this author "Guerby Duval <info@tranzaksyon.com>", the link "https://tranzaksyon.com" neither this copyright.*/namespace App\Voters;use App\Entity\User;use App\Enums\RolesEnum;use Symfony\Bundle\SecurityBundle\Security;use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;use Symfony\Component\Security\Core\Authorization\Voter\Voter;class CompanySettingsVoter extends Voter{const VIEW = 'View_settings';const EDIT = 'Edit_settings';const DELETE = 'Delete_settings';public function __construct(private Security $security){}protected function supports(string $attribute, mixed $subject): bool{if (in_array($attribute, [self::VIEW, self::EDIT, self::DELETE]) && $subject instanceof User) {return true;}return false;}/*** @param string $attribute* @param User $subject* @param TokenInterface $token* @return bool*/protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool{/** @var User $user */$user = $token->getUser();if ($this->security->isGranted('ROLE_SUPER_ADMIN')) {return true;}if ($this->security->isGranted('ROLE_COMPANY_ADMIN') || $this->security->isGranted('ROLE_ADMIN')) {if ($token->getUser()->getId() === $subject->getId()) {return true;}if ($token->getUser()?->getEmployee()?->getSriInfo() !== null && $token->getUser()?->getEmployee()?->getSriInfo()?->getId() === $subject->getSriInfo()?->getId()) {return true;}}// Si se yon partnerif ($this->security->isGranted(RolesEnum::partnerAdmin->value) && $user->getPartner()->getId() === $subject->getBelongToPartner()->getId()) {return true;}return false;}}