[saem-devel] [PATCH 2 of 2] [eac, ui] Don't allow to create AuthorityRecord to user not in an authority

saem-devel at lists.cubicweb.org saem-devel at lists.cubicweb.org
Wed Jan 25 09:30:37 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1485266526 -3600
#      Tue Jan 24 15:02:06 2017 +0100
# Node ID f6456f405e64e855a89c8fcb9011f0cca2abd92c
# Parent  ad262c9f0fb3fabb98db9b0986eec4864babcf9b
[eac, ui] Don't allow to create AuthorityRecord to user not in an authority

rather show a message explaining the user should be updated.

Related to #12572793

diff --git a/views/eac.py b/views/eac.py
--- a/views/eac.py
+++ b/views/eac.py
@@ -1,4 +1,4 @@
-# copyright 2015-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2015-2017 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr -- mailto:contact at logilab.fr
 #
 # This program is free software: you can redistribute it and/or modify it under
@@ -18,11 +18,13 @@
 from six import text_type
 
 from cubicweb import tags
+from cubicweb.predicates import specified_etype_implements
 from cubicweb.web import formfields as ff
+from cubicweb.web.views import editforms
 
 from cubes.eac import views as eac
 
-from cubes.saem_ref import user_has_naa
+from cubes.saem_ref import user_has_naa, user_has_authority
 
 
 def naa_form_vocabulary(form, field):
@@ -62,6 +64,19 @@ class EACImportViewNoNaa(eac.EACImportVi
         self.w(tags.div(msg.format(url)))
 
 
+class EACCreationFormViewNoNaa(editforms.CreationFormView):
+    __select__ = (editforms.CreationFormView.__select__
+                  & specified_etype_implements('AuthorityRecord')
+                  & ~user_has_authority())
+
+    def render_form(self, entity):
+        self.form_title(entity)
+        msg = self._cw._("You must <a href='{0}'>be in an organization</a> to access "
+                         "this functionnality.")
+        url = self._cw.user.absolute_url(vid='edition')
+        self.w(tags.div(msg.format(url)))
+
+
 def registration_callback(vreg):
     vreg.register_all(globals().values(), __name__, (EACImportForm, EACImportView))
     vreg.register_and_replace(EACImportForm, eac.EACImportForm)


More information about the saem-devel mailing list