rename voter helepers

This commit is contained in:
2021-09-17 10:08:33 +02:00
parent ebb2f5d243
commit cf40f38463
10 changed files with 54 additions and 65 deletions

View File

@@ -5,7 +5,7 @@ namespace Chill\MainBundle\Security\Authorization;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher;
class DefaultVoter implements VoterInterface
class DefaultVoterHelper implements VoterHelperInterface
{
protected AuthorizationHelper $authorizationHelper;
@@ -50,14 +50,7 @@ class DefaultVoter implements VoterInterface
}
if (NULL === $subject) {
if (NULL === $center = $this->centerResolverDispatcher
->resolveCenter($subject)) {
return false;
}
return $this->authorizationHelper->userCanReachCenter(
$token->getUser(),
$center
);
return 0 < count($this->authorizationHelper->getReachableCenters($token->getUser(), $attribute, null));
}
return $this->authorizationHelper->userHasAccess(

View File

@@ -4,7 +4,7 @@ namespace Chill\MainBundle\Security\Authorization;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher;
class DefaultVoterFactory implements VoterFactoryInterface
class DefaultVoterHelperFactory implements VoterHelperFactoryInterface
{
protected AuthorizationHelper $authorizationHelper;
protected CenterResolverDispatcher $centerResolverDispatcher;
@@ -19,7 +19,7 @@ class DefaultVoterFactory implements VoterFactoryInterface
public function generate($context): VoterGeneratorInterface
{
return new VoterGenerator(
return new DefaultVoterHelperGenerator(
$this->authorizationHelper,
$this->centerResolverDispatcher
);

View File

@@ -4,7 +4,7 @@ namespace Chill\MainBundle\Security\Authorization;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher;
final class VoterGenerator implements VoterGeneratorInterface
final class DefaultVoterHelperGenerator implements VoterGeneratorInterface
{
protected AuthorizationHelper $authorizationHelper;
protected CenterResolverDispatcher $centerResolverDispatcher;
@@ -25,9 +25,9 @@ final class VoterGenerator implements VoterGeneratorInterface
return $this;
}
public function build(): VoterInterface
public function build(): VoterHelperInterface
{
return new DefaultVoter(
return new DefaultVoterHelper(
$this->authorizationHelper,
$this->centerResolverDispatcher,
$this->configuration

View File

@@ -1,7 +0,0 @@
<?php
namespace Chill\MainBundle\Security\Authorization;
interface VoterFactoryInterface
{
}

View File

@@ -4,4 +4,12 @@ namespace Chill\MainBundle\Security\Authorization;
interface VoterGeneratorInterface
{
/**
* @param string $class The FQDN of a class
* @param array $attributes an array of attributes
* @return $this
*/
public function addCheckFor(string $class, array $attributes): self;
public function build(): VoterHelperInterface;
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Chill\MainBundle\Security\Authorization;
interface VoterHelperFactoryInterface
{
public function generate($context): VoterGeneratorInterface;
}

View File

@@ -0,0 +1,12 @@
<?php
namespace Chill\MainBundle\Security\Authorization;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
interface VoterHelperInterface
{
public function supports($attribute, $subject): bool;
public function voteOnAttribute($attribute, $subject, TokenInterface $token);
}

View File

@@ -1,7 +0,0 @@
<?php
namespace Chill\MainBundle\Security\Authorization;
interface VoterInterface
{
}