diff --git a/src/Bundle/ChillMainBundle/Security/Authorization/ChillExportVoter.php b/src/Bundle/ChillMainBundle/Security/Authorization/ChillExportVoter.php
index 39af35706..f4dd9ba7c 100644
--- a/src/Bundle/ChillMainBundle/Security/Authorization/ChillExportVoter.php
+++ b/src/Bundle/ChillMainBundle/Security/Authorization/ChillExportVoter.php
@@ -1,48 +1,24 @@
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
+
+declare(strict_types=1);
+
namespace Chill\MainBundle\Security\Authorization;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
-use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Entity\User;
-use Symfony\Component\Security\Core\Role\Role;
-/**
- *
- *
- * @author Julien Fastré
- */
class ChillExportVoter extends Voter
{
- const EXPORT = 'chill_export';
-
- /**
- *
- * @var AuthorizationHelper
- */
- protected $authorizationHelper;
-
- public function __construct(AuthorizationHelper $authorizationHelper)
+ public const EXPORT = 'chill_export';
+
+ protected AuthorizationHelperInterface $authorizationHelper;
+
+ public function __construct(AuthorizationHelperInterface $authorizationHelper)
{
$this->authorizationHelper = $authorizationHelper;
}
-
+
protected function supports($attribute, $subject): bool
{
return $attribute === self::EXPORT;
@@ -53,10 +29,7 @@ class ChillExportVoter extends Voter
if (!$token->getUser() instanceof User) {
return false;
}
-
- $centers = $this->authorizationHelper
- ->getReachableCenters($token->getUser(), new Role($attribute));
-
- return count($centers) > 0;
+
+ return [] !== $this->authorizationHelper->getReachableCenters($token->getUser(), $attribute);
}
}
diff --git a/src/Bundle/ChillMainBundle/config/services/security.yaml b/src/Bundle/ChillMainBundle/config/services/security.yaml
index 8dcd15f5d..163b86d8e 100644
--- a/src/Bundle/ChillMainBundle/config/services/security.yaml
+++ b/src/Bundle/ChillMainBundle/config/services/security.yaml
@@ -3,11 +3,15 @@ services:
autowire: true
autoconfigure: true
- # do not autowire the directory Security/Resolver
Chill\MainBundle\Security\Resolver\CenterResolverDispatcher:
arguments:
- !tagged_iterator chill_main.center_resolver
+ Chill\MainBundle\Security\Resolver\CenterResolverManager:
+ arguments:
+ - !tagged_iterator chill_main.center_resolver
+ Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface: '@Chill\MainBundle\Security\Resolver\CenterResolverManager'
+
Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher:
arguments:
- !tagged_iterator chill_main.scope_resolver
@@ -20,7 +24,6 @@ services:
Chill\MainBundle\Security\Authorization\DefaultVoterHelperFactory: ~
- # do not autowire the directory Security/Resolver
Chill\MainBundle\Security\Authorization\VoterHelperFactoryInterface: '@Chill\MainBundle\Security\Authorization\DefaultVoterHelperFactory'
chill.main.security.authorization.helper:
@@ -40,8 +43,6 @@ services:
Symfony\Component\Security\Core\User\UserProviderInterface: "@chill.main.user_provider"
Chill\MainBundle\Security\Authorization\ChillExportVoter:
- arguments:
- $authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
tags:
- { name: security.voter }