fix deprecations: implement abstract method supports and voteOnAttribute for ActivityVoter

This commit is contained in:
nobohan 2018-04-05 10:43:01 +02:00
parent 6327d25783
commit ed00833eb8

View File

@ -19,9 +19,13 @@
namespace Chill\ActivityBundle\Security\Authorization; namespace Chill\ActivityBundle\Security\Authorization;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Chill\MainBundle\Security\Authorization\AbstractChillVoter; use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface; use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
use Chill\MainBundle\Entity\User;
use Chill\ActivityBundle\Entity\Activity;
/** /**
* *
@ -47,27 +51,28 @@ class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
$this->helper = $helper; $this->helper = $helper;
} }
protected function getSupportedAttributes()
{
return array(self::CREATE, self::SEE, self::UPDATE, self::DELETE,
self::SEE_DETAILS);
}
protected function getSupportedClasses() protected function supports($attribute, $subject)
{ {
return array('Chill\ActivityBundle\Entity\Activity'); if ($subject instanceof Activity) {
} return \in_array($attribute, [
self::CREATE, self::SEE, self::UPDATE, self::DELETE,
protected function isGranted($attribute, $report, $user = null) self::SEE_DETAILS
{ ]);
if (! $user instanceof \Chill\MainBundle\Entity\User){ } else {
return false; return false;
} }
return $this->helper->userHasAccess($user, $report, $attribute);
} }
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
if (!$token->getUser() instanceof User) {
return false;
}
return $this->helper->userHasAccess($token->getUser(), $subject, $attribute);
}
public function getRoles() public function getRoles()
{ {
return $this->getSupportedAttributes(); return $this->getSupportedAttributes();