Skip to content

Added support for guards when advancing workflow from a command #23906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 5, 2017
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
use Symfony\Component\Workflow\Event\GuardEvent;
use Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException;

/**
* @author Grégoire Pineau <lyrixx@lyrixx.info>
Expand Down Expand Up @@ -55,6 +56,10 @@ private function getVariables(GuardEvent $event)
{
$token = $this->tokenStorage->getToken();

if (null === $token) {
throw new InvalidTokenConfigurationException(sprintf('There are no tokens available for workflow %s.', $event->getWorkflowName()));
}

if (null !== $this->roleHierarchy) {
$roles = $this->roleHierarchy->getReachableRoles($token->getRoles());
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Workflow\Exception;

/**
* Thrown by GuardListener when there is no token set, but guards are placed on a transition.
*
* @author Matt Johnson <matj1985@gmail.com>
*/
class InvalidTokenConfigurationException extends LogicException implements ExceptionInterface
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ public function testWithSupportedEventAndAccept()
$this->assertTrue($event->isBlocked());
}

/**
* @expectedException \Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException
* @expectedExceptionMessage There are no tokens available for workflow unnamed.
*/
public function testWithNoTokensInTokenStorage()
{
$event = $this->createEvent();
$this->tokenStorage->setToken(null);

$this->listener->onTransition($event, 'event_name_a');
}

private function createEvent()
{
$subject = new \stdClass();
Expand Down