Avoid crash when user has no write permission, in which case no ref_form will be found
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 21 Oct 2016 17:33:20 +0200
changeset 1948 52a312af8f19
parent 1947 bc3703b8278f
child 1949 c61b45994daa
Avoid crash when user has no write permission, in which case no ref_form will be found
views/archiveunit.py
--- a/views/archiveunit.py	Fri Oct 21 12:04:59 2016 +0200
+++ b/views/archiveunit.py	Fri Oct 21 17:33:20 2016 +0200
@@ -543,11 +543,13 @@
 
     def inlined_form_views(self):
         views = super(DataObjectSimplifiedAutomaticEntityForm, self).inlined_form_views()
-        ref_form = [v.form for v in views if v.rtype == 'seda_data_object_reference_id'][0]
-        if not ref_form.edited_entity.has_eid() and not ref_form.posting:
-            ref_form.add_hidden(name='seda_data_object_reference', eidparam=True,
-                                role='subject',
-                                value=self._cw.form['referenced_by'])
+        ref_forms = [v.form for v in views if v.rtype == 'seda_data_object_reference_id']
+        if ref_forms:  # may be empty if user has no write access
+            ref_form = ref_forms[0]
+            if not ref_form.edited_entity.has_eid() and not ref_form.posting:
+                ref_form.add_hidden(name='seda_data_object_reference', eidparam=True,
+                                    role='subject',
+                                    value=self._cw.form['referenced_by'])
         return views