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 adapters in guard handler #1455

Merged
merged 5 commits into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changelog

**Added**

- #1455 Added support for adapters in guard handler
- #1436 Setting in setup for auto-reception of samples upon creation
- #1433 Added Submitter column in Sample's analyses listing
- #1441 Added Auto ID Behavior for Dexterity Contents
Expand Down
9 changes: 9 additions & 0 deletions bika/lims/interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,3 +954,12 @@ class IInternalUse(Interface):
class IDetachedPartition(Interface):
"""Marker interface for samples that have been detached from its primary
"""


class IGuardAdapter(Interface):
"""Marker interface for guard adapters
"""

def guard(self, transition):
"""Return False if you want to block the transition
"""
10 changes: 9 additions & 1 deletion bika/lims/workflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from bika.lims import logger
from bika.lims.browser import ulocalized_time
from bika.lims.decorators import synchronized
from bika.lims.interfaces import IActionHandlerPool
from bika.lims.interfaces import IActionHandlerPool, IGuardAdapter
from bika.lims.interfaces import IJSONReadExtender
from bika.lims.jsonapi import get_include_fields
from bika.lims.utils import changeWorkflowState # noqa
Expand All @@ -37,6 +37,7 @@
from Products.Archetypes.config import UID_CATALOG
from Products.CMFCore.utils import getToolByName
from Products.CMFCore.WorkflowCore import WorkflowException
from zope.component import getAdapters
from zope.interface import implements
from ZPublisher.HTTPRequest import HTTPRequest

Expand Down Expand Up @@ -386,6 +387,13 @@ def guard_handler(instance, transition_id):
"""
if not instance:
return True

# If adapters are found, core's guard will only be evaluated if, and only
# if, ALL "pre-guards" return True
for name, ad in getAdapters((instance,), IGuardAdapter):
if ad.guard(transition_id) is False:
return False

clazz_name = instance.portal_type
# Inspect if bika.lims.workflow.<clazzname>.<guards> module exists
wf_module = _load_wf_module('{0}.guards'.format(clazz_name.lower()))
Expand Down