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