-
-
Notifications
You must be signed in to change notification settings - Fork 152
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 adapters in guard handler #1455
Conversation
This commit allows to adapt the behavior of core's guard handler. Adapters that implement IGuardAdapter have at least one of the two functions below: pre_guard(action) This function is executed first and the core's guard will only be evaluated if the return of pre_guard is True. post_guard(action) This function is only executed when the core's guard returns True. Therefore, the outcome of guard_handler will depend on the following order: pre_guard > core's guard > post_guard
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.
From an architectural point of view, I would rather query all named adapters, where the name is the transition.
If such an adapter is found, I would let handle this adapter the guarding solely.
It would leave then the whole logic to the adapter without bailing out conditionally in the pre_guard
or after_guard
(which I think should be triggered events instead adapter calls).
I think that it would be much more explicit then and also more performant, as only one adapter lookup would be involved instead of always two.
However, regarding the events, I would welcome such before/after events to eventually purge a cache or something like this...
What do you think?
Maybe it get clearer when we think about the purpose of the |
Ouch!... You are totally right. |
If we want to support multiple guard adapters (because different add-ons might have their own), then I cannot use a named adapter, because only the first adapter with that name will be returned by zope. If in turn, we do not want to explicitily pass the action to the adapter's If we use subscriber adapters, the snippet to registry them in zcml would be more confusing because the second parameter will always be Therefore, I thought was better to just pass the action to the |
Ok, the usage in multiple Add-ons is indeed something I did not consider, so somehow all Adapters need to be considered. So it is ok to make the logic |
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.
Thanks! 👍
Description of the issue/feature this PR addresses
This Pull Request allows to adapt the behavior of core's guard handler.
Use case
Imagine you want to be more restrictive regarding the verification of results in such a way that you only want the transition
verify
to be available if the submitted result is in-range. For this to work, you'd need to change the guard expresion from the workflow definition in your add-on, reimport workflows.xml, and update role mappings for pre-existing objects. This improvement makes the task far easier:Current behavior before PR
No support for adapters in guard handler
Desired behavior after PR is merged
Support for adapters in guard_handler
--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.