Beispiel #1
0
 public function vote(TokenInterface $token, $object, array $attributes)
 {
     $check = parent::vote($token, $object, $attributes);
     if ($check) {
         return $check;
     }
     // get current logged in user
     $user = $token->getUser();
     // set the attribute to check against
     $attribute = $attributes[0];
     if ($object instanceof Post) {
         $forum = $object->getTopic()->getForum();
         $this->accessManager->addVoterAccessCheck($attribute, $forum);
         if ($this->accessManager->hasVoterAccess()) {
             return VoterInterface::ACCESS_GRANTED;
         }
     } else {
         if ($object instanceof Topic) {
             $forum = $object->getForum();
             $this->accessManager->addVoterAccessCheck($attribute, $forum);
             if ($this->accessManager->hasVoterAccess()) {
                 return VoterInterface::ACCESS_GRANTED;
             }
         }
     }
 }
Beispiel #2
0
 /**
  * @param TokenInterface $token
  * @param object $object
  * @param array $attributes
  * @return int
  */
 public function vote(TokenInterface $token, $object, array $attributes)
 {
     $check = parent::vote($token, $object, $attributes);
     if ($check !== null) {
         return $check;
     }
     // get current logged in user
     $user = $token->getUser();
     // set the attribute to check against
     $attribute = strtolower($attributes[0]);
     switch ($attribute) {
         case self::VIEW:
             $forum = $object->getTopic()->getForum();
             $this->accessManager->addVoterAccessCheck(ForumVoter::VIEW, $forum);
             if ($this->accessManager->hasVoterAccess()) {
                 return VoterInterface::ACCESS_GRANTED;
             }
             break;
         case self::EDIT:
             if ($user->getId() === $object->getAuthor()->getId()) {
                 return VoterInterface::ACCESS_GRANTED;
             }
             $forum = $object->getTopic()->getForum();
             $this->accessManager->addVoterAccessCheck(ForumVoter::EDIT_POST, $forum);
             if ($this->accessManager->hasVoterAccess()) {
                 return VoterInterface::ACCESS_GRANTED;
             }
             break;
         case self::DELETE:
             if ($user->getId() === $object->getAuthor()->getId()) {
                 return VoterInterface::ACCESS_GRANTED;
             }
             $forum = $object->getTopic()->getForum();
             $this->accessManager->addVoterAccessCheck(ForumVoter::DELETE_POST, $forum);
             if ($this->accessManager->hasVoterAccess()) {
                 return VoterInterface::ACCESS_GRANTED;
             }
             break;
         case self::MOVE:
             $forum = $object->getTopic()->getForum();
             $this->accessManager->addVoterAccessCheck(ForumVoter::MOVE_POST, $forum);
             if ($this->accessManager->hasVoterAccess()) {
                 return VoterInterface::ACCESS_GRANTED;
             }
             break;
     }
     return VoterInterface::ACCESS_ABSTAIN;
 }
Beispiel #3
0
 /**
  * @param TokenInterface $token
  * @param object $object
  * @param array $attributes
  * @return int
  */
 public function vote(TokenInterface $token, $object, array $attributes)
 {
     $check = parent::vote($token, $object, $attributes);
     if ($check !== null) {
         return $check;
     }
     // get current logged in user
     $user = $token->getUser();
     // set the attribute to check against
     $attribute = strtolower($attributes[0]);
     switch ($attribute) {
         case self::VIEW:
             $forum = $object->getForum();
             $this->accessManager->addVoterAccessCheck(ForumVoter::VIEW, $forum);
             // the data object could have for example a method isPrivate()
             // which checks the Boolean attribute $private
             if ($this->accessManager->hasVoterAccess()) {
                 return VoterInterface::ACCESS_GRANTED;
             }
             break;
         case self::EDIT:
             if ($user->getId() === $object->getAuthor()->getId()) {
                 return VoterInterface::ACCESS_GRANTED;
             }
             $forum = $object->getForum();
             $this->accessManager->addVoterAccessCheck(ForumVoter::EDIT_TOPIC, $forum);
             if ($this->accessManager->hasVoterAccess()) {
                 return VoterInterface::ACCESS_GRANTED;
             }
             break;
         case self::DELETE:
             if ($user->getId() === $object->getAuthor()->getId()) {
                 return VoterInterface::ACCESS_GRANTED;
             }
             $forum = $object->getForum();
             $this->accessManager->addVoterAccessCheck(ForumVoter::DELETE_TOPIC, $forum);
             if ($this->accessManager->hasVoterAccess()) {
                 return VoterInterface::ACCESS_GRANTED;
             }
             break;
         case self::MOVE:
             $forum = $object->getForum();
             $this->accessManager->addVoterAccessCheck(ForumVoter::MOVE_TOPIC, $forum);
             if ($this->accessManager->hasVoterAccess()) {
                 return VoterInterface::ACCESS_GRANTED;
             }
             break;
         case self::SPLIT:
             $forum = $object->getForum();
             $this->accessManager->addVoterAccessCheck(ForumVoter::SPLIT_TOPIC, $forum);
             if ($this->accessManager->hasVoterAccess()) {
                 return VoterInterface::ACCESS_GRANTED;
             }
             break;
         case self::REPLY:
             $forum = $object->getForum();
             $this->accessManager->addVoterAccessCheck(ForumVoter::CREATE_POST, $forum);
             if ($this->accessManager->hasVoterAccess() && !$object->isLocked()) {
                 return VoterInterface::ACCESS_GRANTED;
             }
             break;
     }
     return VoterInterface::ACCESS_ABSTAIN;
 }