web/views/autoform.py
changeset 10651 9ca33768473c
parent 10609 e2d8e81bfe68
parent 10646 45671fb330f5
child 10663 54b8a1f249fb
equal deleted inserted replaced
10622:3cc6154b94a3 10651:9ca33768473c
   126 from six.moves import range
   126 from six.moves import range
   127 
   127 
   128 from logilab.mtconverter import xml_escape
   128 from logilab.mtconverter import xml_escape
   129 from logilab.common.decorators import iclassmethod, cached
   129 from logilab.common.decorators import iclassmethod, cached
   130 from logilab.common.deprecation import deprecated
   130 from logilab.common.deprecation import deprecated
       
   131 from logilab.common.registry import NoSelectableObject
   131 
   132 
   132 from cubicweb import neg_role, uilib
   133 from cubicweb import neg_role, uilib
   133 from cubicweb.schema import display_name
   134 from cubicweb.schema import display_name
   134 from cubicweb.view import EntityView
   135 from cubicweb.view import EntityView
   135 from cubicweb.predicates import (
   136 from cubicweb.predicates import (
   945                     rschema, role, tschema, ttype))
   946                     rschema, role, tschema, ttype))
   946 
   947 
   947     def check_inlined_rdef_permissions(self, rschema, role, tschema, ttype):
   948     def check_inlined_rdef_permissions(self, rschema, role, tschema, ttype):
   948         """return true if permissions are granted on the inlined object and
   949         """return true if permissions are granted on the inlined object and
   949         relation"""
   950         relation"""
       
   951         if not tschema.has_perm(self._cw, 'add'):
       
   952             return False
   950         entity = self.edited_entity
   953         entity = self.edited_entity
   951         rdef = entity.e_schema.rdef(rschema, role, ttype)
   954         rdef = entity.e_schema.rdef(rschema, role, ttype)
   952         if entity.has_eid():
   955         if entity.has_eid():
   953             if role == 'subject':
   956             if role == 'subject':
   954                 rdefkwargs = {'fromeid': entity.eid}
   957                 rdefkwargs = {'fromeid': entity.eid}
   955             else:
   958             else:
   956                 rdefkwargs = {'toeid': entity.eid}
   959                 rdefkwargs = {'toeid': entity.eid}
   957         else:
   960             return rdef.has_perm(self._cw, 'add', **rdefkwargs)
   958             rdefkwargs = {}
   961         return rdef.may_have_permission('add', self._cw)
   959         return (tschema.has_perm(self._cw, 'add')
       
   960                 and rdef.has_perm(self._cw, 'add', **rdefkwargs))
       
   961 
   962 
   962 
   963 
   963     def should_hide_add_new_relation_link(self, rschema, card):
   964     def should_hide_add_new_relation_link(self, rschema, card):
   964         """return true if once an inlined creation form is added, the 'add new'
   965         """return true if once an inlined creation form is added, the 'add new'
   965         link should be hidden
   966         link should be hidden
   986 
   987 
   987     def inline_creation_form_view(self, rschema, ttype, role):
   988     def inline_creation_form_view(self, rschema, ttype, role):
   988         """yield inline form views to a newly related (hence created) entity
   989         """yield inline form views to a newly related (hence created) entity
   989         through the given relation
   990         through the given relation
   990         """
   991         """
   991         yield self._cw.vreg['views'].select('inline-creation', self._cw,
   992         try:
   992                                             etype=ttype, rtype=rschema, role=role,
   993             yield self._cw.vreg['views'].select('inline-creation', self._cw,
   993                                             peid=self.edited_entity.eid,
   994                                                 etype=ttype, rtype=rschema, role=role,
   994                                             petype=self.edited_entity.e_schema,
   995                                                 peid=self.edited_entity.eid,
   995                                             pform=self)
   996                                                 petype=self.edited_entity.e_schema,
       
   997                                                 pform=self)
       
   998         except NoSelectableObject:
       
   999             # may be raised if user doesn't have the permission to add ttype entities (no checked
       
  1000             # earlier) or if there is some custom selector on the view
       
  1001             pass
   996 
  1002 
   997 
  1003 
   998 ## default form ui configuration ##############################################
  1004 ## default form ui configuration ##############################################
   999 
  1005 
  1000 _AFS = uicfg.autoform_section
  1006 _AFS = uicfg.autoform_section