def _executeTransition(self, ob, tdef=None, kwargs=None): ''' Private method. Puts object in a new state. ''' moved = 0 if tdef is None: state = self.initial_state former_status = {} action = '' else: state = tdef.new_state_id if not state: # Stay in same state. state = self._getWorkflowStateOf(ob, 1) former_status = self._getStatusOf(ob) action = tdef.id # Execute a script if specified. if tdef.script_name: script = self.scripts[tdef.script_name] # Pass lots of info to the script in a single parameter. md = exprNamespace(ob, self, former_status, action, state, kwargs) accessor = NamespaceAccessor(md) try: script(accessor) # May throw an exception. except ObjectMoved, ex: ob = ex.getNewObject() moved = 1
def getCatalogVariablesFor(self, ob): ''' Allows this workflow to make workflow-specific variables available to the catalog, making it possible to implement worklists in a simple way. Returns a mapping containing the catalog variables that apply to ob. ''' res = {} status = self._getStatusOf(ob) for id, vdef in self.variables.items(): if vdef.for_catalog: if status.has_key(id): value = status[id] # Not set yet. Use a default. elif vdef.default_expr is not None: md = exprNamespace(ob, self, status) value = vdef.default_expr(md) else: value = vdef.default_value res[id] = value # Always provide the state variable. state_var = self.state_var res[state_var] = status.get(state_var, self.initial_state) return res
def check(self, sm, wf_def, ob): ''' Checks conditions in this guard. ''' pp = self.permissions if pp: found = 0 for p in pp: if sm.checkPermission(p, ob): found = 1 break if not found: return 0 roles = self.roles if roles: # Require at least one of the given roles. found = 0 u_roles = sm.getUser().getRolesInContext(ob) for role in roles: if role in u_roles: found = 1 break if not found: return 0 expr = self.expr if expr is not None: md = exprNamespace(ob, wf_def) res = expr(md) if not res: return 0 return 1
def getInfoFor(self, ob, name, default): ''' Allows the user to request information provided by the workflow. This method must perform its own security checks. ''' if name == self.state_var: return self._getWorkflowStateOf(ob, 1) vdef = self.variables[name] if vdef.info_guard is not None and not vdef.info_guard.check( getSecurityManager(), self, ob): return default status = self._getStatusOf(ob) if status is not None and status.has_key(id): value = status[id] # Not set yet. Use a default. elif vdef.default_expr is not None: md = exprNamespace(ob, self, status) value = vdef.default_expr(md) else: value = vdef.default_value return value
if sdef is None: raise WorkflowException, 'Destination state undefined: ' + state # Update variables. state_values = sdef.var_values if state_values is None: state_values = {} tdef_exprs = None if tdef is not None: tdef_exprs = tdef.var_exprs if tdef_exprs is None: tdef_exprs = {} status = {} for id, vdef in self.variables.items(): if not vdef.for_status: continue if state_values.has_key(id): value = state_values[id] elif tdef_exprs.has_key(id): md = exprNamespace(ob, self, former_status, action, state, kwargs) value = tdef_exprs[id](md) elif vdef.default_expr is not None: md = exprNamespace(ob, self, former_status, action, state, kwargs) value = vdef.default_expr(md) else: value = vdef.default_value status[id] = value # Update state. status[self.state_var] = state tool = aq_parent(aq_inner(self)) tool.setStatusOf(self.id, ob, status) # Update role to permission assignments. self.updateRoleMappingsFor(ob)