-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Conversation
@@ -55,6 +56,11 @@ private function getVariables(GuardEvent $event) | |||
{ | |||
$token = $this->tokenStorage->getToken(); | |||
|
|||
if ($token == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null === $token
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
Hello. @nicolas-grekas you can simply add the workflow label instead of pinging me ;) (Both are fine anyway) I'm 👎 with the current implementation. I understand your PR it's a convenient fallback but IMHO it will lead to many WTF for people that are not aware to see "feature"/fallaback. May be we can instead throw an exception if the token is null. WDYT? |
@lyrixx Hrmm, that makes sense. In my own implementation, I'm only writing expressions that check the subject. It would be nice if we could only throw an exception only if the expression required the user (like it used an is_granted check), but that would mean modifying the Expression language, right? |
It is possible but it will need more work (I mean much more CPU work). Not sure it worth it. |
How about something like this? |
it will lead to PHP warnings in the expression evaluation. |
Ok, gotcha. So I guess just something like this: |
Edit: oups, it's already a PR. :D sorry |
@@ -55,6 +56,10 @@ private function getVariables(GuardEvent $event) | |||
{ | |||
$token = $this->tokenStorage->getToken(); | |||
|
|||
if (null === $token) { | |||
throw new \Exception("No token is set"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use top level exceptions.
@@ -55,6 +55,10 @@ private function getVariables(GuardEvent $event) | |||
{ | |||
$token = $this->tokenStorage->getToken(); | |||
|
|||
if (null === $token) { | |||
throw new \Exception('No token is set'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why @stloyd's comment is lost ; but he was right.
You should use an exception that lives in the Workflow component. If the existing exception does not match
this case, you will have to create a new one.
public function testWithNoTokenStorage() | ||
{ | ||
$event = $this->createEvent(); | ||
$this->tokenStorage = null; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
@@ -55,6 +56,10 @@ private function getVariables(GuardEvent $event) | |||
{ | |||
$token = $this->tokenStorage->getToken(); | |||
|
|||
if (null === $token) { | |||
throw new InvalidTokenConfigurationException('No token is set'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could maybe be something like sprintf('There are no token available for the transition event %s', $eventName)
?
WDYT @lyrixx ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So:
throw new InvalidTokenConfigurationException(sprintf('There are no token available for the transition event %s', $event->getWorkflowName()));
Travis failure seems unrelated |
@@ -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())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[...] no tokens [...]
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
* @expectedException \Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException | ||
* @expectedExceptionMessage There are no token available for workflow unnamed | ||
*/ | ||
public function testWithNoTokenStorage() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!
👍 |
Thank you @GDIBass. |
…mmand (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
Added support for advancing a workflow from the command line when the transition has guards.