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

Conversation

GDIBass
Copy link
Contributor

@GDIBass GDIBass commented Aug 16, 2017

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.

@@ -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.

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Aug 17, 2017
@nicolas-grekas
Copy link
Member

ping @Nyholm @lyrixx

@lyrixx
Copy link
Member

lyrixx commented Aug 17, 2017

Hello.

@nicolas-grekas you can simply add the workflow label instead of pinging me ;) (Both are fine anyway)

@GDIBass:

I'm 👎 with the current implementation.
It's the developer responsibility to set the right token when using the security from the CLI.

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?

@GDIBass
Copy link
Contributor Author

GDIBass commented Aug 17, 2017

@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?

@lyrixx
Copy link
Member

lyrixx commented Aug 17, 2017

It is possible but it will need more work (I mean much more CPU work). Not sure it worth it.

@GDIBass
Copy link
Contributor Author

GDIBass commented Aug 17, 2017

How about something like this?

https://pastebin.com/34hgUi7j

@lyrixx
Copy link
Member

lyrixx commented Aug 17, 2017

it will lead to PHP warnings in the expression evaluation.

@GDIBass
Copy link
Contributor Author

GDIBass commented Aug 17, 2017

Ok, gotcha. So I guess just something like this:

https://pastebin.com/cc9iazXs

@lyrixx
Copy link
Member

lyrixx commented Aug 17, 2017

Do you want to create a pull request ?

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");
Copy link
Contributor

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');
Copy link
Member

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;
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

@@ -55,6 +56,10 @@ private function getVariables(GuardEvent $event)
{
$token = $this->tokenStorage->getToken();

if (null === $token) {
throw new InvalidTokenConfigurationException('No token is set');
Copy link
Contributor

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 ?

Copy link
Contributor Author

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()));

@Simperfit
Copy link
Contributor

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()));
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.

* @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!

@lyrixx
Copy link
Member

lyrixx commented Oct 5, 2017

👍

@fabpot
Copy link
Member

fabpot commented Oct 5, 2017

Thank you @GDIBass.

@fabpot fabpot merged commit 15fd863 into symfony:3.3 Oct 5, 2017
fabpot added a commit that referenced this pull request Oct 5, 2017
…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
@fabpot fabpot mentioned this pull request Oct 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants