Skip to content
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

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

Merged
merged 12 commits into from Oct 5, 2017
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Workflow\EventListener;

use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
Expand Down Expand Up @@ -55,6 +56,11 @@ private function getVariables(GuardEvent $event)
{
$token = $this->tokenStorage->getToken();

if ($token == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

null === $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.

$token = new AnonymousToken('secret', 'anon', array());
$this->tokenStorage->setToken($token);
}

if (null !== $this->roleHierarchy) {
$roles = $this->roleHierarchy->getReachableRoles($token->getRoles());
} else {
Expand Down
Expand Up @@ -69,6 +69,20 @@ public function testWithSupportedEventAndAccept()
$this->assertTrue($event->isBlocked());
}

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 = null;
Copy link
Member

Choose a reason for hiding this comment

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

this does not work.
You should configure the token storage to return null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, thanks for your patience here. First time contributing!

I'll get this done right away


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

$this->assertFalse($event->isBlocked());

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

$this->assertTrue($event->isBlocked());
}

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