<?php
namespace App\Voters;
use App\Entity\Media\Media;
use App\Entity\Person\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;
class MediaVoter extends AppVoter
{
protected function supports($attribute, $subject = null)
{
if (!in_array($attribute, [self::CREATE, self::EDIT])) {
return false;
}
if (!$subject instanceof Media && $subject != null) {
return false;
}
return true;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
$user = $token->getUser();
if (!$user instanceof UserInterface) {
return false;
}
switch ($attribute) {
case self::CREATE:
if ($this->decisionManager->decide($token, [
User::ROLE_CONSENTZ_ADMIN,
User::ROLE_SUPER_CLINIC_ADMIN,
User::ROLE_CLINIC_ADMIN
])
) {
return true;
}
break;
case self::EDIT:
if ($this->decisionManager->decide($token, [
User::ROLE_CONSENTZ_ADMIN,
User::ROLE_SUPER_CLINIC_ADMIN,
User::ROLE_CLINIC_ADMIN
])
) {
return true;
}
break;
}
return false;
}
}