From 51cc5a6d3668a4dc91493f6361a12f83b4178575 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Fri, 26 Jul 2013 09:29:55 +0200 Subject: [PATCH] move checkActors() to stateful object to allow overriding by subclass --- stateful/README.txt | 2 ++ stateful/base.py | 11 +++++++++++ stateful/definition.py | 11 +---------- stateful/interfaces.py | 7 +++---- 4 files changed, 17 insertions(+), 14 deletions(-) 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 39d088c..74272f4 100644 --- a/stateful/base.py +++ b/stateful/base.py @@ -82,6 +82,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 b8b8131..ed4f010 100644 --- a/stateful/definition.py +++ b/stateful/definition.py @@ -125,7 +125,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 @@ -133,15 +133,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):