Commit c589e844 authored by iv's avatar iv

ERP5Workflow: perf: cleanup of doActionFor

Before this fix, checking that the action was possible from the
current state was not done correctly (isActionSupported was not
used to set the transition).

Also avoid to check if transition is in getTransitionValueList:
it is useless (transition *is* on of the workflow or is None!)
and calls the expensive 'objectValues' method
parent 484fd839
...@@ -297,26 +297,24 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -297,26 +297,24 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
Allows the user to request a workflow action. This method Allows the user to request a workflow action. This method
must perform its own security checks. must perform its own security checks.
''' '''
sdef = self._getWorkflowStateOf(document, id_only=0) state = self._getWorkflowStateOf(document, id_only=0)
kw['comment'] = comment kw['comment'] = comment
if sdef is None: if state 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):
wf_id = self.getId() if not self.isActionSupported(document, action, state=state, **kw):
if wf_id is None: # action is not allowed from the current state
raise WorkflowException(
_(u'Requested workflow not found.'))
tdef = self._getOb(id=action)
if tdef not in self.getTransitionValueList():
raise Unauthorized(action) raise Unauthorized(action)
if tdef is None or tdef.getTriggerType() != TRIGGER_USER_ACTION:
transition = self._getOb(action, None)
if transition is None or transition.getTriggerType() != TRIGGER_USER_ACTION:
msg = _(u"Transition '${action_id}' is not triggered by a user " msg = _(u"Transition '${action_id}' is not triggered by a user "
u"action.", mapping={'action_id': action}) u"action.", mapping={'action_id': action})
raise WorkflowException(msg) raise WorkflowException(msg)
if not self._checkTransitionGuard(tdef, document, **kw): if not self._checkTransitionGuard(transition, document, **kw):
raise Unauthorized(action) raise Unauthorized(action)
self._changeStateOf(document, tdef, kw) self._changeStateOf(document, transition, kw)
def _changeStateOf(self, document, tdef=None, kwargs=None): def _changeStateOf(self, document, tdef=None, kwargs=None):
''' '''
......
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