diff --git a/stateful/README.txt b/stateful/README.txt index f3fefca..d12e8d3 100644 --- a/stateful/README.txt +++ b/stateful/README.txt @@ -78,6 +78,8 @@ Check actors >>> removeAction.actors = ['master'] >>> demo.getActors() + >>> demo.checkActors(['master']) + True >>> demo.empty = True >>> removeAction in demo.getAvailableTransitionsForUser() diff --git a/stateful/base.py b/stateful/base.py index 1d53e3b..67cee8d 100644 --- a/stateful/base.py +++ b/stateful/base.py @@ -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 diff --git a/stateful/definition.py b/stateful/definition.py index 01fda8f..7dea42c 100644 --- a/stateful/definition.py +++ b/stateful/definition.py @@ -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 diff --git a/stateful/interfaces.py b/stateful/interfaces.py index e312f50..14d0aa1 100644 --- a/stateful/interfaces.py +++ b/stateful/interfaces.py @@ -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):