Commit 2a1e09ff authored by Jérome Perrin's avatar Jérome Perrin

Interaction Workflow: allow configuring filters on a portal type group

parent 4aa03b09
......@@ -57,6 +57,7 @@ class InteractionDefinition (SimpleItem):
activate_script_name = () # Executed as activity
method_id = ()
portal_type_filter = None
portal_type_group_filter = None
once_per_transaction = False
temporary_document_disallowed = False
......@@ -117,6 +118,7 @@ class InteractionDefinition (SimpleItem):
def setProperties(self, title,
portal_type_filter=None,
portal_type_group_filter=None,
trigger_type=TRIGGER_WORKFLOW_METHOD,
once_per_transaction=False,
temporary_document_disallowed=False,
......@@ -139,6 +141,8 @@ class InteractionDefinition (SimpleItem):
self.method_id = method_id
if portal_type_filter is not None and 'None' in portal_type_filter:
portal_type_filter = None
if portal_type_group_filter is not None and 'None' in portal_type_group_filter:
portal_type_group_filter = None
if 'None' in after_script_name:
after_script_name = ()
if 'None' in activate_script_name:
......@@ -146,6 +150,7 @@ class InteractionDefinition (SimpleItem):
if 'None' in script_name:
script_name = ()
self.portal_type_filter = portal_type_filter
self.portal_type_group_filter = portal_type_group_filter
self.title = str(title)
self.description = str(description)
self.trigger_type = int(trigger_type)
......
......@@ -20,7 +20,7 @@
</tr>
<tr>
<th align="left">Filter</th>
<th align="left">Portal Type Filter</th>
<td>
<select name="portal_type_filter:list" multiple size="5">
<option value="None">(None)</option>
......@@ -43,6 +43,20 @@
</td>
</tr>
<tr>
<th align="left">Portal Type Group Filter</th>
<td>
<select name="portal_type_group_filter:list" multiple size="5">
<option value="None">(None)</option>
<dtml-in "portal_types['Base Type'].getAvailableGroupList()" sort>
<dtml-let selected="_['sequence-item'] in (portal_type_group_filter or []) and 'selected' or ' '">
<option value="&dtml-sequence-item;" &dtml-selected;>&dtml-sequence-item;</option>
</dtml-let>
</dtml-in>
</select>
</td>
</tr>
<tr>
<th align="left">Trigger Method Id(s)</th>
<td><input type="text" name="method_id" value="<dtml-var "' '.join(method_id)">" size="50" /></td>
......
......@@ -36,7 +36,11 @@
<br />
</dtml-if>
<dtml-if portal_type_filter>
Filter: &dtml-portal_type_filter;
Portal Type Filter: &dtml-portal_type_filter;
<br />
</dtml-if>
<dtml-if portal_type_group_filter>
Portal Type Group Filter: &dtml-portal_type_group_filter;
<br />
</dtml-if>
<dtml-if method_id>
......
......@@ -678,6 +678,56 @@ context.setTitle('Bar')
self.assertEqual('validated', self.organisation.getValidationState())
self.assertEqual('titi', self.organisation.getDescription())
def test_portal_type_filter(self):
self.createInteractionWorkflow()
self.getWorkflowTool().setChainForPortalTypes(
['Bank Account'],'test_workflow, validation_workflow')
self.interaction.setProperties(
'default',
# only for bank accounts
portal_type_filter=['Bank Account'],
method_id='getReference',
after_script_name=('afterEdit',))
params = 'sci, **kw'
body = "context = sci[\'object\']\n" +\
"context.setDescription('modified')"
self.script.ZPythonScript_edit(params, body)
bank_account = self.organisation.newContent(
portal_type='Bank Account')
self.assertEqual('', bank_account.getDescription())
self.organisation.getReference()
self.assertEqual('', self.organisation.getDescription())
bank_account.getReference()
self.assertEqual('modified', bank_account.getDescription())
def test_portal_type_group_filter(self):
self.createInteractionWorkflow()
self.getWorkflowTool().setChainForPortalTypes(
['Bank Account'],'test_workflow, validation_workflow')
self.interaction.setProperties(
'default',
# only for payment nodes portal type group (ie. bank account)
portal_type_group_filter=['payment_node'],
method_id='getReference',
after_script_name=('afterEdit',))
params = 'sci, **kw'
body = "context = sci[\'object\']\n" +\
"context.setDescription('modified')"
self.script.ZPythonScript_edit(params, body)
bank_account = self.organisation.newContent(
portal_type='Bank Account')
self.assertEqual('', bank_account.getDescription())
self.organisation.getReference()
self.assertEqual('', self.organisation.getDescription())
bank_account.getReference()
self.assertEqual('modified', bank_account.getDescription())
def test_suite():
......
......@@ -588,9 +588,18 @@ def initializePortalTypeDynamicWorkflowMethods(ptype_klass, portal_workflow):
for wf_id, v in interaction_workflow_dict.iteritems():
transition_id_set, trigger_dict = v
for tr_id, tdef in trigger_dict.iteritems():
# Check portal type filter
if (tdef.portal_type_filter is not None and \
portal_type not in tdef.portal_type_filter):
continue
# Check portal type group filter
if tdef.portal_type_group_filter is not None:
getPortalGroupedTypeSet = portal_workflow.getPortalObject()._getPortalGroupedTypeSet
if not any(portal_type in getPortalGroupedTypeSet(portal_type_group) for
portal_type_group in tdef.portal_type_group_filter):
continue
for imethod_id in tdef.method_id:
if wildcard_interaction_method_id_match(imethod_id):
# Interactions workflows can use regexp based wildcard methods
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment