Merge branch 'master' into bbmaster
This commit is contained in:
commit
9989af825a
4 changed files with 17 additions and 14 deletions
|
@ -78,6 +78,8 @@ Check actors
|
|||
>>> removeAction.actors = ['master']
|
||||
|
||||
>>> demo.getActors()
|
||||
>>> demo.checkActors(['master'])
|
||||
True
|
||||
|
||||
>>> demo.empty = True
|
||||
>>> removeAction in demo.getAvailableTransitionsForUser()
|
||||
|
|
|
@ -80,6 +80,17 @@ class Stateful(object):
|
|||
def getStatesDefinition(self):
|
||||
return statesDefinitions.get(self.statesDefinition, None)
|
||||
|
||||
def checkActors(self, actors):
|
||||
if not actors:
|
||||
return True
|
||||
stfActors = self.getActors()
|
||||
if stfActors is None:
|
||||
return True
|
||||
for actor in actors:
|
||||
if actor in stfActors:
|
||||
return True
|
||||
return False
|
||||
|
||||
def getActors(self):
|
||||
return None
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ class StatesDefinition(object):
|
|||
return False
|
||||
if action.condition and not action.condition(obj):
|
||||
return False
|
||||
if not self.checkActors(action.actors, obj):
|
||||
if not obj.checkActors(action.actors):
|
||||
return False
|
||||
if not self.checkRoles(action.roles, obj):
|
||||
return False
|
||||
|
@ -137,15 +137,6 @@ class StatesDefinition(object):
|
|||
return False
|
||||
return True
|
||||
|
||||
def checkActors(self, actors, obj):
|
||||
stfActors = obj.getActors()
|
||||
if stfActors is None:
|
||||
return True
|
||||
for actor in actors:
|
||||
if actor in stfActors:
|
||||
return True
|
||||
return False
|
||||
|
||||
def checkRoles(self, roles, obj):
|
||||
return True
|
||||
|
||||
|
|
|
@ -103,10 +103,9 @@ class IStateful(Interface):
|
|||
for the current state.
|
||||
"""
|
||||
|
||||
def getActors():
|
||||
""" Return a collection of names of actors or groups that will be
|
||||
used for checking if a certain transition is allowed. May be
|
||||
None in which case not checking should be applied.
|
||||
def checkActors(actors):
|
||||
""" Return True if this stateful object is associated with the
|
||||
actors given.
|
||||
"""
|
||||
|
||||
def notify(transition, previousState):
|
||||
|
|
Loading…
Add table
Reference in a new issue