[web/views] avoid propagation of NoSelectableObject in some case of inlined relations / permissions
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 02 Sep 2015 15:31:18 +0200
changeset 10634 06a43f727601
parent 10633 d800ecd381f6
child 10635 2b1cb1ba8df5
[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
web/test/unittest_views_editforms.py
web/views/autoform.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):
 
--- 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 ##############################################