<?php
namespace App\Voters;
use App\Entity\Person\SuperClinicAdmin;
use App\Entity\Person\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
class SuperAdminVoter extends AppVoter
{
protected function supports($attribute, $subject)
{
return $subject instanceof SuperClinicAdmin && $attribute == self::EDIT;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
/** @var User $user */
$user = $token->getUser();
return $this->decisionManager->decide($token,
[User::ROLE_CONSENTZ_ADMIN]) || ($user instanceof SuperClinicAdmin && $user->getOrganisation() === $subject->getOrganisation());
}
}