From eeff93c88a7af48f5b955c72a715946af0759fb1 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 5 Apr 2018 09:54:28 +0200 Subject: [PATCH] fix deprecations: implement abstract function for reportVoter --- Security/Authorization/ReportVoter.php | 44 +++++++++++++++----------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/Security/Authorization/ReportVoter.php b/Security/Authorization/ReportVoter.php index 6ffb9d153..5227cbc9c 100644 --- a/Security/Authorization/ReportVoter.php +++ b/Security/Authorization/ReportVoter.php @@ -19,12 +19,17 @@ namespace Chill\ReportBundle\Security\Authorization; +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; + use Chill\MainBundle\Security\Authorization\AbstractChillVoter; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Security\ProvideRoleHierarchyInterface; +use Chill\ReportBundle\Entity\Report; +use Chill\MainBundle\Entity\User; + /** - * + * * * @author Julien Fastré */ @@ -33,38 +38,41 @@ class ReportVoter extends AbstractChillVoter implements ProvideRoleHierarchyInte const CREATE = 'CHILL_REPORT_CREATE'; const SEE = 'CHILL_REPORT_SEE'; const UPDATE = 'CHILL_REPORT_UPDATE'; - + /** * * @var AuthorizationHelper */ protected $helper; - + + public function __construct(AuthorizationHelper $helper) { $this->helper = $helper; } - - protected function getSupportedAttributes() - { - return array(self::CREATE, self::SEE, self::UPDATE); - } - protected function getSupportedClasses() - { - return array('Chill\ReportBundle\Entity\Report'); - } - protected function isGranted($attribute, $report, $user = null) + protected function supports($attribute, $subject) { - if (! $user instanceof \Chill\MainBundle\Entity\User){ - + if ($subject instanceof Report) { + return \in_array($attribute, [ + self::CREATE, self::UPDATE, self::SEE + ]); + } else { 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() { return $this->getSupportedAttributes(); @@ -74,7 +82,7 @@ class ReportVoter extends AbstractChillVoter implements ProvideRoleHierarchyInte { return array(); } - + public function getRolesWithHierarchy() { return [ 'Report' => $this->getRoles() ];