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
Next Next commit
Added support for guards when advancing workflow from a command
  • Loading branch information
GDIBass committed Aug 16, 2017
commit b044ffb4a23d109d62724e7c62855f4d03d72a32
Original file line number Diff line number Diff line change
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) {
$token = new AnonymousToken('secret','anon',[]);
$this->tokenStorage->setToken($token);
}

if (null !== $this->roleHierarchy) {
$roles = $this->roleHierarchy->getReachableRoles($token->getRoles());
} else {
Expand Down
Original file line number Diff line number Diff line change
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
0