@@ -89,6 +89,13 @@ def __init__(self, name='', description='', klass=None,
8989
9090 if check is None :
9191 self .check_version = 0
92+ if filter is not None :
93+ if klass is None :
94+ s = "Definition of a filter function" \
95+ " needs a check function if no klass is given"
96+ raise ValueError (s )
97+ self .check = self .check_factory (klass , filter )
98+ self .check_version = 1
9299 else :
93100 args = findargspec .findargspec (check )
94101 # args[2] is the keywords argument. Leave it as a subscript and
@@ -102,6 +109,18 @@ def __init__(self, name='', description='', klass=None,
102109 # function definition is function(db, userid, itemid, **other)
103110 self .check_version = 2
104111
112+ def check_factory (self , klass , filter_function ):
113+ """ When a Permission defines a filter function but no check
114+ function, we manufacture a check function here
115+ """
116+ def check (db , userid , itemid ):
117+ cls = db .getclass (klass )
118+ args = filter_function (db , userid , cls )
119+ for a in args :
120+ if cls .filter ([itemid ], ** a ):
121+ return True
122+ return check
123+
105124 def test (self , db , permission , classname , property , userid , itemid ):
106125 ''' Test permissions 5 args:
107126 permission - string like Edit, Register etc. Required, no wildcard.
0 commit comments