Commit bda71cc4 authored by wenjie.zheng's avatar wenjie.zheng Committed by Sebastien Robin

Workflow.py: modify object getter since the id of object has added suffix; add...

Workflow.py: modify object getter since the id of object has added suffix; add property Reference and variable _isAWorkflow.
parent 94d2d891
...@@ -63,17 +63,18 @@ from Products.CMFCore.utils import getToolByName ...@@ -63,17 +63,18 @@ from Products.CMFCore.utils import getToolByName
from Products.ERP5.Tool import ERP5WorkflowTool from Products.ERP5.Tool import ERP5WorkflowTool
from Products.ERP5Type.id_as_reference import IdAsReferenceMixin from Products.ERP5Type.id_as_reference import IdAsReferenceMixin
class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject): class Workflow(IdAsReferenceMixin('_workflow'), XMLObject):
""" """
A ERP5 Workflow. A ERP5 Workflow.
""" """
meta_type = 'ERP5 Workflow' meta_type = 'ERP5 Workflow'
portal_type = 'Workflow' portal_type = 'Workflow'
_isAWorkflow = True # DCWorkflow Tool compatibility
add_permission = Permissions.AddPortalContent add_permission = Permissions.AddPortalContent
isPortalContent = 1 isPortalContent = 1
isRADContent = 1 isRADContent = 1
default_reference = ''
### zwj: for security issue ### zwj: for security issue
managed_permission_list = () managed_permission_list = ()
managed_role = () managed_role = ()
...@@ -90,6 +91,7 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject): ...@@ -90,6 +91,7 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject):
PropertySheet.XMLObject, PropertySheet.XMLObject,
PropertySheet.CategoryCore, PropertySheet.CategoryCore,
PropertySheet.DublinCore, PropertySheet.DublinCore,
PropertySheet.Reference,
PropertySheet.Workflow, PropertySheet.Workflow,
) )
...@@ -104,7 +106,7 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject): ...@@ -104,7 +106,7 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject):
# Initialize workflow history # Initialize workflow history
status_dict = {state_var: self.getSourceId()} status_dict = {state_var: self.getSourceId()}
variable_list = self.objectValues(portal_type='Variable') variable_list = self.objectValues(portal_type='Variable')
former_status = self._getOb(status_dict[state_var], None) ### _getObjectByRef former_status = self._getOb(status_dict[state_var], None)
ec = Expression_createExprContext(StateChangeInfo(document, self, former_status)) ec = Expression_createExprContext(StateChangeInfo(document, self, former_status))
for variable in variable_list: for variable in variable_list:
...@@ -115,7 +117,7 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject): ...@@ -115,7 +117,7 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject):
value = expr(ec) value = expr(ec)
else: else:
value = variable.getInitialValue(object=object) value = variable.getInitialValue(object=object)
status_dict[variable.getId()] = value ### getRef status_dict['_'.join(variable.getId().split('_')[:-1])] = value # remove suffix
self._updateWorkflowHistory(document, status_dict) self._updateWorkflowHistory(document, status_dict)
self.updateRoleMappingsFor(document) self.updateRoleMappingsFor(document)
...@@ -124,7 +126,7 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject): ...@@ -124,7 +126,7 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject):
""" """
Generate a key used in the workflow history. Generate a key used in the workflow history.
""" """
history_key = self.unrestrictedTraverse(self.getRelativeUrl()).getId()### getRef history_key = self.unrestrictedTraverse(self.getRelativeUrl()).getId()
return history_key return history_key
def _updateWorkflowHistory(self, document, status_dict): def _updateWorkflowHistory(self, document, status_dict):
...@@ -150,13 +152,6 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject): ...@@ -150,13 +152,6 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject):
# XXX this _p_changed is apparently not necessary # XXX this _p_changed is apparently not necessary
#document.workflow_history._p_changed = 1 #document.workflow_history._p_changed = 1
### a getter for Workflow. For other objects, this is not recommended.
def _getObjectByRef(self, ref):
for ob in self:
if wf.getRef() == ref:
return ob
return None
def getCurrentStatusDict(self, document): def getCurrentStatusDict(self, document):
""" """
Get the current status dict. Get the current status dict.
...@@ -212,8 +207,8 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject): ...@@ -212,8 +207,8 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject):
if sdef is None: if sdef is None:
return 0 return 0
if action in sdef.getDestinationIdList():### getRef, for id in sdef.getDestinationIdList: tdef = sdef._getOb(id) if ob.getRef == action .... if action in sdef.getDestinationIdList():
tdef = self._getOb(action, None) ### _getObjectByRef tdef = self._getOb(action, None)
if (tdef is not None and if (tdef is not None and
tdef.trigger_type == TRIGGER_USER_ACTION and tdef.trigger_type == TRIGGER_USER_ACTION and
self._checkTransitionGuard(tdef, document, **kw)): self._checkTransitionGuard(tdef, document, **kw)):
...@@ -242,8 +237,8 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject): ...@@ -242,8 +237,8 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject):
def _findAutomaticTransition(self, document, sdef): def _findAutomaticTransition(self, document, sdef):
tdef = None tdef = None
for tid in sdef.getDestinationIdList():### getRef for tid in sdef.getDestinationIdList():
t = self._getOb(id=tid) ### getObjectByRef t = self._getOb(id=tid)
if t is not None and t.trigger_type == TRIGGER_AUTOMATIC: if t is not None and t.trigger_type == TRIGGER_AUTOMATIC:
if self._checkTransitionGuard(t, document): if self._checkTransitionGuard(t, document):
tdef = t tdef = t
...@@ -289,11 +284,11 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject): ...@@ -289,11 +284,11 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject):
if sdef is None: if sdef is None:
raise WorkflowException(_(u'Object is in an undefined state.')) raise WorkflowException(_(u'Object is in an undefined state.'))
if self.isActionSupported(document, action, **kw): if self.isActionSupported(document, action, **kw):
wf_id = self.getId()### getRef wf_id = self.getId()
if wf_id is None: if wf_id is None:
raise WorkflowException( raise WorkflowException(
_(u'Requested workflow definition not found.')) _(u'Requested workflow not found.'))
tdef = self._getOb(id=action)### _getObjectByRef tdef = self._getOb(id=action)
if tdef not in self.objectValues(portal_type='Transition'): if tdef not in self.objectValues(portal_type='Transition'):
raise Unauthorized(action) raise Unauthorized(action)
...@@ -308,10 +303,9 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject): ...@@ -308,10 +303,9 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject):
workflow_list = document.getTypeInfo().getTypeERP5WorkflowList() workflow_list = document.getTypeInfo().getTypeERP5WorkflowList()
for interaction_workflow in self.getParent().objectValues(portal_type='Interaction Workflow'): for interaction_workflow in self.getParent().objectValues(portal_type='Interaction Workflow'):
if interaction_workflow.getId() in workflow_list:### getRef if interaction_workflow.getId() in workflow_list:
for interaction in interaction_workflow.objectValues(portal_type='Interaction'): for interaction in interaction_workflow.objectValues(portal_type='Interaction'):
LOG('looking for interaction trigger method %s'%str(action.split('_')[0]), WARNING, 'in WorkflowTool.py') if '_'.join(action.split('_')[0:-1]) in interaction.getMethodId():
if str(action.split('_')[0]) in interaction.getMethodId():
interaction.execute(document) interaction.execute(document)
def _changeStateOf(self, document, tdef=None, kwargs=None): def _changeStateOf(self, document, tdef=None, kwargs=None):
...@@ -347,8 +341,8 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject): ...@@ -347,8 +341,8 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject):
return None return None
res = [] res = []
for tid in sdef.getDestinationIdList():### getRef, keep tid for following codes for tid in sdef.getDestinationIdList():
tdef = self._getOb(id=tid)### _getObjectByRef tdef = self._getOb(id=tid)
if tdef is not None and tdef.trigger_type == TRIGGER_USER_ACTION and \ if tdef is not None and tdef.trigger_type == TRIGGER_USER_ACTION and \
tdef.actbox_name and self._checkTransitionGuard(tdef, document): tdef.actbox_name and self._checkTransitionGuard(tdef, document):
if fmt_data is None: if fmt_data is None:
...@@ -375,6 +369,10 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject): ...@@ -375,6 +369,10 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject):
(worklist id as key) and which value is a dict composed of (worklist id as key) and which value is a dict composed of
variable matches. variable matches.
""" """
if not info.object.getPortalType() in ['Workflow', 'Interaction Workflow']:
# avoid getting DC workflow
return
if not self.objectValues(portal_type='Worklist'): if not self.objectValues(portal_type='Worklist'):
return None return None
...@@ -390,15 +388,15 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject): ...@@ -390,15 +388,15 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject):
#LOG ('Supported portal types are: %s'%result, WARNING, ' in Workflow.py') #LOG ('Supported portal types are: %s'%result, WARNING, ' in Workflow.py')
return result return result
portal_type_list = getPortalTypeListForWorkflow(self.id)### getRef portal_type_list = getPortalTypeListForWorkflow(self.id)
if not portal_type_list: if not portal_type_list:
return None return None
variable_match_dict = {} variable_match_dict = {}
security_manager = getSecurityManager() security_manager = getSecurityManager()
workflow_id = self.id### getRef, don't use id anymore, but keep workflow_id for following codes workflow_id = self.id
workflow_title = self.getTitle() workflow_title = self.getTitle()
for worklist_definition in self.objectValues(portal_type='Worklist'): for worklist_definition in self.objectValues(portal_type='Worklist'):
worklist_id = worklist_definition.getId() ### getRef worklist_id = worklist_definition.getId()
action_box_name = worklist_definition.getActboxName() action_box_name = worklist_definition.getActboxName()
guard = worklist_definition.getGuard() guard = worklist_definition.getGuard()
if action_box_name: if action_box_name:
...@@ -449,7 +447,7 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject): ...@@ -449,7 +447,7 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject):
'worklist_title': action_box_name, 'worklist_title': action_box_name,
'worklist_id': worklist_id, 'worklist_id': worklist_id,
'workflow_title': workflow_title, 'workflow_title': workflow_title,
'workflow_id': workflow_id,### see line 397 redefine reference as id 'workflow_id': workflow_id,
'action_box_url': worklist_definition.actbox_url, 'action_box_url': worklist_definition.actbox_url,
'action_box_category': worklist_definition.actbox_category} 'action_box_category': worklist_definition.actbox_category}
...@@ -468,15 +466,14 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject): ...@@ -468,15 +466,14 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject):
LOG('464 zwj: ob is %s, name is %s'%(ob.getId(),name), WARNING, ' in Workflow.py.') LOG('464 zwj: ob is %s, name is %s'%(ob.getId(),name), WARNING, ' in Workflow.py.')
state_var = self.getStateVariable() state_var = self.getStateVariable()
if name == state_var: if name == state_var:
#return self._getWorkflowStateOf(ob, 1) LOG ('468 State = : %s'%ob._getDefaultAcquiredValue(state_var).getId(), WARNING, ' in Workflow.py')
LOG ('468 State = : %s'%ob._getDefaultAcquiredValue(state_var).getId(), WARNING, ' in Workflow.py')### getRef return ob._getDefaultAcquiredValue(state_var).getId()
return ob._getDefaultAcquiredValue(state_var).getId()### getRef
vdef = self._getOb(name)### _getObjectByRef vdef = self._getOb(name)
LOG('zwj: vdef is %s'%vdef.getId(), WARNING, ' in Workflow.py.')### getRef LOG('zwj: vdef is %s'%vdef.getId(), WARNING, ' in Workflow.py.')
status_dict = self.getCurrentStatusDict(ob) status_dict = self.getCurrentStatusDict(ob)
former_status = self._getOb(status_dict[state_var], None) ### _getObjectByRef former_status = self._getOb(status_dict[state_var], None)
if former_status == None: if former_status == None:
former_status = self.getSourceValue() former_status = self.getSourceValue()
...@@ -500,17 +497,17 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject): ...@@ -500,17 +497,17 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject):
def _getWorkflowStateOf(self, ob, id_only=0): def _getWorkflowStateOf(self, ob, id_only=0):
tool = getToolByName(self, 'portal_workflow') tool = getToolByName(self, 'portal_workflow')
status = tool.getStatusOf(self.id, ob)### at tool level has to use id, not ref status = tool.getStatusOf(self.id, ob)
if status is None: if status is None:
state = self.getSourceId()### getSource, getRef, state = self.getSourceId()
else: else:
state = status.get(self.getStateVariable(), None) state = status.get(self.getStateVariable(), None)
if state is None: if state is None:
state = self.getSourceId()### getSource, getRef, state = self.getSourceId()
if id_only: if id_only:
return state return state
else: else:
return self._getOb(state, None)### _getObjectByRef return self._getOb(state, None)
########### ###########
## Graph ## ## Graph ##
...@@ -531,29 +528,29 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject): ...@@ -531,29 +528,29 @@ class Workflow(IdAsReferenceMixin('erp5workflow_'), XMLObject):
for state in self.objectValues(portal_type='State'): for state in self.objectValues(portal_type='State'):
out.append('%s [shape=box,label="%s",' \ out.append('%s [shape=box,label="%s",' \
'style="filled",fillcolor="#ffcc99"];' % \ 'style="filled",fillcolor="#ffcc99"];' % \
(state.getId(), state.getTitle())) ### getRef (state.getId(), state.getTitle()))
# XXX Use API instead of getDestinationValueList # XXX Use API instead of getDestinationValueList
for available_transition in state.getDestinationValueList(): for available_transition in state.getDestinationValueList():
transition_with_init_state_list.append(available_transition.getId()) ### getRef transition_with_init_state_list.append(available_transition.getId())
destination_state = available_transition.getDestinationValue() destination_state = available_transition.getDestinationValue()
if destination_state is None: if destination_state is None:
# take care of 'remain in state' transitions # take care of 'remain in state' transitions
destination_state = state destination_state = state
# #
key = (state.getId(), destination_state.getId()) ### getRef key = (state.getId(), destination_state.getId())
value = transition_dict.get(key, []) value = transition_dict.get(key, [])
value.append(available_transition.getTitle()) value.append(available_transition.getTitle())
transition_dict[key] = value transition_dict[key] = value
# iterate also on transitions, and add transitions with no initial state # iterate also on transitions, and add transitions with no initial state
for transition in self.objectValues(portal_type='Transition'): for transition in self.objectValues(portal_type='Transition'):
trans_id = transition.getId() ### getRef trans_id = transition.getId()
if trans_id not in transition_with_init_state_list: if trans_id not in transition_with_init_state_list:
destination_state = transition.getDestinationValue() destination_state = transition.getDestinationValue()
if destination_state is None: if destination_state is None:
dest_state_id = None dest_state_id = None
else: else:
dest_state_id = destination_state.getId() ### getRef dest_state_id = destination_state.getId()
key = (None, dest_state_id) key = (None, dest_state_id)
value = transition_dict.get(key, []) value = transition_dict.get(key, [])
......
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