server/rqlrewrite.py
branchtls-sprint
changeset 1132 96752791c2b6
parent 0 b97547f5f1fa
child 1138 22f634977c95
equal deleted inserted replaced
1131:544609e83317 1132:96752791c2b6
     1 """RQL rewriting utilities, used for read security checking
     1 """RQL rewriting utilities, used for read security checking
     2 
     2 
     3 :organization: Logilab
     3 :organization: Logilab
     4 :copyright: 2007-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     4 :copyright: 2007-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 """
     6 """
     7 
     7 
     8 from rql import nodes, stmts, TypeResolverException
     8 from rql import nodes, stmts, TypeResolverException
     9 from cubicweb import Unauthorized, server, typed_eid
     9 from cubicweb import Unauthorized, server, typed_eid
    23                         try:
    23                         try:
    24                             defined[var].stinfo['possibletypes'].remove(newsol[var])
    24                             defined[var].stinfo['possibletypes'].remove(newsol[var])
    25                         except KeyError:
    25                         except KeyError:
    26                             pass
    26                             pass
    27                         break
    27                         break
    28                 except KeyError,ex:
    28                 except KeyError:
    29                     # variable has been rewritten
    29                     # variable has been rewritten
    30                     continue
    30                     continue
    31             else:
    31             else:
    32                 newsolutions.append(newsol)
    32                 newsolutions.append(newsol)
    33                 solutions.remove(newsol)
    33                 solutions.remove(newsol)
   355             ttypes_func = rschema.objects
   355             ttypes_func = rschema.objects
   356             rprop = rschema.rproperty
   356             rprop = rschema.rproperty
   357         else: # target == 'subject':
   357         else: # target == 'subject':
   358             cardindex = 1
   358             cardindex = 1
   359             ttypes_func = rschema.subjects
   359             ttypes_func = rschema.subjects
   360             rprop = lambda x,y,z: rschema.rproperty(y, x, z)
   360             rprop = lambda x, y, z: rschema.rproperty(y, x, z)
   361         for etype in self.varstinfo['possibletypes']:
   361         for etype in self.varstinfo['possibletypes']:
   362             for ttype in ttypes_func(etype):
   362             for ttype in ttypes_func(etype):
   363                 if rprop(etype, ttype, 'cardinality')[cardindex] in '+*':
   363                 if rprop(etype, ttype, 'cardinality')[cardindex] in '+*':
   364                     return False
   364                     return False
   365         return True
   365         return True