selectors.py
branchtls-sprint
changeset 1715 cba9f175da2d
parent 1694 d7990e3478b2
child 1784 f0fb914e57db
equal deleted inserted replaced
1714:a721966779be 1715:cba9f175da2d
    49 from logilab.common.deprecation import deprecated_function
    49 from logilab.common.deprecation import deprecated_function
    50 from logilab.common.interface import implements as implements_iface
    50 from logilab.common.interface import implements as implements_iface
    51 
    51 
    52 from yams import BASE_TYPES
    52 from yams import BASE_TYPES
    53 
    53 
    54 from cubicweb import Unauthorized, NoSelectableObject, NotAnEntity, role
    54 from cubicweb import (Unauthorized, NoSelectableObject, NotAnEntity,
       
    55                       role, typed_eid)
    55 from cubicweb.vregistry import (NoSelectableObject, Selector,
    56 from cubicweb.vregistry import (NoSelectableObject, Selector,
    56                                 chainall, objectify_selector)
    57                                 chainall, objectify_selector)
    57 from cubicweb.cwconfig import CubicWebConfiguration
    58 from cubicweb.cwconfig import CubicWebConfiguration
    58 from cubicweb.schema import split_expression
    59 from cubicweb.schema import split_expression
    59 
    60 
   525                     return 0
   526                     return 0
   526                 score = 1
   527                 score = 1
   527             else:
   528             else:
   528                 score = all(user.owns(r[col]) for r in rset)
   529                 score = all(user.owns(r[col]) for r in rset)
   529         return score
   530         return score
       
   531 
       
   532 
       
   533 class match_transition(match_search_state):
       
   534     @lltrace
       
   535     def __call__(self, cls, req, rset=None, row=None, col=0, **kwargs):
       
   536         try:
       
   537             trname = req.execute('Any XN WHERE X is Transition, X eid %(x)s, X name XN',
       
   538                                  {'x': typed_eid(req.form['treid'])})[0][0]
       
   539         except (KeyError, IndexError):
       
   540             return 0
       
   541         # XXX check this is a transition that apply to the object?
       
   542         if not trname in self.expected:
       
   543             return 0
       
   544         return 1
   530 
   545 
   531 
   546 
   532 class match_view(match_search_state):
   547 class match_view(match_search_state):
   533     """accept if the current view is in one of the expected vid given to the
   548     """accept if the current view is in one of the expected vid given to the
   534     initializer
   549     initializer
  1094 @unbind_method
  1109 @unbind_method
  1095 def accepts_compat(registered):
  1110 def accepts_compat(registered):
  1096     def plug_selector(cls, vreg):
  1111     def plug_selector(cls, vreg):
  1097         cls = registered(cls, vreg)
  1112         cls = registered(cls, vreg)
  1098         if getattr(cls, 'accepts', None):
  1113         if getattr(cls, 'accepts', None):
  1099             warn('use "implements("EntityType", IFace)" instead of using accepts',
  1114             warn('use "implements("EntityType", IFace)" instead of using accepts on %s'
       
  1115                  % cls,
  1100                  DeprecationWarning)
  1116                  DeprecationWarning)
  1101             cls.__select__ &= implements(*cls.accepts)
  1117             cls.__select__ &= implements(*cls.accepts)
  1102         return cls
  1118         return cls
  1103     return plug_selector
  1119     return plug_selector
  1104 
  1120