Exemple #1
0
 def 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 = apply(func, args, kw)
     try:
         self._changeStateOf(ob, tdef)
     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)
Exemple #2
0
            try:
                sdef = self._executeTransition(ob, tdef, kwargs)
            except ObjectMoved, ex:
                moved = 1
                ob = ex.getNewObject()
                sdef = self._getWorkflowStateOf(ob)
            if sdef is None:
                break
            tdef = self._findAutomaticTransition(ob, sdef)
            if tdef is None:
                # No more automatic transitions.
                break
            # Else continue.
        if moved:
            # Re-raise.
            raise ObjectMoved(ob)

    def _executeTransition(self, ob, tdef=None, kwargs=None):
        '''
        Private method.
        Puts object in a new state.
        '''
        sci = None
        econtext = None
        moved = 0

        # Figure out the old and new states.
        old_sdef = self._getWorkflowStateOf(ob)
        old_state = old_sdef.getId()
        if tdef is None:
            new_state = self.initial_state