Changeset 2311


Ignore:
Timestamp:
Feb 9, 2010 9:52:02 PM (8 years ago)
Author:
hazmat
bzr:committer:
kapil.foss@gmail.com
bzr:mapping-version:
v4
bzr:revno:
13
bzr:root:
ore.workflow/trunk
bzr:text-parents:

CHANGES.txt svn-v4:0c136a03-8cb9-0310-93d0-cb4b675037b3:ore.workflow/trunk:2270
CREDITS.txt svn-v4:0c136a03-8cb9-0310-93d0-cb4b675037b3:ore.workflow/trunk:2128
src/ore/workflow/workflow.py svn-v4:0c136a03-8cb9-0310-93d0-cb4b675037b3:ore.workflow/trunk:2269
bzr:timestamp:
2010-02-09 16:51:57.229000092 -0500
bzr:user-agent:
bzr2.0.2+bzr-svn0.6.5
svn:original-date:
2010-02-09T21:51:57.229000Z
Message:

commit fix for firing transition sans security, based on c.ledermann's patch. whitespace geddon

Location:
ore.workflow/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ore.workflow/trunk/CHANGES.txt

    r2270 r2311  
    11 
    22ore.workflow changes 
     3 
     41.0.4 (2010-2-9) 
     5 
     6- fix for firing a transition toward a state, with check_security=False 
     7  (ledermann) 
    38 
    491.0.3 (2008-11-5) 
  • ore.workflow/trunk/CREDITS.txt

    r2128 r2311  
    66Kapil Thangavelu - allowed for multiple workflows in a site, and 
    77parallel workflows, maintainer of [ ore.workflow ] 
     8Christian Ledermann - testing, feedback, patches. 
    89 
    910The hurry.workflow library for Zope 3 was originally developed at 
  • ore.workflow/trunk/src/ore/workflow/workflow.py

    r2269 r2311  
    22from cStringIO import StringIO 
    33from persistent import Persistent 
    4 from zope import interface  
     4from zope import interface 
    55from zope.event import notify 
    66from zope.security.management import getInteraction 
     
    1414except: 
    1515    from zope.app.annotation.interfaces import IAnnotations 
    16      
     16 
    1717from zope.app.container.contained import Contained 
    1818 
     
    2222    from zope.app.event.objectevent import ObjectModifiedEvent 
    2323 
    24 try:     
     24try: 
    2525    from zope.component.interfaces import ObjectEvent 
    2626except ImportError: 
     
    4242    pass 
    4343 
    44 # XXX this is needed to make the tests pass in the absence of 
    45 # interactions.. 
     44# Used needed to make the tests pass in the absence of 
     45# interactions.. or when security checks are explicity not requested. 
    4646def nullCheckPermission(permission, principal_id): 
    4747    return True 
     
    6666        self.order = order 
    6767        self.user_data = user_data 
    68          
     68 
    6969    def __cmp__(self, other): 
    7070        return cmp(self.order, other.order) 
    71      
     71 
    7272class Workflow(Persistent, Contained): 
    7373    interface.implements(IWorkflow) 
    74      
     74 
    7575    def __init__(self, transitions): 
    7676        self.refresh(transitions) 
     
    8787            self._register(transition) 
    8888        self._p_changed = True 
    89          
     89 
    9090    def getTransitions(self, source): 
    9191        try: 
     
    9393        except KeyError: 
    9494            return [] 
    95          
     95 
    9696    def getTransition(self, source, transition_id): 
    9797        transition = self._id_transitions[transition_id] 
     
    132132 
    133133        transition colors 
    134          
     134 
    135135         - automatic triggers in green 
    136136         - system triggers in yellow if no conditions 
     
    139139 
    140140        state colors 
    141          
     141 
    142142         - end states in red 
    143           
    144143        """ 
    145          
    146144        io = StringIO() 
    147145        states = set() 
     
    180178        return io.getvalue() 
    181179 
    182          
     180 
    183181class WorkflowState(object): 
    184      
     182 
    185183    interface.implements(IWorkflowState) 
    186184 
    187185    workflow_state_key = "hurry.workflow.state" 
    188186    workflow_id_key  = "hurry.workflow.id" 
    189      
     187 
    190188    def __init__(self, context): 
    191189        # XXX okay, I'm tired of it not being able to set annotations, so 
     
    197195        wf_versions = zapi.getUtility(IWorkflowVersions) 
    198196        self.setId(wf_versions.createVersionId()) 
    199          
     197 
    200198    def setState(self, state): 
    201199        if state != self.getState(): 
    202200            IAnnotations(self.context)[ self.workflow_state_key ] = state 
    203              
     201 
    204202    def setId(self, id): 
    205203        # XXX catalog should be informed (or should it?) 
    206204        IAnnotations(self.context)[ self.workflow_id_key ] = id 
    207          
     205 
    208206    def getState(self): 
    209207        try: 
     
    217215        except KeyError: 
    218216            return None 
    219              
     217 
    220218class WorkflowInfo(object): 
    221219 
     
    234232            return IWorkflowState( self.context ) 
    235233        return IWorkflowState( context ) 
    236      
     234 
    237235    def workflow( self ): 
    238236        return zapi.queryAdapter(self.context, IWorkflow) or zapi.getUtility(IWorkflow) 
     
    260258    def _setState( self, state_id ): 
    261259        pass 
    262          
     260 
    263261    def fireTransition(self, transition_id, comment=None, side_effect=None, 
    264262                       check_security=True): 
     
    270268        self._check( transition, check_security ) 
    271269        transition.action(self, self.context) 
    272          
     270 
    273271        if transition.source is None: 
    274272            self.state().initialize() 
     
    279277        # change state of context or new object 
    280278        state.setState(transition.destination) 
    281          
     279 
    282280        # allow workflow info to provide custom behavior for state changes 
    283281        self._setState(transition.destination) 
     
    287285                                        transition.destination, transition, comment) 
    288286        notify(event) 
    289          
     287 
    290288        # send modified event for original or new object 
    291289        notify(ObjectModifiedEvent(self.context)) 
     
    293291    def fireTransitionToward(self, state, comment=None, side_effect=None, 
    294292                             check_security=True): 
    295         transition_ids = self.getFireableTransitionIdsToward(state) 
     293        transition_ids = self.getFireableTransitionIdsToward(state, check_security) 
    296294        if not transition_ids: 
    297295            raise interfaces.NoTransitionAvailableError 
     
    300298        return self.fireTransition(transition_ids[0], 
    301299                                   comment, side_effect, check_security) 
    302          
     300 
    303301    def fireTransitionForVersions(self, state, transition_id): 
    304302        id = self.state().getId() 
     
    321319                # we're done with this one now. 
    322320                return 
    323              
     321 
    324322    def hasVersion(self, state): 
    325323        wf_versions = zapi.getUtility(IWorkflowVersions) 
    326324        id = self.state().getId() 
    327325        return wf_versions.hasVersion(state, id) 
    328      
    329     def getManualTransitionIds(self): 
     326 
     327    def getManualTransitionIds(self, check_security=True): 
    330328        try: 
    331329            checkPermission = getInteraction().checkPermission 
    332330        except NoInteraction: 
    333331            checkPermission = nullCheckPermission 
     332        if not check_security: 
     333            checkPermission = nullCheckPermission 
     334 
    334335        return [transition.transition_id for transition in 
    335336                sorted(self._getTransitions(MANUAL)) if 
     
    343344                transition.condition(self, self.context)] 
    344345 
    345     def getFireableTransitionIds(self): 
    346         return self.getManualTransitionIds() + self.getSystemTransitionIds() 
    347      
     346    def getFireableTransitionIds(self, check_security=True): 
     347        return (self.getManualTransitionIds(check_security=check_security) + 
     348                self.getSystemTransitionIds()) 
     349 
    348350    def getFireableTransitionIdsToward(self, state): 
    349351        wf = self.workflow() 
     
    354356                result.append(transition_id) 
    355357        return result 
    356      
     358 
    357359    def getAutomaticTransitionIds(self): 
    358360        return [transition.transition_id for transition in 
     
    374376class AdaptedWorkflowBase( object ): 
    375377    pass 
    376      
     378 
    377379def AdaptedWorkflow( workflow ): 
    378380    """ 
     
    381383 
    382384    assert IWorkflow.providedBy( workflow ) 
    383      
     385 
    384386    class AdaptedWorkflow( AdaptedWorkflowBase ): 
    385387 
     
    389391 
    390392            for m in IWorkflow.names(): 
    391                 setattr( self, m, getattr( workflow, m ) )  
     393                setattr( self, m, getattr( workflow, m ) ) 
    392394 
    393395    interface.classImplements( AdaptedWorkflow, IWorkflow ) 
     
    407409 
    408410    assert IWorkflow.providedBy( workflow ) 
    409      
     411 
    410412    class _ParallelWorkflowState( WorkflowState ): 
    411413        workflow_state_key = "%s.state"%(wf_name) 
     
    414416    class _ParallelWorkflowInfo( ParallelWorkflowInfo ): 
    415417        name = wf_name 
    416          
     418 
    417419    if not register_for: 
    418420        return [ workflow, _ParallelWorkflowState, _ParallelWorkflowInfo ] 
     
    420422    # when you have a few these, zcml registration can be tedious, try to optionally 
    421423    # automate some of the pain, even if only for the global site manager 
    422      
     424 
    423425    if IAdaptedWorkflow.providedBy( workflow ): 
    424426        component.provideAdapter( workflow, (register_for,), IWorkflow, wf_name ) 
     
    430432                              IWorkflowInfo, 
    431433                              wf_name ) 
    432      
     434 
    433435    component.provideAdapter( _ParallelWorkflowState, 
    434436                              (register_for, ), 
     
    441443 
    442444    name = "ore_workflow" 
    443      
     445 
    444446    def info( self, context = None ): 
    445447        if context is None: 
    446448            return zapi.getAdapter( self.context, IWorkflowInfo, self.name ) 
    447         return zapi.getAdapter( context, IWorkflowInfo, self.name )         
     449        return zapi.getAdapter( context, IWorkflowInfo, self.name ) 
    448450 
    449451    def state( self, context = None ): 
     
    451453            return zapi.getAdapter( self.context, IWorkflowState, self.name ) 
    452454        return zapi.getAdapter( context, IWorkflowState, self.name ) 
    453      
     455 
    454456    def workflow( self ): 
    455457        return zapi.queryAdapter( self.context, IWorkflow, self.name ) \ 
    456458               or zapi.getUtility(IWorkflow, self.name ) 
    457459 
    458          
    459                      
    460460class WorkflowVersions(object): 
    461461    interface.implements(IWorkflowVersions) 
Note: See TracChangeset for help on using the changeset viewer.