server/querier.py
changeset 2601 5196d213f4e3
parent 2593 16d9419a4a79
child 2621 1b9d08840a0e
equal deleted inserted replaced
2600:6cd6c5d11b45 2601:5196d213f4e3
    21 from cubicweb.rset import ResultSet
    21 from cubicweb.rset import ResultSet
    22 
    22 
    23 from cubicweb.server.utils import cleanup_solutions
    23 from cubicweb.server.utils import cleanup_solutions
    24 from cubicweb.server.rqlannotation import SQLGenAnnotator, set_qdata
    24 from cubicweb.server.rqlannotation import SQLGenAnnotator, set_qdata
    25 from cubicweb.server.ssplanner import add_types_restriction
    25 from cubicweb.server.ssplanner import add_types_restriction
       
    26 
       
    27 READ_ONLY_RTYPES = set(('eid', 'has_text', 'is', 'is_instance_of', 'identity'))
    26 
    28 
    27 def empty_rset(session, rql, args, rqlst=None):
    29 def empty_rset(session, rql, args, rqlst=None):
    28     """build an empty result set object"""
    30     """build an empty result set object"""
    29     return ResultSet([], rql, args, rqlst=rqlst)
    31     return ResultSet([], rql, args, rqlst=rqlst)
    30 
    32 
    65     for the associated variable with the given solution
    67     for the associated variable with the given solution
    66     """
    68     """
    67     if rqlst.where is not None:
    69     if rqlst.where is not None:
    68         for rel in rqlst.where.iget_nodes(Relation):
    70         for rel in rqlst.where.iget_nodes(Relation):
    69             # XXX has_text may have specific perm ?
    71             # XXX has_text may have specific perm ?
    70             if rel.r_type in ('is', 'is_instance_of', 'has_text', 'identity', 'eid'):
    72             if rel.r_type in READ_ONLY_RTYPES:
    71                 continue
    73                 continue
    72             if not schema.rschema(rel.r_type).has_access(user, 'read'):
    74             if not schema.rschema(rel.r_type).has_access(user, 'read'):
    73                 raise Unauthorized('read', rel.r_type)
    75                 raise Unauthorized('read', rel.r_type)
    74     localchecks = {}
    76     localchecks = {}
    75     # iterate on defined_vars and not on solutions to ignore column aliases
    77     # iterate on defined_vars and not on solutions to ignore column aliases
   369         """
   371         """
   370         to_select = {}
   372         to_select = {}
   371         for relation in rqlst.main_relations:
   373         for relation in rqlst.main_relations:
   372             lhs, rhs = relation.get_variable_parts()
   374             lhs, rhs = relation.get_variable_parts()
   373             rtype = relation.r_type
   375             rtype = relation.r_type
   374             if rtype in ('eid', 'has_text', 'is', 'is_instance_of', 'identity'):
   376             if rtype in READ_ONLY_RTYPES:
   375                 raise QueryError("can't assign to %s" % rtype)
   377                 raise QueryError("can't assign to %s" % rtype)
   376             try:
   378             try:
   377                 edef = to_build[str(lhs)]
   379                 edef = to_build[str(lhs)]
   378             except KeyError:
   380             except KeyError:
   379                 # lhs var is not to build, should be selected and added as an
   381                 # lhs var is not to build, should be selected and added as an