<?php
namespace App\Voters;
use App\Entity\Organisation\Organisation;
use App\Entity\Person\SuperClinicAdmin;
use App\Entity\Person\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
class OrganisationVoter extends AppVoter
{
protected function supports($attribute, $subject)
{
return $attribute == self::VIEW && $subject instanceof Organisation;
}
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);
}
}