selectors.py
changeset 3890 d7a270f50f54
parent 3777 3ef8cdb5fb1c
parent 3877 7ca53fc72a0a
child 4026 d80a55a024d8
equal deleted inserted replaced
3810:5b75fd66c80e 3890:d7a270f50f54
   665         self.rtype = rtype
   665         self.rtype = rtype
   666         self.role = role
   666         self.role = role
   667         self.target_etype = target_etype
   667         self.target_etype = target_etype
   668         self.action = action
   668         self.action = action
   669 
   669 
   670     @lltrace
       
   671     def __call__(self, cls, req, *args, **kwargs):
       
   672         rschema = req.vreg.schema.rschema(self.rtype)
       
   673         if not (rschema.has_perm(req, self.action)
       
   674                 or rschema.has_local_role(self.action)):
       
   675             return 0
       
   676         if self.action != 'read':
       
   677             if not (rschema.has_perm(req, 'read')
       
   678                     or rschema.has_local_role('read')):
       
   679                 return 0
       
   680         score = super(relation_possible, self).__call__(cls, req, *args, **kwargs)
       
   681         return score
       
   682 
       
   683     def score_class(self, eclass, req):
   670     def score_class(self, eclass, req):
   684         eschema = eclass.e_schema
   671         eschema = eclass.e_schema
   685         try:
   672         try:
   686             if self.role == 'object':
   673             if self.role == 'object':
   687                 rschema = eschema.objrels[self.rtype]
   674                 rschema = eschema.objrels[self.rtype]
   689                 rschema = eschema.subjrels[self.rtype]
   676                 rschema = eschema.subjrels[self.rtype]
   690         except KeyError:
   677         except KeyError:
   691             return 0
   678             return 0
   692         if self.target_etype is not None:
   679         if self.target_etype is not None:
   693             try:
   680             try:
   694                 if self.role == 'subject':
   681                 rdef = rschema.role_rdef(eschema, self.target_etype, self.role)
   695                     return int(self.target_etype in rschema.objects(eschema))
   682                 if not rdef.may_have_permission(self.action, req):
   696                 else:
   683                     return 0
   697                     return int(self.target_etype in rschema.subjects(eschema))
       
   698             except KeyError:
   684             except KeyError:
   699                 return 0
   685                 return 0
       
   686         else:
       
   687             return rschema.may_have_permission(self.action, req, eschema, self.role)
   700         return 1
   688         return 1
   701 
   689 
   702 
   690 
   703 class partial_relation_possible(PartialSelectorMixIn, relation_possible):
   691 class partial_relation_possible(PartialSelectorMixIn, relation_possible):
   704     """partial version of the relation_possible selector
   692     """partial version of the relation_possible selector