bug #23906 Added support for guards when advancing workflow from a command (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 -------15fd863112
Updated Test name and exception name to be more accuratefefc20233b
newline at end of file8f2fa6b047
changed exception message49839e3c28
Ahh, I see. It actually wants a newline!2c9d1e2d42
Removed newline92308b4815
Created new Exception to throw and modified tests.2ebc71a616
Created new Exception to throw and modified tests3a8b2eded1
Code standard fixes22b44e251f
Changed automatic token generation to throw an exception instead8ab59cb1c2
Updated if statement324c208e12
Code standards updateb044ffb4a2
Added support for guards when advancing workflow from a command
This commit is contained in:
commit
9568fae01f
@ -16,6 +16,7 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInt
|
||||
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>
|
||||
@ -55,6 +56,10 @@ class GuardListener
|
||||
{
|
||||
$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 {
|
||||
|
@ -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
|
||||
{
|
||||
}
|
@ -69,6 +69,18 @@ class GuardListenerTest extends TestCase
|
||||
$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();
|
||||
|
Reference in New Issue
Block a user