entity.py
branchstable
changeset 9188 0677e03077fb
parent 8992 55a1567d92a0
child 9256 697a8181ba30
child 9277 c964d8cf6efc
equal deleted inserted replaced
9187:8406bef5d5f2 9188:0677e03077fb
     1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
  1179                 # compute a varmap suitable to RQLRewriter.rewrite argument
  1179                 # compute a varmap suitable to RQLRewriter.rewrite argument
  1180                 varmap = dict((v, v) for v in (searchedvar.name, evar.name)
  1180                 varmap = dict((v, v) for v in (searchedvar.name, evar.name)
  1181                               if v in select.defined_vars and v in cstr.mainvars)
  1181                               if v in select.defined_vars and v in cstr.mainvars)
  1182                 # rewrite constraint by constraint since we want a AND between
  1182                 # rewrite constraint by constraint since we want a AND between
  1183                 # expressions.
  1183                 # expressions.
  1184                 rewriter.rewrite(select, [(varmap, (cstr,))], select.solutions,
  1184                 rewriter.rewrite(select, [(varmap, (cstr,))], args, existant)
  1185                                  args, existant)
       
  1186         # insert security RQL expressions granting the permission to 'add' the
  1185         # insert security RQL expressions granting the permission to 'add' the
  1187         # relation into the rql syntax tree, if necessary
  1186         # relation into the rql syntax tree, if necessary
  1188         rqlexprs = rdef.get_rqlexprs('add')
  1187         rqlexprs = rdef.get_rqlexprs('add')
  1189         if not self.has_eid():
  1188         if not self.has_eid():
  1190             rqlexprs = [rqlexpr for rqlexpr in rqlexprs
  1189             rqlexprs = [rqlexpr for rqlexpr in rqlexprs
  1192         if rqlexprs and not rdef.has_perm(self._cw, 'add', **sec_check_args):
  1191         if rqlexprs and not rdef.has_perm(self._cw, 'add', **sec_check_args):
  1193             # compute a varmap suitable to RQLRewriter.rewrite argument
  1192             # compute a varmap suitable to RQLRewriter.rewrite argument
  1194             varmap = dict((v, v) for v in (searchedvar.name, evar.name)
  1193             varmap = dict((v, v) for v in (searchedvar.name, evar.name)
  1195                           if v in select.defined_vars)
  1194                           if v in select.defined_vars)
  1196             # rewrite all expressions at once since we want a OR between them.
  1195             # rewrite all expressions at once since we want a OR between them.
  1197             rewriter.rewrite(select, [(varmap, rqlexprs)], select.solutions,
  1196             rewriter.rewrite(select, [(varmap, rqlexprs)], args, existant)
  1198                              args, existant)
       
  1199         # ensure we have an order defined
  1197         # ensure we have an order defined
  1200         if not select.orderby:
  1198         if not select.orderby:
  1201             select.add_sort_var(select.defined_vars[searchedvar.name])
  1199             select.add_sort_var(select.defined_vars[searchedvar.name])
  1202         # we're done, turn the rql syntax tree as a string
  1200         # we're done, turn the rql syntax tree as a string
  1203         rql = select.as_string()
  1201         rql = select.as_string()