src/Bidcoz/Bundle/CoreBundle/Security/Authorization/Voter/ContactVoter.php line 14

Open in your IDE?
  1. <?php
  2. namespace Bidcoz\Bundle\CoreBundle\Security\Authorization\Voter;
  3. use Bidcoz\Bundle\CoreBundle\Entity\Contact\Contact;
  4. use RS\DiExtraBundle\Annotation as DI;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  7. /**
  8.  * @DI\Service
  9.  * @DI\Tag("security.voter")
  10.  */
  11. class ContactVoter extends Voter
  12. {
  13.     const EDIT_EMAIL 'EDIT_EMAIL';
  14.     protected function supports($attribute$subject)
  15.     {
  16.         return $subject instanceof Contact && self::EDIT_EMAIL === $attribute;
  17.     }
  18.     protected function voteOnAttribute($attribute$contactTokenInterface $token)
  19.     {
  20.         if (!$contact instanceof Contact) {
  21.             return false;
  22.         }
  23.         $user $contact->getUser();
  24.         if (!$user->hasLoggedIn()) {
  25.             return true;
  26.         }
  27.         if ($user->hasRole('ROLE_SUPER_ADMIN')) {
  28.             return true;
  29.         }
  30.         return false;
  31.     }
  32. }