8000 Added support for guards when advancing workflow from a command by GDIBass · Pull Request #23906 · symfony/symfony · GitHub
[go: up one dir, main page]

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 token available for workflow %s', $event->getWorkflowName()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] no tokens [...]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and the exception message should end with a dot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

}

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 token available for workflow unnamed
*/
public function testWithNoTokenStorage()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, there is a token storage but no token

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

{
$event = $this->createEvent();
$this->tokenStorage->setToken(null);

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

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