35 """ |
35 """ |
36 __docformat__ = "restructuredtext en" |
36 __docformat__ = "restructuredtext en" |
37 |
37 |
38 from warnings import warn |
38 from warnings import warn |
39 from logging import getLogger |
39 from logging import getLogger |
|
40 from itertools import chain |
40 |
41 |
41 from logilab.common.decorators import classproperty |
42 from logilab.common.decorators import classproperty |
42 from logilab.common.deprecation import deprecated |
43 from logilab.common.deprecation import deprecated |
43 from logilab.common.logging_ext import set_log_methods |
44 from logilab.common.logging_ext import set_log_methods |
44 |
45 |
112 def regular_session(cls, req, **kwargs): |
113 def regular_session(cls, req, **kwargs): |
113 if req is None or req.is_super_session: |
114 if req is None or req.is_super_session: |
114 return 0 |
115 return 0 |
115 return 1 |
116 return 1 |
116 |
117 |
|
118 |
|
119 class rechain(object): |
|
120 def __init__(self, *iterators): |
|
121 self.iterators = iterators |
|
122 def __iter__(self): |
|
123 return iter(chain(*self.iterators)) |
|
124 |
|
125 |
117 class match_rtype(match_search_state): |
126 class match_rtype(match_search_state): |
118 """accept if parameters specified as initializer arguments are specified |
127 """accept if parameters specified as initializer arguments are specified |
119 in named arguments given to the selector |
128 in named arguments given to the selector |
120 |
129 |
121 :param *expected: parameters (eg `basestring`) which are expected to be |
130 :param *expected: parameters (eg `basestring`) which are expected to be |
122 found in named arguments (kwargs) |
131 found in named arguments (kwargs) |
123 """ |
132 """ |
|
133 def __init__(self, *expected): |
|
134 self.expected = expected |
|
135 if len(expected) == 1: |
|
136 try: |
|
137 iter(expected[0]) |
|
138 self.expected = expected[0] |
|
139 except TypeError: |
|
140 pass |
124 |
141 |
125 @lltrace |
142 @lltrace |
126 def __call__(self, cls, req, *args, **kwargs): |
143 def __call__(self, cls, req, *args, **kwargs): |
127 return kwargs.get('rtype') in self.expected |
144 return kwargs.get('rtype') in self.expected |
128 |
145 |
191 # base classes for relation propagation ######################################## |
208 # base classes for relation propagation ######################################## |
192 |
209 |
193 class PropagateSubjectRelationHook(Hook): |
210 class PropagateSubjectRelationHook(Hook): |
194 """propagate permissions and nosy list when new entity are added""" |
211 """propagate permissions and nosy list when new entity are added""" |
195 events = ('after_add_relation',) |
212 events = ('after_add_relation',) |
|
213 |
196 # to set in concrete class |
214 # to set in concrete class |
197 rtype = None |
215 main_rtype = None |
198 subject_relations = None |
216 subject_relations = None |
199 object_relations = None |
217 object_relations = None |
200 accepts = None # subject_relations + object_relations |
|
201 |
218 |
202 def __call__(self): |
219 def __call__(self): |
203 for eid in (self.eidfrom, self.eidto): |
220 for eid in (self.eidfrom, self.eidto): |
204 etype = self._cw.describe(eid)[0] |
221 etype = self._cw.describe(eid)[0] |
205 if not self.schema.eschema(etype).has_subject_relation(self.main_rtype): |
222 if not self.schema.eschema(etype).has_subject_relation(self.main_rtype): |
216 |
233 |
217 |
234 |
218 class PropagateSubjectRelationAddHook(Hook): |
235 class PropagateSubjectRelationAddHook(Hook): |
219 """propagate on existing entities when a permission or nosy list is added""" |
236 """propagate on existing entities when a permission or nosy list is added""" |
220 events = ('after_add_relation',) |
237 events = ('after_add_relation',) |
|
238 |
221 # to set in concrete class |
239 # to set in concrete class |
222 main_rtype = None |
240 main_rtype = None |
223 subject_relations = None |
241 subject_relations = None |
224 object_relations = None |
242 object_relations = None |
225 |
243 |
239 |
257 |
240 |
258 |
241 class PropagateSubjectRelationDelHook(Hook): |
259 class PropagateSubjectRelationDelHook(Hook): |
242 """propagate on existing entities when a permission is deleted""" |
260 """propagate on existing entities when a permission is deleted""" |
243 events = ('after_delete_relation',) |
261 events = ('after_delete_relation',) |
|
262 |
244 # to set in concrete class |
263 # to set in concrete class |
245 main_rtype = None |
264 main_rtype = None |
246 subject_relations = None |
265 subject_relations = None |
247 object_relations = None |
266 object_relations = None |
248 |
267 |