workflows: add support for per-workflow action availability check (#11230)

This commit is contained in:
Frédéric Péters 2016-06-06 19:17:27 +02:00
parent 81908abd75
commit 8f10a5c134
6 changed files with 30 additions and 9 deletions

View File

@ -27,7 +27,7 @@ from wcs.qommon.template import get_current_theme
from wcs.categories import Category
from wcs.data_sources import NamedDataSource
from wcs.roles import Role
from wcs.workflows import Workflow, DisplayMessageWorkflowStatusItem
from wcs.workflows import Workflow, DisplayMessageWorkflowStatusItem, WorkflowCriticalityLevel
from wcs.wf.wscall import WebserviceCallStatusItem
from wcs.formdef import FormDef
from wcs import fields
@ -1421,6 +1421,27 @@ def test_workflows_add_all_actions(pub):
resp = resp.follow() # redirect to items/
resp = resp.follow() # redirect to ./
def test_workflows_check_available_actions(pub):
create_superuser(pub)
Workflow.wipe()
workflow = Workflow(name='foo')
workflow.add_status(name='baz')
workflow.store()
app = login(get_app(pub))
resp = app.get('/backoffice/workflows/1/')
resp = resp.click('baz')
assert not 'Modify Criticality' in [x[0] for x in resp.forms[0]['type'].options]
workflow.criticality_levels = [WorkflowCriticalityLevel(name='green')]
workflow.store()
resp = app.get('/backoffice/workflows/1/')
resp = resp.click('baz')
assert 'Modify Criticality' in [x[0] for x in resp.forms[0]['type'].options]
def test_workflows_edit_dispatch_action(pub):
create_superuser(pub)
role = create_role()

View File

@ -500,7 +500,7 @@ class WorkflowStatusPage(Directory):
return r.getvalue()
def is_item_available(self, item):
return item.is_available()
return item.is_available(workflow=self.workflow)
def get_new_item_form(self):
form = Form(enctype='multipart/form-data', action = 'newitem')

View File

@ -34,10 +34,10 @@ class ModifyCriticalityWorkflowStatusItem(WorkflowStatusItem):
return ('mode', 'absolute_value')
@classmethod
def is_available(cls):
# TODO: if we had per-workflow availability we could show this action
# only on the workflow where criticality levels are set.
return get_publisher().has_site_option('workflow-criticality-levels')
def is_available(cls, workflow=None):
if not get_publisher().has_site_option('workflow-criticality-levels'):
return False
return workflow and workflow.criticality_levels
def add_parameters_widgets(self, form, parameters, prefix='', formdef=None):
if 'mode' in parameters:

View File

@ -34,7 +34,7 @@ class ResubmitWorkflowStatusItem(WorkflowStatusItem):
backoffice_info_text = None
@classmethod
def is_available(cls):
def is_available(cls, workflow=None):
return get_publisher().has_site_option('workflow-resubmit-action')
def render_as_line(self):

View File

@ -31,7 +31,7 @@ class TimeoutWorkflowStatusItem(WorkflowStatusJumpItem):
_granularity = 20 * 60 # default: 20 minutes, see bottom of file
@classmethod
def is_available(cls):
def is_available(cls, workflow=None):
return False
def render_as_line(self):

View File

@ -1416,7 +1416,7 @@ class WorkflowStatusItem(XmlSerialisable):
pass
@classmethod
def is_available(cls):
def is_available(cls, workflow=None):
return True
def migrate(self):