diff --git a/src/Resources/config/publish-workflow.xml b/src/Resources/config/publish-workflow.xml index 4ed57cf..bd947ba 100644 --- a/src/Resources/config/publish-workflow.xml +++ b/src/Resources/config/publish-workflow.xml @@ -35,7 +35,8 @@ - + + diff --git a/src/Security/Authorization/Voter/PublishedVoter.php b/src/Security/Authorization/Voter/PublishedVoter.php index ad9be41..8140ecb 100644 --- a/src/Security/Authorization/Voter/PublishedVoter.php +++ b/src/Security/Authorization/Voter/PublishedVoter.php @@ -11,9 +11,12 @@ namespace Symfony\Cmf\Bundle\CoreBundle\Security\Authorization\Voter; +use function is_subclass_of; +use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishableReadInterface; +use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishTimePeriodReadInterface; use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowChecker; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; -use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; +use Symfony\Component\Security\Core\Authorization\Voter\Voter; /** * This is a security voter registered with the Symfony security system that @@ -21,7 +24,7 @@ * * @author David Buchmann */ -class PublishedVoter implements VoterInterface +class PublishedVoter extends Voter { /** * @var PublishWorkflowChecker @@ -36,41 +39,27 @@ public function __construct(PublishWorkflowChecker $publishWorkflowChecker) /** * {@inheritdoc} */ - public function supportsAttribute($attribute) + public function supportsAttribute($attribute): bool { return PublishWorkflowChecker::VIEW_ATTRIBUTE === $attribute || PublishWorkflowChecker::VIEW_ANONYMOUS_ATTRIBUTE === $attribute ; } - /** - * {@inheritdoc} - */ - public function supportsClass($class) + public function supportsType(string $subjectType): bool { - return $this->publishWorkflowChecker->supportsClass($class); + return is_subclass_of($subjectType, PublishableReadInterface::class) + || is_subclass_of($subjectType, PublishTimePeriodReadInterface::class); } - /** - * {@inheritdoc} - * - * @param object $subject - */ - public function vote(TokenInterface $token, $subject, array $attributes) + protected function supports($attribute, $subject) { - if (!\is_object($subject) || !$this->supportsClass(\get_class($subject))) { - return self::ACCESS_ABSTAIN; - } - foreach ($attributes as $attribute) { - if (!$this->supportsAttribute($attribute)) { - return self::ACCESS_ABSTAIN; - } - } - - if ($this->publishWorkflowChecker->isGranted($attributes, $subject)) { - return self::ACCESS_GRANTED; - } + return \is_object($subject) && $this->supportsType(\get_class($subject)) + && $this->supportsAttribute($attribute); + } - return self::ACCESS_DENIED; + protected function voteOnAttribute($attribute, $subject, TokenInterface $token) + { + return $this->publishWorkflowChecker->isGranted($attribute, $subject); } }