[gen]: method Wrapper.do: added param 'noSecurity' allowing to bypass check of roles mentioned as conditions for triggering worfklow actions.
This commit is contained in:
		
							parent
							
								
									699cc8346b
								
							
						
					
					
						commit
						178059ba1b
					
				
					 4 changed files with 11 additions and 9 deletions
				
			
		|  | @ -2631,7 +2631,7 @@ class Transition: | ||||||
|                     break |                     break | ||||||
|         return res |         return res | ||||||
| 
 | 
 | ||||||
|     def isTriggerable(self, obj, wf): |     def isTriggerable(self, obj, wf, noSecurity=False): | ||||||
|         '''Can this transition be triggered on p_obj?''' |         '''Can this transition be triggered on p_obj?''' | ||||||
|         wf = wf.__instance__ # We need the prototypical instance here. |         wf = wf.__instance__ # We need the prototypical instance here. | ||||||
|         # Checks that the current state of the object is a start state for this |         # Checks that the current state of the object is a start state for this | ||||||
|  | @ -2651,6 +2651,7 @@ class Transition: | ||||||
|         if isinstance(self.condition, Role): |         if isinstance(self.condition, Role): | ||||||
|             # Condition is a role. Transition may be triggered if the user has |             # Condition is a role. Transition may be triggered if the user has | ||||||
|             # this role. |             # this role. | ||||||
|  |             if noSecurity: return True | ||||||
|             return user.has_role(self.condition.name, obj) |             return user.has_role(self.condition.name, obj) | ||||||
|         elif type(self.condition) == types.FunctionType: |         elif type(self.condition) == types.FunctionType: | ||||||
|             return self.condition(wf, obj.appy()) |             return self.condition(wf, obj.appy()) | ||||||
|  | @ -2663,7 +2664,7 @@ class Transition: | ||||||
|                 if isinstance(roleOrFunction, basestring): |                 if isinstance(roleOrFunction, basestring): | ||||||
|                     if hasRole == None: |                     if hasRole == None: | ||||||
|                         hasRole = False |                         hasRole = False | ||||||
|                     if user.has_role(roleOrFunction, obj): |                     if user.has_role(roleOrFunction, obj) or noSecurity: | ||||||
|                         hasRole = True |                         hasRole = True | ||||||
|                 elif type(roleOrFunction) == types.FunctionType: |                 elif type(roleOrFunction) == types.FunctionType: | ||||||
|                     if not roleOrFunction(wf, obj.appy()): |                     if not roleOrFunction(wf, obj.appy()): | ||||||
|  |  | ||||||
|  | @ -1071,7 +1071,7 @@ class BaseMixin: | ||||||
|             return self.goto(msg) |             return self.goto(msg) | ||||||
| 
 | 
 | ||||||
|     def trigger(self, transitionName, comment='', doAction=True, doNotify=True, |     def trigger(self, transitionName, comment='', doAction=True, doNotify=True, | ||||||
|                 doHistory=True, doSay=True): |                 doHistory=True, doSay=True, noSecurity=False): | ||||||
|         '''Triggers transition named p_transitionName.''' |         '''Triggers transition named p_transitionName.''' | ||||||
|         # Check that this transition exists. |         # Check that this transition exists. | ||||||
|         wf = self.getWorkflow() |         wf = self.getWorkflow() | ||||||
|  | @ -1080,7 +1080,7 @@ class BaseMixin: | ||||||
|             raise 'Transition "%s" was not found.' % transitionName |             raise 'Transition "%s" was not found.' % transitionName | ||||||
|         # Is this transition triggerable? |         # Is this transition triggerable? | ||||||
|         transition = getattr(wf, transitionName) |         transition = getattr(wf, transitionName) | ||||||
|         if not transition.isTriggerable(self, wf): |         if not transition.isTriggerable(self, wf, noSecurity=noSecurity): | ||||||
|             raise 'Transition "%s" can\'t be triggered.' % transitionName |             raise 'Transition "%s" can\'t be triggered.' % transitionName | ||||||
|         # Trigger the transition |         # Trigger the transition | ||||||
|         transition.trigger(transitionName, self, wf, comment, doAction=doAction, |         transition.trigger(transitionName, self, wf, comment, doAction=doAction, | ||||||
|  |  | ||||||
|  | @ -86,9 +86,9 @@ | ||||||
|       <td tal:condition="isDataChange" tal:content="python: _('data_change')"></td> |       <td tal:condition="isDataChange" tal:content="python: _('data_change')"></td> | ||||||
|       <td tal:condition="not: isDataChange" |       <td tal:condition="not: isDataChange" | ||||||
|           tal:content="python: _(contextObj.getWorkflowLabel(event['action']))"/> |           tal:content="python: _(contextObj.getWorkflowLabel(event['action']))"/> | ||||||
|       <td tal:define="actorid python:event.get('actor')" |       <td tal:define="actorId python:event.get('actor')" | ||||||
|           tal:content="python: tool.getUserName(actorid)"/> |           tal:content="python: tool.getUserName(actorId)"/> | ||||||
|       <td tal:content="event/time"/> |       <td tal:content="python: tool.formatDate(event['time'], withHour=True)"/> | ||||||
|       <td tal:condition="not: isDataChange"> |       <td tal:condition="not: isDataChange"> | ||||||
|         <tal:c condition="rhComments" |         <tal:c condition="rhComments" | ||||||
|                content="structure python: contextObj.formatText(rhComments)"/> |                content="structure python: contextObj.formatText(rhComments)"/> | ||||||
|  |  | ||||||
|  | @ -255,11 +255,12 @@ class AbstractWrapper(object): | ||||||
|                                 format=format) |                                 format=format) | ||||||
| 
 | 
 | ||||||
|     def do(self, transition, comment='', doAction=True, doNotify=True, |     def do(self, transition, comment='', doAction=True, doNotify=True, | ||||||
|            doHistory=True): |            doHistory=True, noSecurity=False): | ||||||
|         '''This method allows to trigger on p_self a workflow p_transition |         '''This method allows to trigger on p_self a workflow p_transition | ||||||
|            programmatically. See doc in self.o.do.''' |            programmatically. See doc in self.o.do.''' | ||||||
|         return self.o.trigger(transition, comment, doAction=doAction, |         return self.o.trigger(transition, comment, doAction=doAction, | ||||||
|                             doNotify=doNotify, doHistory=doHistory, doSay=False) |                               doNotify=doNotify, doHistory=doHistory, | ||||||
|  |                               doSay=False, noSecurity=noSecurity) | ||||||
| 
 | 
 | ||||||
|     def log(self, message, type='info'): return self.o.log(message, type) |     def log(self, message, type='info'): return self.o.log(message, type) | ||||||
|     def say(self, message, type='info'): return self.o.say(message, type) |     def say(self, message, type='info'): return self.o.say(message, type) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Gaetan Delannay
						Gaetan Delannay