# HG changeset patch # User Sylvain Thénault # Date 1441200678 -7200 # Node ID 06a43f727601d01e7c9e7668ae2644ed5644db3e # Parent d800ecd381f6411e0f3a6aa1c5c50897317adf78 [web/views] avoid propagation of NoSelectableObject in some case of inlined relations / permissions When selecting an inlined creation form, we should catch the NoSelectable exception that will be raised if the user cannot add entities of the target type (this is not and cannot be verified earlier) or if some other custom selector prevents the form from being selected. Closes #6510921 diff -r d800ecd381f6 -r 06a43f727601 web/test/unittest_views_editforms.py --- a/web/test/unittest_views_editforms.py Wed Oct 07 17:27:35 2015 +0200 +++ b/web/test/unittest_views_editforms.py Wed Sep 02 15:31:18 2015 +0200 @@ -173,6 +173,12 @@ [rschema.type for rschema, _ in mform.editable_attributes()]) + def test_inlined_relations(self): + with self.admin_access.web_request() as req: + with self.temporary_permissions(EmailAddress={'add': ()}): + autoform = self.vreg['forms'].select('edition', req, entity=req.user) + self.assertEqual(list(autoform.inlined_form_views()), []) + class FormViewsTC(CubicWebTC): diff -r d800ecd381f6 -r 06a43f727601 web/views/autoform.py --- a/web/views/autoform.py Wed Oct 07 17:27:35 2015 +0200 +++ b/web/views/autoform.py Wed Sep 02 15:31:18 2015 +0200 @@ -126,6 +126,7 @@ from logilab.mtconverter import xml_escape from logilab.common.decorators import iclassmethod, cached from logilab.common.deprecation import deprecated +from logilab.common.registry import NoSelectableObject from cubicweb import neg_role, uilib from cubicweb.schema import display_name @@ -992,11 +993,16 @@ """yield inline form views to a newly related (hence created) entity through the given relation """ - yield self._cw.vreg['views'].select('inline-creation', self._cw, - etype=ttype, rtype=rschema, role=role, - peid=self.edited_entity.eid, - petype=self.edited_entity.e_schema, - pform=self) + try: + yield self._cw.vreg['views'].select('inline-creation', self._cw, + etype=ttype, rtype=rschema, role=role, + peid=self.edited_entity.eid, + petype=self.edited_entity.e_schema, + pform=self) + except NoSelectableObject: + # may be raised if user doesn't have the permission to add ttype entities (no checked + # earlier) or if there is some custom selector on the view + pass ## default form ui configuration ##############################################