<?php
namespace Bidcoz\Bundle\CoreBundle\Security\Authorization\Voter;
use Bidcoz\Bundle\CoreBundle\Entity\Contact\Contact;
use RS\DiExtraBundle\Annotation as DI;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* @DI\Service
* @DI\Tag("security.voter")
*/
class ContactVoter extends Voter
{
const EDIT_EMAIL = 'EDIT_EMAIL';
protected function supports($attribute, $subject)
{
return $subject instanceof Contact && self::EDIT_EMAIL === $attribute;
}
protected function voteOnAttribute($attribute, $contact, TokenInterface $token)
{
if (!$contact instanceof Contact) {
return false;
}
$user = $contact->getUser();
if (!$user->hasLoggedIn()) {
return true;
}
if ($user->hasRole('ROLE_SUPER_ADMIN')) {
return true;
}
return false;
}
}