common/selectors.py
changeset 394 1cc99ab21304
parent 367 2c0d00b40387
child 402 e0cb1579eba2
equal deleted inserted replaced
393:45a675515427 394:1cc99ab21304
   408     if hasattr(cls, 'etype'):
   408     if hasattr(cls, 'etype'):
   409         eschema = schema.eschema(cls.etype)
   409         eschema = schema.eschema(cls.etype)
   410         if not (eschema.has_perm(req, perm) or eschema.has_local_role(perm)):
   410         if not (eschema.has_perm(req, perm) or eschema.has_local_role(perm)):
   411             return 0
   411             return 0
   412     if hasattr(cls, 'rtype'):
   412     if hasattr(cls, 'rtype'):
   413         if not schema.rschema(cls.rtype).has_perm(req, perm):
   413         rschema = schema.rschema(cls.rtype)
       
   414         if not (rschema.has_perm(req, perm) or rschema.has_local_role(perm)):
   414             return 0
   415             return 0
   415     return 1
   416     return 1
   416 
   417 
   417 @lltrace
   418 @lltrace
   418 def has_relation(cls, req, rset, row=None, col=None, **kwargs):
   419 def has_relation(cls, req, rset, row=None, col=None, **kwargs):
   419     """check if the user has read access on the relations's type refered by the
   420     """check if the user has read access on the relations's type refered by the
   420     .rtype attribute of the class, and if all entities types in the
   421     .rtype attribute of the class, and if all entities types in the
   421     result set has this relation.
   422     result set has this relation.
   422     """
   423     """
   423     if hasattr(cls, 'rtype'):
   424     if hasattr(cls, 'rtype'):
       
   425         rschema = cls.schema.rschema(cls.rtype)
   424         perm = getattr(cls, 'require_permission', 'read')
   426         perm = getattr(cls, 'require_permission', 'read')
   425         if not cls.schema.rschema(cls.rtype).has_perm(req, perm):
   427         if not (rschema.has_perm(req, perm) or rschema.has_local_role(perm)):
   426             return 0
   428             return 0
   427         if row is None:
   429         if row is None:
   428             for etype in rset.column_types(col or 0):
   430             for etype in rset.column_types(col or 0):
   429                 if not cls.relation_possible(etype):
   431                 if not cls.relation_possible(etype):
   430                     return 0
   432                     return 0
   437 def one_has_relation(cls, req, rset, row=None, col=None, **kwargs):
   439 def one_has_relation(cls, req, rset, row=None, col=None, **kwargs):
   438     """check if the user has read access on the relations's type refered by the
   440     """check if the user has read access on the relations's type refered by the
   439     .rtype attribute of the class, and if at least one entity type in the
   441     .rtype attribute of the class, and if at least one entity type in the
   440     result set has this relation.
   442     result set has this relation.
   441     """
   443     """
       
   444     rschema = cls.schema.rschema(cls.rtype)
   442     perm = getattr(cls, 'require_permission', 'read')
   445     perm = getattr(cls, 'require_permission', 'read')
   443     if not cls.schema.rschema(cls.rtype).has_perm(req, perm):
   446     if not (rschema.has_perm(req, perm) or rschema.has_local_role(perm)):
   444         return 0
   447         return 0
   445     if row is None:
   448     if row is None:
   446         for etype in rset.column_types(col or 0):
   449         for etype in rset.column_types(col or 0):
   447             if cls.relation_possible(etype):
   450             if cls.relation_possible(etype):
   448                 return 1
   451                 return 1