8000 bug #23906 Added support for guards when advancing workflow from a co… · symfony/symfony@9568fae · GitHub
[go: up one dir, main page]

Skip to content

Commit 9568fae

Browse files
committed
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 ------- 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
2 parents 01644c5 + 15fd863 commit 9568fae

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/Symfony/Component/Workflow/EventListener/GuardListener.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
1717
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
1818
use Symfony\Component\Workflow\Event\GuardEvent;
19+
use Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException;
1920

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

59+
if (null === $token) {
60+
throw new InvalidTokenConfigurationException(sprintf('There are no tokens available for workflow %s.', $event->getWorkflowName()));
61+
}
62+
5863
if (null !== $this->roleHierarchy) {
5964
$roles = $this->roleHierarchy->getReachableRoles($token->getRoles());
6065
} else {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Workflow\Exception;
13+
14+
/**
15+
* Thrown by GuardListener when there is no token set, but guards are placed on a transition.
16+
*
17+
* @author Matt Johnson <matj1985@gmail.com>
18+
*/
19+
class InvalidTokenConfigurationException extends LogicException implements ExceptionInterface
20+
{
21+
}

src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ public function testWithSupportedEventAndAccept()
6969
$this->assertTrue($event->isBlocked());
7070
}
7171

72+
/**
73+
* @expectedException \Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException
74+
* @expectedExceptionMessage There are no tokens available for workflow unnamed.
75+
*/
76+
public function testWithNoTokensInTokenStorage()
77+
{
78+
$event = $this->createEvent();
79+
$this->tokenStorage->setToken(null);
80+
81+
$this->listener->onTransition($event, 'event_name_a');
82+
}
83+
7284
private function createEvent()
7385
{
7486
$subject = new \stdClass();

0 commit comments

Comments
 (0)
0