[Erp5-report] r13171 - in /erp5/trunk/products/ERP5Type/patches: DCWorkflow.py WorkflowTool.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Mar 1 23:45:55 CET 2007
Author: jp
Date: Thu Mar 1 23:45:53 2007
New Revision: 13171
URL: http://svn.erp5.org?rev=13171&view=rev
Log:
Pass method variables to workflow history. This change may be good or not. I do not know yet. Reviewing this code and patches is required.
Modified:
erp5/trunk/products/ERP5Type/patches/DCWorkflow.py
erp5/trunk/products/ERP5Type/patches/WorkflowTool.py
Modified: erp5/trunk/products/ERP5Type/patches/DCWorkflow.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/patches/DCWorkflow.py?rev=13171&r1=13170&r2=13171&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/patches/DCWorkflow.py (original)
+++ erp5/trunk/products/ERP5Type/patches/DCWorkflow.py Thu Mar 1 23:45:53 2007
@@ -16,7 +16,8 @@
from Globals import DTMLFile
from Products.ERP5Type import _dtmldir
-from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition, StateChangeInfo, ObjectMoved, createExprContext, aq_parent, aq_inner
+from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition, StateChangeInfo, createExprContext
+from Products.DCWorkflow.DCWorkflow import ObjectDeleted, ObjectMoved, aq_parent, aq_inner
from Products.DCWorkflow import DCWorkflow
from Products.DCWorkflow.Transitions import TRIGGER_WORKFLOW_METHOD, TransitionDefinition
from AccessControl import getSecurityManager, ClassSecurityInfo, ModuleSecurityInfo
@@ -30,8 +31,6 @@
from string import join
from zLOG import LOG
-
-
# Patch WorkflowUIMixin to add description on workflows
from Products.DCWorkflow.WorkflowUIMixin import WorkflowUIMixin as WorkflowUIMixin_class
from Products.DCWorkflow.Guard import Guard
@@ -55,7 +54,6 @@
WorkflowUIMixin_class.setProperties = WorkflowUIMixin_setProperties
WorkflowUIMixin_class.manage_properties = DTMLFile('workflow_properties', _dtmldir)
-
def DCWorkflowDefinition_listGlobalActions(self, info):
@@ -144,7 +142,6 @@
ModuleSecurityInfo('Products.DCWorkflow.DCWorkflow').declarePublic('ValidationFailed')
-
# Patch excecuteTransition from DCWorkflowDefinition, to put ValidationFailed
# error messages in workflow history.
def DCWorkflowDefinition_executeTransition(self, ob, tdef=None, kwargs=None):
@@ -271,9 +268,40 @@
else:
return new_sdef
-
DCWorkflowDefinition._executeTransition = DCWorkflowDefinition_executeTransition
from Products.DCWorkflow.utils import modifyRolesForPermission
+
+
+def DCWorkflowDefinition_wrapWorkflowMethod(self, ob, method_id, func, args, kw):
+ '''
+ Allows the user to request a workflow action. This method
+ must perform its own security checks.
+ '''
+ sdef = self._getWorkflowStateOf(ob)
+ if sdef is None:
+ raise WorkflowException, 'Object is in an undefined state'
+ if method_id not in sdef.transitions:
+ raise Unauthorized(method_id)
+ tdef = self.transitions.get(method_id, None)
+ if tdef is None or tdef.trigger_type != TRIGGER_WORKFLOW_METHOD:
+ raise WorkflowException, (
+ 'Transition %s is not triggered by a workflow method'
+ % method_id)
+ if not self._checkTransitionGuard(tdef, ob):
+ raise Unauthorized(method_id)
+ res = func(*args, **kw)
+ try:
+ self._changeStateOf(ob, tdef, kw)
+ except ObjectDeleted:
+ # Re-raise with a different result.
+ raise ObjectDeleted(res)
+ except ObjectMoved, ex:
+ # Re-raise with a different result.
+ raise ObjectMoved(ex.getNewObject(), res)
+ return res
+
+DCWorkflowDefinition.wrapWorkflowMethod = DCWorkflowDefinition_wrapWorkflowMethod
+
# Patch updateRoleMappingsFor so that if 2 workflows define security, then we
# should do an AND operation between each permission
@@ -453,6 +481,4 @@
addWorkflowFactory(createERP5Workflow,
id='erp5_workflow',
- title='ERP5-style empty workflow')
-
-
+ title='ERP5-style empty workflow')
Modified: erp5/trunk/products/ERP5Type/patches/WorkflowTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/patches/WorkflowTool.py?rev=13171&r1=13170&r2=13171&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/patches/WorkflowTool.py (original)
+++ erp5/trunk/products/ERP5Type/patches/WorkflowTool.py Thu Mar 1 23:45:53 2007
@@ -12,6 +12,8 @@
#
##############################################################################
+from zLOG import LOG
+
# Make sure Interaction Workflows are called even if method not wrapped
from Products.CMFCore.WorkflowTool import WorkflowTool
@@ -25,24 +27,25 @@
By default, the workflow tool takes the first workflow wich
support the method_id. In ERP5, with Interaction Worfklows, we
may have many workflows wich can support a worfklow method,
- that's why we need this patch
+ that's why we need this patch.
- We should have 1 or 0 classic workflow (ie a DCWorkflow), and
- 0 or many Interaction workflows. We should take care that the
- method will be called once
+ Current implementation supports:
+ - at most 1 DCWorkflow per portal type per method_id
+ - as many Interaction workflows as needed per portal type
+
+ NOTE: automatic transitions are invoked through
+ _findAutomaticTransition in DC Workflows.
+
+ TODO: make it possible to have multiple DC Workflow
+ per portal type per method_id
"""
# Check workflow containing the workflow method
wf_list = []
wfs = self.getWorkflowsFor(ob)
if wfs:
for w in wfs:
-# LOG('ERP5WorkflowTool.wrapWorkflowMethod, is wfMSupported', 0,
-# repr((w.isWorkflowMethodSupported(ob, method_id),
-# w.getId(), ob, method_id )))
if (hasattr(w, 'isWorkflowMethodSupported')
- and w.isWorkflowMethodSupported(ob, method_id)):
- #wf = w
- #break
+ and w.isWorkflowMethodSupported(ob, method_id)):
wf_list.append(w)
else:
wfs = ()
@@ -58,6 +61,13 @@
for w in wf_list:
if w.__class__.__name__ != 'InteractionWorkflowDefinition':
only_interaction_defined = 0
+ # XXX - There is a problem here if the same workflow method
+ # is used by multiple workflows. Function "func" will be
+ # called multiple times. Patch or changes required to mak
+ # sure func is only called once.
+ # Solution consists in reimplementing _invokeWithNotification
+ # at the level of each workflow without notification
+ # (ex. _invokeWithoutNotification)
result = self._invokeWithNotification(
[], ob, method_id, w.wrapWorkflowMethod,
(ob, method_id, func, args, kw), {})
More information about the Erp5-report
mailing list