@@ -89,6 +89,13 @@ def __init__(self, name='', description='', klass=None,
89
89
90
90
if check is None :
91
91
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
92
99
else :
93
100
args = findargspec .findargspec (check )
94
101
# args[2] is the keywords argument. Leave it as a subscript and
@@ -102,6 +109,18 @@ def __init__(self, name='', description='', klass=None,
102
109
# function definition is function(db, userid, itemid, **other)
103
110
self .check_version = 2
104
111
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
+
105
124
def test (self , db , permission , classname , property , userid , itemid ):
106
125
''' Test permissions 5 args:
107
126
permission - string like Edit, Register etc. Required, no wildcard.
0 commit comments