Merge branch 'bbmaster' of ssh://git.cy55.de/home/git/cybertools into bbmaster

This commit is contained in:
hplattner 2013-08-07 11:03:16 +02:00
commit 7aaa0547a1
4 changed files with 17 additions and 14 deletions

View file

@ -78,6 +78,8 @@ Check actors
>>> removeAction.actors = ['master']
>>> demo.getActors()
>>> demo.checkActors(['master'])
True
>>> demo.empty = True
>>> removeAction in demo.getAvailableTransitionsForUser()

View file

@ -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

View file

@ -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

View file

@ -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):