632 :param rtype: a relation type (`basestring`) |
632 :param rtype: a relation type (`basestring`) |
633 :param role: the role of the result set entity in the relation. 'subject' or |
633 :param role: the role of the result set entity in the relation. 'subject' or |
634 'object', default to 'subject'. |
634 'object', default to 'subject'. |
635 """ |
635 """ |
636 |
636 |
637 def __init__(self, rtype, role='subject'): |
637 def __init__(self, rtype, role='subject', once_is_enough=False): |
|
638 super(may_add_relation, self).__init__(once_is_enough) |
638 self.rtype = rtype |
639 self.rtype = rtype |
639 self.role = role |
640 self.role = role |
640 |
641 |
641 def score_entity(self, entity): |
642 def score_entity(self, entity): |
642 rschema = entity.schema.rschema(self.rtype) |
643 rschema = entity.schema.rschema(self.rtype) |
661 :param target_type: if specified, check the relation's end may be of this |
662 :param target_type: if specified, check the relation's end may be of this |
662 target type (`basestring`) |
663 target type (`basestring`) |
663 """ |
664 """ |
664 def __init__(self, rtype, role='subject', target_etype=None, |
665 def __init__(self, rtype, role='subject', target_etype=None, |
665 once_is_enough=False): |
666 once_is_enough=False): |
|
667 super(has_related_entities, self).__init__(once_is_enough) |
666 self.rtype = rtype |
668 self.rtype = rtype |
667 self.role = role |
669 self.role = role |
668 self.target_etype = target_etype |
670 self.target_etype = target_etype |
669 self.once_is_enough = once_is_enough |
|
670 |
671 |
671 def score_entity(self, entity): |
672 def score_entity(self, entity): |
672 rset = entity.related(self.rtype, self.role) |
673 rset = entity.related(self.rtype, self.role) |
673 if self.target_etype: |
674 if self.target_etype: |
674 return any(x for x, in rset.description if x == self.target_etype) |
675 return any(x for x, in rset.description if x == self.target_etype) |
687 note: None values (resulting from some outer join in the query) are not |
688 note: None values (resulting from some outer join in the query) are not |
688 considered. |
689 considered. |
689 |
690 |
690 :param action: an entity schema action (eg 'read'/'add'/'delete'/'update') |
691 :param action: an entity schema action (eg 'read'/'add'/'delete'/'update') |
691 """ |
692 """ |
692 def __init__(self, action): |
693 def __init__(self, action, once_is_enough=False): |
|
694 super(has_permission, self).__init__(once_is_enough) |
693 self.action = action |
695 self.action = action |
694 |
696 |
695 @lltrace |
697 @lltrace |
696 def __call__(self, cls, req, rset, row=None, col=0, **kwargs): |
698 def __call__(self, cls, req, rset, row=None, col=0, **kwargs): |
697 user = req.user |
699 user = req.user |
780 See `EntitySelector` documentation for behaviour when row is not specified. |
782 See `EntitySelector` documentation for behaviour when row is not specified. |
781 |
783 |
782 :param *etypes: entity types (`basestring`) which should be refused |
784 :param *etypes: entity types (`basestring`) which should be refused |
783 """ |
785 """ |
784 def __init__(self, *etypes): |
786 def __init__(self, *etypes): |
|
787 super(but_etype, self).__init__() |
785 self.but_etypes = etypes |
788 self.but_etypes = etypes |
786 |
789 |
787 def score(self, req, rset, row, col): |
790 def score(self, req, rset, row, col): |
788 if rset.description[row][col] in self.but_etypes: |
791 if rset.description[row][col] in self.but_etypes: |
789 return 0 |
792 return 0 |