350 newgroups = list(erschema.get_groups(action)) |
350 newgroups = list(erschema.get_groups(action)) |
351 for geid, gname in self.rqlexec('Any G, GN WHERE T %s G, G name GN, ' |
351 for geid, gname in self.rqlexec('Any G, GN WHERE T %s G, G name GN, ' |
352 'T eid %%(x)s' % perm, {'x': teid}, 'x', |
352 'T eid %%(x)s' % perm, {'x': teid}, 'x', |
353 ask_confirm=False): |
353 ask_confirm=False): |
354 if not gname in newgroups: |
354 if not gname in newgroups: |
355 if not confirm or self.confirm('remove %s permission of %s to %s?' |
355 if not confirm or self.confirm('Remove %s permission of %s to %s?' |
356 % (action, erschema, gname)): |
356 % (action, erschema, gname)): |
357 self.rqlexec('DELETE T %s G WHERE G eid %%(x)s, T eid %s' |
357 self.rqlexec('DELETE T %s G WHERE G eid %%(x)s, T eid %s' |
358 % (perm, teid), |
358 % (perm, teid), |
359 {'x': geid}, 'x', ask_confirm=False) |
359 {'x': geid}, 'x', ask_confirm=False) |
360 else: |
360 else: |
361 newgroups.remove(gname) |
361 newgroups.remove(gname) |
362 for gname in newgroups: |
362 for gname in newgroups: |
363 if not confirm or self.confirm('grant %s permission of %s to %s?' |
363 if not confirm or self.confirm('Grant %s permission of %s to %s?' |
364 % (action, erschema, gname)): |
364 % (action, erschema, gname)): |
365 self.rqlexec('SET T %s G WHERE G eid %%(x)s, T eid %s' |
365 self.rqlexec('SET T %s G WHERE G eid %%(x)s, T eid %s' |
366 % (perm, teid), |
366 % (perm, teid), |
367 {'x': gm[gname]}, 'x', ask_confirm=False) |
367 {'x': gm[gname]}, 'x', ask_confirm=False) |
368 # handle rql expressions |
368 # handle rql expressions |
369 newexprs = dict((expr.expression, expr) for expr in erschema.get_rqlexprs(action)) |
369 newexprs = dict((expr.expression, expr) for expr in erschema.get_rqlexprs(action)) |
370 for expreid, expression in self.rqlexec('Any E, EX WHERE T %s E, E expression EX, ' |
370 for expreid, expression in self.rqlexec('Any E, EX WHERE T %s E, E expression EX, ' |
371 'T eid %s' % (perm, teid), |
371 'T eid %s' % (perm, teid), |
372 ask_confirm=False): |
372 ask_confirm=False): |
373 if not expression in newexprs: |
373 if not expression in newexprs: |
374 if not confirm or self.confirm('remove %s expression for %s permission of %s?' |
374 if not confirm or self.confirm('Remove %s expression for %s permission of %s?' |
375 % (expression, action, erschema)): |
375 % (expression, action, erschema)): |
376 # deleting the relation will delete the expression entity |
376 # deleting the relation will delete the expression entity |
377 self.rqlexec('DELETE T %s E WHERE E eid %%(x)s, T eid %s' |
377 self.rqlexec('DELETE T %s E WHERE E eid %%(x)s, T eid %s' |
378 % (perm, teid), |
378 % (perm, teid), |
379 {'x': expreid}, 'x', ask_confirm=False) |
379 {'x': expreid}, 'x', ask_confirm=False) |
380 else: |
380 else: |
381 newexprs.pop(expression) |
381 newexprs.pop(expression) |
382 for expression in newexprs.values(): |
382 for expression in newexprs.values(): |
383 expr = expression.expression |
383 expr = expression.expression |
384 if not confirm or self.confirm('add %s expression for %s permission of %s?' |
384 if not confirm or self.confirm('Add %s expression for %s permission of %s?' |
385 % (expr, action, erschema)): |
385 % (expr, action, erschema)): |
386 self.rqlexec('INSERT RQLExpression X: X exprtype %%(exprtype)s, ' |
386 self.rqlexec('INSERT RQLExpression X: X exprtype %%(exprtype)s, ' |
387 'X expression %%(expr)s, X mainvars %%(vars)s, T %s X ' |
387 'X expression %%(expr)s, X mainvars %%(vars)s, T %s X ' |
388 'WHERE T eid %%(x)s' % perm, |
388 'WHERE T eid %%(x)s' % perm, |
389 {'expr': expr, 'exprtype': exprtype, |
389 {'expr': expr, 'exprtype': exprtype, |
1173 for rql, kwargs in rql: |
1173 for rql, kwargs in rql: |
1174 if kwargs: |
1174 if kwargs: |
1175 msg = '%s (%s)' % (rql, kwargs) |
1175 msg = '%s (%s)' % (rql, kwargs) |
1176 else: |
1176 else: |
1177 msg = rql |
1177 msg = rql |
1178 if not ask_confirm or self.confirm('execute rql: %s ?' % msg): |
1178 if not ask_confirm or self.confirm('Execute rql: %s ?' % msg): |
1179 try: |
1179 try: |
1180 res = execute(rql, kwargs, cachekey) |
1180 res = execute(rql, kwargs, cachekey) |
1181 except Exception, ex: |
1181 except Exception, ex: |
1182 if self.confirm('error: %s\nabort?' % ex): |
1182 if self.confirm('Error: %s\nabort?' % ex): |
1183 raise |
1183 raise |
1184 return res |
1184 return res |
1185 |
1185 |
1186 def rqliter(self, rql, kwargs=None, ask_confirm=True): |
1186 def rqliter(self, rql, kwargs=None, ask_confirm=True): |
1187 return ForRqlIterator(self, rql, None, ask_confirm) |
1187 return ForRqlIterator(self, rql, None, ask_confirm) |