Commit 827299ef authored by wenjie.zheng's avatar wenjie.zheng

Merge branch 'erp5_workflow_converted' of...

Merge branch 'erp5_workflow_converted' of https://lab.nexedi.cn/Wenjie/erp5_workflow into erp5_workflow_converted
parents 6a5dbad8 a64acdb8
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Property Sheet" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_count</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_mt_index</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>_tree</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>WorkflowConfigurator</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Property Sheet</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Length" module="BTrees.Length"/>
</pickle>
<pickle> <int>0</int> </pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Standard Property" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>elementary_type/string</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>configuration_after_script_id_property</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Standard Property</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -118,7 +118,7 @@ ...@@ -118,7 +118,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>_text</string> </key> <key> <string>_text</string> </key>
<value> <string>python: [(x, x) for x in here.getParent().getValidRoleList()]</string> </value> <value> <string>python: [(x, x) for x in here.getParent().getManagedRoleList()]</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>managed_permissions = sorted(context.getParent().getManagedPermissionList())\n <value> <string>managed_permissions = sorted(context.getParent().getManagedPermissionList())\n
available_roles = context.getRoleList()\n available_roles = context.getManagedRoleList()\n
\n \n
ma_i = []\n ma_i = []\n
ma_j = []\n ma_j = []\n
......
...@@ -118,7 +118,7 @@ ...@@ -118,7 +118,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>_text</string> </key> <key> <string>_text</string> </key>
<value> <string>python: [(x, x) for x in here.getParent().getRoleList()]</string> </value> <value> <string>python: [(x, x) for x in here.getParent().getManagedRoleList()]</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -118,7 +118,7 @@ ...@@ -118,7 +118,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>_text</string> </key> <key> <string>_text</string> </key>
<value> <string>python: [(x, x) for x in here.getParent().getRoleList()]</string> </value> <value> <string>python: [(x, x) for x in here.getParent().getManagedRoleList()]</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -118,7 +118,7 @@ ...@@ -118,7 +118,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>_text</string> </key> <key> <string>_text</string> </key>
<value> <string>python: [(x, x) for x in here.getParent().getRoleList()]</string> </value> <value> <string>python: [(x, x) for x in here.getParent().getManagedRoleList()]</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -5,4 +5,5 @@ WorkflowScript ...@@ -5,4 +5,5 @@ WorkflowScript
Worklist Worklist
Variable Variable
Transition Transition
State State
\ No newline at end of file WorkflowConfigurator
\ No newline at end of file
...@@ -2241,8 +2241,10 @@ class ERP5Generator(PortalGenerator): ...@@ -2241,8 +2241,10 @@ class ERP5Generator(PortalGenerator):
# Make sure the cache is initialized # Make sure the cache is initialized
p.portal_caches.updateCache() p.portal_caches.updateCache()
# Migrate Workflow Tool at fresh installation # Workflow Tool migration. It's better to create an ERP5 Workflow Tool from
p.migrateToPortalWorkflowClass() # beginning than migrate DC Workflow Tool
# p.migrateToPortalWorkflowClass()
self.setupLastTools(p, **kw) self.setupLastTools(p, **kw)
# Make sure tools are cleanly indexed with a uid before creating children # Make sure tools are cleanly indexed with a uid before creating children
......
...@@ -330,13 +330,13 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -330,13 +330,13 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
state.setStatePermissionRoles(permission_roles) state.setStatePermissionRoles(permission_roles)
if sdef.permission_roles is not None: if sdef.permission_roles is not None:
state.setCellRange(sorted(sdef.permission_roles.keys()), state.setCellRange(sorted(sdef.permission_roles.keys()),
sorted(workflow.getRoleList()), sorted(workflow.getManagedRoleList()),
base_id='cell') base_id='cell')
i = -1 i = -1
for permission in sorted(workflow.getWorkflowManagedPermissionList()): for permission in sorted(workflow.getWorkflowManagedPermissionList()):
i = i + 1 i = i + 1
j = -1 j = -1
for role in workflow.getRoleList(): for role in workflow.getManagedRoleList():
j = j + 1 j = j + 1
pr_cell = state.newContent(id='cell_%s_%s'%(i,j), portal_type='PermissionRoles') pr_cell = state.newContent(id='cell_%s_%s'%(i,j), portal_type='PermissionRoles')
if permission in permission_roles and role in permission_roles[permission]: if permission in permission_roles and role in permission_roles[permission]:
...@@ -406,31 +406,19 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -406,31 +406,19 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
interaction.setReference(tdef.id) interaction.setReference(tdef.id)
script_list = [] script_list = []
for script_name in tdef.activate_script_name: for script_name in tdef.activate_script_name:
if script_name in dc_workflow.interactions.objectIds(): script_list.append('script_'+script_name)
script_list.append('interaction_'+script_name)
elif script_name in dc_workflow.scripts.objectIds():
script_list.append('script_'+script_name)
interaction.setActivateScriptNameList(tuple(script_list)) interaction.setActivateScriptNameList(tuple(script_list))
script_list = [] script_list = []
for script_name in tdef.after_script_name: for script_name in tdef.after_script_name:
if script_name in dc_workflow.interactions.objectIds(): script_list.append('script_'+script_name)
script_list.append('interaction_'+script_name)
elif script_name in dc_workflow.scripts.objectIds():
script_list.append('script_'+script_name)
interaction.setAfterScriptNameList(tuple(script_list)) interaction.setAfterScriptNameList(tuple(script_list))
script_list = [] script_list = []
for script_name in tdef.before_commit_script_name: for script_name in tdef.before_commit_script_name:
if script_name in dc_workflow.interactions.objectIds(): script_list.append('script_'+script_name)
script_list.append('interaction_'+script_name)
elif script_name in dc_workflow.scripts.objectIds():
script_list.append('script_'+script_name)
interaction.setBeforeCommitScriptNameList(tuple(script_list)) interaction.setBeforeCommitScriptNameList(tuple(script_list))
script_list = [] script_list = []
for script_name in tdef.script_name: for script_name in tdef.script_name:
if script_name in dc_workflow.interactions.objectIds(): script_list.append('script_'+script_name)
script_list.append('interaction_'+script_name)
elif script_name in dc_workflow.scripts.objectIds():
script_list.append('script_'+script_name)
interaction.setBeforeScriptNameList(tuple(script_list)) interaction.setBeforeScriptNameList(tuple(script_list))
# configure guard # configure guard
if tdef.guard: if tdef.guard:
...@@ -700,7 +688,9 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool): ...@@ -700,7 +688,9 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
worklist_dict = {} worklist_dict = {}
document = info.object document = info.object
document_pt = document.getTypeInfo() document_pt = None
if document is not None:
document_pt = document.getTypeInfo()
if document_pt is not None: if document_pt is not None:
workflow_list = document_pt.getTypeWorkflowList() workflow_list = document_pt.getTypeWorkflowList()
......
...@@ -56,7 +56,6 @@ def listFilteredActionsFor(self, object=None): ...@@ -56,7 +56,6 @@ def listFilteredActionsFor(self, object=None):
listActionProviderlist = list(self.listActionProviders()) listActionProviderlist = list(self.listActionProviders())
if 'portal_workflow' not in listActionProviderlist: if 'portal_workflow' not in listActionProviderlist:
listActionProviderlist.append('portal_workflow') listActionProviderlist.append('portal_workflow')
for provider_name in listActionProviderlist: for provider_name in listActionProviderlist:
# Include actions from specific tools. # Include actions from specific tools.
provider = getattr(self, provider_name) provider = getattr(self, provider_name)
......
...@@ -772,7 +772,7 @@ def DCWorkflowDefinition_notifySuccess(self, ob, transition_list, result, args=N ...@@ -772,7 +772,7 @@ def DCWorkflowDefinition_notifySuccess(self, ob, transition_list, result, args=N
''' '''
pass pass
# following patches are required for the new workflow tool compatibility. # following 15 patches are required for the new workflow tool compatibility.
def DCWorkflowDefinition_getVariableValueList(self): def DCWorkflowDefinition_getVariableValueList(self):
if self.variables is not None: if self.variables is not None:
return self.variables return self.variables
...@@ -820,7 +820,7 @@ def DCWorkflowDefinition_getPortalType(self): ...@@ -820,7 +820,7 @@ def DCWorkflowDefinition_getPortalType(self):
return self.__class__.__name__ return self.__class__.__name__
def method_getReference(self): def method_getReference(self):
return self.id return self.id
# return infomation to Base_viewDict # a necessary funtion in Base_viewDict
def DCWorkflowDefinition_showDict(self): def DCWorkflowDefinition_showDict(self):
attr_dict = {} attr_dict = {}
for attr in sorted(self.__dict__.keys()): for attr in sorted(self.__dict__.keys()):
......
...@@ -58,7 +58,7 @@ from Testing.ZopeTestCase import PortalTestCase, user_name ...@@ -58,7 +58,7 @@ from Testing.ZopeTestCase import PortalTestCase, user_name
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Products.DCWorkflow.DCWorkflow import ValidationFailed from Products.DCWorkflow.DCWorkflow import ValidationFailed
from Products.ERP5Type.Accessor.Constant import PropertyGetter as ConstantGetter from Products.ERP5Type.Accessor.Constant import PropertyGetter as ConstantGetter
from zLOG import LOG, DEBUG from zLOG import LOG, DEBUG, WARNING
from Products.ERP5Type.tests.backportUnittest import SetupSiteError from Products.ERP5Type.tests.backportUnittest import SetupSiteError
from Products.ERP5Type.tests.utils import addUserToDeveloperRole from Products.ERP5Type.tests.utils import addUserToDeveloperRole
...@@ -934,6 +934,26 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin): ...@@ -934,6 +934,26 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin):
ptype.addTypeWorkflowList(new_workflow.getId()) ptype.addTypeWorkflowList(new_workflow.getId())
# Converting DCWorkflow dynamically
if workflow_tool.getPortalType() != "Workflow Tool":
raise NotImplementedError("Workflow tool has not been converted!")
for workflow_id in workflow_tool:
workflow = workflow_tool._getOb(workflow_id)
if workflow.getPortalType() not in ['Workflow', 'Interaction Workflow']:
LOG("COnverting workflow '%s'"%workflow_id,WARNING," in ERP5TypeTestCase.py 924")
new_workflow = workflow_tool.dc_workflow_asERP5Object(workflow_tool, workflow, temp=0)
type_workflow_dict = workflow_tool.getChainsByType()
for ptype_id in type_workflow_dict:
ptype = getattr(workflow_tool.getPortalObject().portal_types, ptype_id, None)
if ptype is not None and workflow.id in workflow_tool.getChainsByType()[ptype_id]:
# 1. clean DC workflow assignement:
workflow_tool.delTypeCBT(ptype.id, workflow.id)
# 2. assign ERP5 Workflow to portal type:
type_workflow_list = ptype.getTypeWorkflowList()
if new_workflow.getId() not in type_workflow_list:
ptype.addTypeWorkflowList(new_workflow.getId())
def setUpERP5Site(self, def setUpERP5Site(self,
business_template_list=(), business_template_list=(),
quiet=0, quiet=0,
......
...@@ -122,7 +122,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow): ...@@ -122,7 +122,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
break break
if vdef is not None: if vdef is not None:
if vdef.getTypeInfo().getId() == 'Variable': if vdef.getPortalType() == 'Variable':
return 1 return 1
return 0 return 0
return 0 return 0
...@@ -406,9 +406,6 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow): ...@@ -406,9 +406,6 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
def getStateValueList(self): def getStateValueList(self):
return None return None
def getManagedRoleList(self):
return sorted(self.getPortalObject().getDefaultModule('acl_users').valid_roles())
def showAsXML(self, root=None): def showAsXML(self, root=None):
if root is None: if root is None:
root = Element('erp5') root = Element('erp5')
......
...@@ -68,7 +68,7 @@ class PermissionRoles(XMLObject): ...@@ -68,7 +68,7 @@ class PermissionRoles(XMLObject):
# zwj: make sure here gets the right coordinates # zwj: make sure here gets the right coordinates
workflow = self.getParent().getParent() workflow = self.getParent().getParent()
permission_list = sorted(workflow.getManagedPermissionList()) permission_list = sorted(workflow.getManagedPermissionList())
role_list = workflow.getRoleList() role_list = workflow.getManagedRoleList()
permission = permission_list[permission_id] permission = permission_list[permission_id]
role = role_list[role_id] role = role_list[role_id]
# zwj: check the name of the role and permission is the one we want # zwj: check the name of the role and permission is the one we want
......
...@@ -95,32 +95,14 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -95,32 +95,14 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
) )
def notifyCreated(self, document): def notifyCreated(self, document):
"""
Set initial state on the Document
"""
state_var = self.getStateVariable()
object = self.getStateChangeInformation(document, self.getSourceValue())
# Initialize workflow history
state_id = self.getSourceValue().getReference()
status_dict = {state_var: state_id}
variable_list = self.objectValues(portal_type='Variable')
former_status = self._getOb(status_dict[state_var], None)
ec = createExprContext(StateChangeInfo(document, self, former_status))
for variable in variable_list: """Notifies this workflow after an object has been created and added.
if variable.for_status == 0: """
continue try:
if variable.default_expr is not None: self._changeStateOf(document, None)
expr = Expression(variable.default_expr) except ( ObjectDeleted, ObjectMoved ):
value = expr(ec) # Swallow.
else: pass
value = variable.getInitialValue(object=object)
if value is None: value = ''
status_dict[variable.getReference()] = value
self._updateWorkflowHistory(document, status_dict)
self.updateRoleMappingsFor(document)
initializeDocument = notifyCreated initializeDocument = notifyCreated
...@@ -275,7 +257,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -275,7 +257,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
del self.erp5_permission_roles[permission_roles] del self.erp5_permission_roles[permission_roles]
return changed return changed
def getRoleList(self): def getManagedRoleList(self):
return sorted(self.getPortalObject().getDefaultModule('acl_users').valid_roles()) return sorted(self.getPortalObject().getDefaultModule('acl_users').valid_roles())
security.declarePrivate('doActionFor') security.declarePrivate('doActionFor')
...@@ -373,9 +355,11 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -373,9 +355,11 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
workflow_tool = portal.portal_workflow workflow_tool = portal.portal_workflow
result = [] result = []
append = result.append append = result.append
if info.object.getTypeInfo() is not None: document = info.object
for workflow_id in info.object.getTypeInfo().getTypeWorkflowList(): if document is not None:
append(info.object.getTypeInfo().getId()) if document.getTypeInfo() is not None:
for workflow_id in document.getTypeInfo().getTypeWorkflowList():
append(document.getTypeInfo().getId())
return result return result
portal_type_list = getPortalTypeListForWorkflow(self.id) portal_type_list = getPortalTypeListForWorkflow(self.id)
...@@ -613,7 +597,8 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -613,7 +597,8 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
if tdef is None: if tdef is None:
new_sdef = self.getSourceValue() new_sdef = self.getSourceValue()
if not new_state: new_state = new_sdef.getReference()
if not new_sdef:
return return
former_status = {} former_status = {}
else: else:
...@@ -654,6 +639,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -654,6 +639,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
if state_values is None: state_values = {} if state_values is None: state_values = {}
tdef_exprs = {} tdef_exprs = {}
transition_variable_list = []
if tdef is not None: if tdef is not None:
transition_variable_list = tdef.objectValues(portal_type='Transition Variable') transition_variable_list = tdef.objectValues(portal_type='Transition Variable')
for transition_variable in transition_variable_list: for transition_variable in transition_variable_list:
...@@ -719,22 +705,23 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -719,22 +705,23 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
self.updateRoleMappingsFor(document) self.updateRoleMappingsFor(document)
# Execute the "after" script. # Execute the "after" script.
script_id = getattr(tdef, 'getAfterScriptId')() if tdef is not None:
if script_id is not None: script_id = getattr(tdef, 'getAfterScriptId')()
kwargs = form_kw if script_id is not None:
# Script can be either script or workflow method kwargs = form_kw
if script_id in old_sdef.getDestinationIdList() and \ # Script can be either script or workflow method
self._getOb(script_id).trigger_type == TRIGGER_WORKFLOW_METHOD: if script_id in old_sdef.getDestinationIdList() and \
getattr(document, convertToMixedCase(self._getOb(script_id).getReference()))() self._getOb(script_id).trigger_type == TRIGGER_WORKFLOW_METHOD:
else: getattr(document, convertToMixedCase(self._getOb(script_id).getReference()))()
script = self._getOb(script_id)
# Pass lots of info to the script in a single parameter.
if script.getTypeInfo().getId() == 'Workflow Script':
sci = StateChangeInfo(
document, self, former_status, tdef, old_sdef, new_sdef, kwargs)
script.execute(sci) # May throw an exception.
else: else:
raise NotImplementedError ('Unsupported Script %s for state %s'%(script_id, old_sdef.getReference())) script = self._getOb(script_id)
# Pass lots of info to the script in a single parameter.
if script.getTypeInfo().getId() == 'Workflow Script':
sci = StateChangeInfo(
document, self, former_status, tdef, old_sdef, new_sdef, kwargs)
script.execute(sci) # May throw an exception.
else:
raise NotImplementedError ('Unsupported Script %s for state %s'%(script_id, old_sdef.getReference()))
# Return the new state object. # Return the new state object.
if moved_exc is not None: if moved_exc is not None:
# Propagate the notification that the object has moved. # Propagate the notification that the object has moved.
......
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