Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
bug #23906 Added support for guards when advancing workflow from a co…
…mmand (GDIBass)

This PR was merged into the 3.3 branch.

Discussion
----------

Added support for guards when advancing workflow from a command

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23904
| License       | MIT
| Doc PR        | symfony/symfony-docs

Added support for advancing a workflow from the command line when the transition has guards.

Commits
-------

15fd863 Updated Test name and exception name to be more accurate
fefc202 newline at end of file
8f2fa6b changed exception message
49839e3 Ahh, I see.  It actually wants a newline!
2c9d1e2 Removed newline
92308b4 Created new Exception to throw and modified tests.
2ebc71a Created new Exception to throw and modified tests
3a8b2ed Code standard fixes
22b44e2 Changed automatic token generation to throw an exception instead
8ab59cb Updated if statement
324c208 Code standards update
b044ffb Added support for guards when advancing workflow from a command
  • Loading branch information
fabpot committed Oct 5, 2017
2 parents 01644c5 + 15fd863 commit 9568fae
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
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
@@ -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
{
}
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

0 comments on commit 9568fae

Please sign in to comment.