200 if rtype in self.subject_relations: |
200 if rtype in self.subject_relations: |
201 meid, seid = fromeid, toeid |
201 meid, seid = fromeid, toeid |
202 else: |
202 else: |
203 assert rtype in self.object_relations |
203 assert rtype in self.object_relations |
204 meid, seid = toeid, fromeid |
204 meid, seid = toeid, fromeid |
205 rql = 'SET E %s P WHERE X %s P, X eid %%(x)s, E eid %%(e)s, NOT E %s P'\ |
205 session.unsafe_execute( |
206 % (self.rtype, self.rtype, self.rtype) |
206 'SET E %s P WHERE X %s P, X eid %%(x)s, E eid %%(e)s, NOT E %s P'\ |
207 rqls = [(rql, {'x': meid, 'e': seid}, ('x', 'e'))] |
207 % (self.rtype, self.rtype, self.rtype), |
208 RQLPrecommitOperation(session, rqls=rqls) |
208 {'x': meid, 'e': seid}, ('x', 'e')) |
209 |
209 |
210 |
210 |
211 class PropagateSubjectRelationAddHook(Hook): |
211 class PropagateSubjectRelationAddHook(Hook): |
212 """propagate on existing entities when a permission or nosy list is added""" |
212 """propagate on existing entities when a permission or nosy list is added""" |
213 events = ('after_add_relation',) |
213 events = ('after_add_relation',) |
217 object_relations = None |
217 object_relations = None |
218 accepts = None # (self.rtype,) |
218 accepts = None # (self.rtype,) |
219 |
219 |
220 def call(self, session, fromeid, rtype, toeid): |
220 def call(self, session, fromeid, rtype, toeid): |
221 eschema = self.schema.eschema(session.describe(fromeid)[0]) |
221 eschema = self.schema.eschema(session.describe(fromeid)[0]) |
222 rqls = [] |
222 execute = session.unsafe_execute |
223 for rel in self.subject_relations: |
223 for rel in self.subject_relations: |
224 if eschema.has_subject_relation(rel): |
224 if eschema.has_subject_relation(rel): |
225 rqls.append(('SET R %s P WHERE X eid %%(x)s, P eid %%(p)s, ' |
225 execute('SET R %s P WHERE X eid %%(x)s, P eid %%(p)s, ' |
226 'X %s R, NOT R %s P' % (rtype, rel, rtype), |
226 'X %s R, NOT R %s P' % (rtype, rel, rtype), |
227 {'x': fromeid, 'p': toeid}, 'x')) |
227 {'x': fromeid, 'p': toeid}, 'x') |
228 for rel in self.object_relations: |
228 for rel in self.object_relations: |
229 if eschema.has_object_relation(rel): |
229 if eschema.has_object_relation(rel): |
230 rqls.append(('SET R %s P WHERE X eid %%(x)s, P eid %%(p)s, ' |
230 execute('SET R %s P WHERE X eid %%(x)s, P eid %%(p)s, ' |
231 'R %s X, NOT R %s P' % (rtype, rel, rtype), |
231 'R %s X, NOT R %s P' % (rtype, rel, rtype), |
232 {'x': fromeid, 'p': toeid}, 'x')) |
232 {'x': fromeid, 'p': toeid}, 'x') |
233 if rqls: |
|
234 RQLPrecommitOperation(session, rqls=rqls) |
|
235 |
233 |
236 |
234 |
237 class PropagateSubjectRelationDelHook(Hook): |
235 class PropagateSubjectRelationDelHook(Hook): |
238 """propagate on existing entities when a permission is deleted""" |
236 """propagate on existing entities when a permission is deleted""" |
239 events = ('after_delete_relation',) |
237 events = ('after_delete_relation',) |
243 object_relations = None |
241 object_relations = None |
244 accepts = None # (self.rtype,) |
242 accepts = None # (self.rtype,) |
245 |
243 |
246 def call(self, session, fromeid, rtype, toeid): |
244 def call(self, session, fromeid, rtype, toeid): |
247 eschema = self.schema.eschema(session.describe(fromeid)[0]) |
245 eschema = self.schema.eschema(session.describe(fromeid)[0]) |
248 rqls = [] |
246 execute = session.unsafe_execute |
249 for rel in self.subject_relations: |
247 for rel in self.subject_relations: |
250 if eschema.has_subject_relation(rel): |
248 if eschema.has_subject_relation(rel): |
251 rqls.append(('DELETE R %s P WHERE X eid %%(x)s, P eid %%(p)s, ' |
249 execute('DELETE R %s P WHERE X eid %%(x)s, P eid %%(p)s, ' |
252 'X %s R' % (rtype, rel), |
250 'X %s R' % (rtype, rel), |
253 {'x': fromeid, 'p': toeid}, 'x')) |
251 {'x': fromeid, 'p': toeid}, 'x') |
254 for rel in self.object_relations: |
252 for rel in self.object_relations: |
255 if eschema.has_object_relation(rel): |
253 if eschema.has_object_relation(rel): |
256 rqls.append(('DELETE R %s P WHERE X eid %%(x)s, P eid %%(p)s, ' |
254 execute('DELETE R %s P WHERE X eid %%(x)s, P eid %%(p)s, ' |
257 'R %s X' % (rtype, rel), |
255 'R %s X' % (rtype, rel), |
258 {'x': fromeid, 'p': toeid}, 'x')) |
256 {'x': fromeid, 'p': toeid}, 'x') |
259 if rqls: |
|
260 RQLPrecommitOperation(session, rqls=rqls) |
|
261 |
257 |
262 |
258 |
263 # abstract classes for operation ############################################### |
259 # abstract classes for operation ############################################### |
264 |
260 |
265 class Operation(object): |
261 class Operation(object): |