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 @@
<dictionary>
<item>
<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>
</dictionary>
</pickle>
......
......@@ -51,7 +51,7 @@
<item>
<key> <string>_body</string> </key>
<value> <string>managed_permissions = sorted(context.getParent().getManagedPermissionList())\n
available_roles = context.getRoleList()\n
available_roles = context.getManagedRoleList()\n
\n
ma_i = []\n
ma_j = []\n
......
......@@ -118,7 +118,7 @@
<dictionary>
<item>
<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>
</dictionary>
</pickle>
......
......@@ -118,7 +118,7 @@
<dictionary>
<item>
<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>
</dictionary>
</pickle>
......
......@@ -118,7 +118,7 @@
<dictionary>
<item>
<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>
</dictionary>
</pickle>
......
......@@ -5,4 +5,5 @@ WorkflowScript
Worklist
Variable
Transition
State
\ No newline at end of file
State
WorkflowConfigurator
\ No newline at end of file
......@@ -2241,8 +2241,10 @@ class ERP5Generator(PortalGenerator):
# Make sure the cache is initialized
p.portal_caches.updateCache()
# Migrate Workflow Tool at fresh installation
p.migrateToPortalWorkflowClass()
# Workflow Tool migration. It's better to create an ERP5 Workflow Tool from
# beginning than migrate DC Workflow Tool
# p.migrateToPortalWorkflowClass()
self.setupLastTools(p, **kw)
# Make sure tools are cleanly indexed with a uid before creating children
......
......@@ -330,13 +330,13 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
state.setStatePermissionRoles(permission_roles)
if sdef.permission_roles is not None:
state.setCellRange(sorted(sdef.permission_roles.keys()),
sorted(workflow.getRoleList()),
sorted(workflow.getManagedRoleList()),
base_id='cell')
i = -1
for permission in sorted(workflow.getWorkflowManagedPermissionList()):
i = i + 1
j = -1
for role in workflow.getRoleList():
for role in workflow.getManagedRoleList():
j = j + 1
pr_cell = state.newContent(id='cell_%s_%s'%(i,j), portal_type='PermissionRoles')
if permission in permission_roles and role in permission_roles[permission]:
......@@ -406,31 +406,19 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
interaction.setReference(tdef.id)
script_list = []
for script_name in tdef.activate_script_name:
if script_name in dc_workflow.interactions.objectIds():
script_list.append('interaction_'+script_name)
elif script_name in dc_workflow.scripts.objectIds():
script_list.append('script_'+script_name)
script_list.append('script_'+script_name)
interaction.setActivateScriptNameList(tuple(script_list))
script_list = []
for script_name in tdef.after_script_name:
if script_name in dc_workflow.interactions.objectIds():
script_list.append('interaction_'+script_name)
elif script_name in dc_workflow.scripts.objectIds():
script_list.append('script_'+script_name)
script_list.append('script_'+script_name)
interaction.setAfterScriptNameList(tuple(script_list))
script_list = []
for script_name in tdef.before_commit_script_name:
if script_name in dc_workflow.interactions.objectIds():
script_list.append('interaction_'+script_name)
elif script_name in dc_workflow.scripts.objectIds():
script_list.append('script_'+script_name)
script_list.append('script_'+script_name)
interaction.setBeforeCommitScriptNameList(tuple(script_list))
script_list = []
for script_name in tdef.script_name:
if script_name in dc_workflow.interactions.objectIds():
script_list.append('interaction_'+script_name)
elif script_name in dc_workflow.scripts.objectIds():
script_list.append('script_'+script_name)
script_list.append('script_'+script_name)
interaction.setBeforeScriptNameList(tuple(script_list))
# configure guard
if tdef.guard:
......@@ -700,7 +688,9 @@ class WorkflowTool(BaseTool, OriginalWorkflowTool):
worklist_dict = {}
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:
workflow_list = document_pt.getTypeWorkflowList()
......
......@@ -56,7 +56,6 @@ def listFilteredActionsFor(self, object=None):
listActionProviderlist = list(self.listActionProviders())
if 'portal_workflow' not in listActionProviderlist:
listActionProviderlist.append('portal_workflow')
for provider_name in listActionProviderlist:
# Include actions from specific tools.
provider = getattr(self, provider_name)
......
......@@ -772,7 +772,7 @@ def DCWorkflowDefinition_notifySuccess(self, ob, transition_list, result, args=N
'''
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):
if self.variables is not None:
return self.variables
......@@ -820,7 +820,7 @@ def DCWorkflowDefinition_getPortalType(self):
return self.__class__.__name__
def method_getReference(self):
return self.id
# return infomation to Base_viewDict
# a necessary funtion in Base_viewDict
def DCWorkflowDefinition_showDict(self):
attr_dict = {}
for attr in sorted(self.__dict__.keys()):
......
......@@ -58,7 +58,7 @@ from Testing.ZopeTestCase import PortalTestCase, user_name
from Products.CMFCore.utils import getToolByName
from Products.DCWorkflow.DCWorkflow import ValidationFailed
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.utils import addUserToDeveloperRole
......@@ -934,6 +934,26 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin):
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,
business_template_list=(),
quiet=0,
......
......@@ -122,7 +122,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
break
if vdef is not None:
if vdef.getTypeInfo().getId() == 'Variable':
if vdef.getPortalType() == 'Variable':
return 1
return 0
return 0
......@@ -406,9 +406,6 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), Workflow):
def getStateValueList(self):
return None
def getManagedRoleList(self):
return sorted(self.getPortalObject().getDefaultModule('acl_users').valid_roles())
def showAsXML(self, root=None):
if root is None:
root = Element('erp5')
......
......@@ -68,7 +68,7 @@ class PermissionRoles(XMLObject):
# zwj: make sure here gets the right coordinates
workflow = self.getParent().getParent()
permission_list = sorted(workflow.getManagedPermissionList())
role_list = workflow.getRoleList()
role_list = workflow.getManagedRoleList()
permission = permission_list[permission_id]
role = role_list[role_id]
# zwj: check the name of the role and permission is the one we want
......
......@@ -95,32 +95,14 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
)
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:
if variable.for_status == 0:
continue
if variable.default_expr is not None:
expr = Expression(variable.default_expr)
value = expr(ec)
else:
value = variable.getInitialValue(object=object)
if value is None: value = ''
status_dict[variable.getReference()] = value
self._updateWorkflowHistory(document, status_dict)
self.updateRoleMappingsFor(document)
"""Notifies this workflow after an object has been created and added.
"""
try:
self._changeStateOf(document, None)
except ( ObjectDeleted, ObjectMoved ):
# Swallow.
pass
initializeDocument = notifyCreated
......@@ -275,7 +257,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
del self.erp5_permission_roles[permission_roles]
return changed
def getRoleList(self):
def getManagedRoleList(self):
return sorted(self.getPortalObject().getDefaultModule('acl_users').valid_roles())
security.declarePrivate('doActionFor')
......@@ -373,9 +355,11 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
workflow_tool = portal.portal_workflow
result = []
append = result.append
if info.object.getTypeInfo() is not None:
for workflow_id in info.object.getTypeInfo().getTypeWorkflowList():
append(info.object.getTypeInfo().getId())
document = info.object
if document is not None:
if document.getTypeInfo() is not None:
for workflow_id in document.getTypeInfo().getTypeWorkflowList():
append(document.getTypeInfo().getId())
return result
portal_type_list = getPortalTypeListForWorkflow(self.id)
......@@ -613,7 +597,8 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
if tdef is None:
new_sdef = self.getSourceValue()
if not new_state:
new_state = new_sdef.getReference()
if not new_sdef:
return
former_status = {}
else:
......@@ -654,6 +639,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
if state_values is None: state_values = {}
tdef_exprs = {}
transition_variable_list = []
if tdef is not None:
transition_variable_list = tdef.objectValues(portal_type='Transition Variable')
for transition_variable in transition_variable_list:
......@@ -719,22 +705,23 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
self.updateRoleMappingsFor(document)
# Execute the "after" script.
script_id = getattr(tdef, 'getAfterScriptId')()
if script_id is not None:
kwargs = form_kw
# Script can be either script or workflow method
if script_id in old_sdef.getDestinationIdList() and \
self._getOb(script_id).trigger_type == TRIGGER_WORKFLOW_METHOD:
getattr(document, convertToMixedCase(self._getOb(script_id).getReference()))()
else:
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.
if tdef is not None:
script_id = getattr(tdef, 'getAfterScriptId')()
if script_id is not None:
kwargs = form_kw
# Script can be either script or workflow method
if script_id in old_sdef.getDestinationIdList() and \
self._getOb(script_id).trigger_type == TRIGGER_WORKFLOW_METHOD:
getattr(document, convertToMixedCase(self._getOb(script_id).getReference()))()
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.
if moved_exc is not None:
# 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