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

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Jan 27 14:50:19 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 5fd81c862498bd4b517e3b44473872ddc84b8f25
# Parent  c8692647dfc7a6b4a0f3a3028ac31f4106d4bd43
[eac] 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,6 +1,6 @@
-# copyright 2015-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2015 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
 # the terms of the GNU Lesser General Public License as published by the Free
 # Software Foundation, either version 2.1 of the License, or (at your option)
@@ -16,15 +16,17 @@
 """cubicweb-saem-ref views for import/export of AuthorityRecord from/to EAC"""
 
 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):
     """Field vocabulary function returning the list of available authorities"""
     rset = form._cw.execute('Any XN, X ORDERBY XN WHERE X is ArkNameAssigningAuthority, X who XN')
@@ -63,9 +65,22 @@ class EACImportViewNoNaa(eac.EACImportVi
                 msg += " <a href='{}'>{}</a>".format(authority.absolute_url(vid='edition'),
                                                      self._cw._('Edit authority settings'))
         self.w(tags.div(msg))
 
 
+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 be in an organization to access this functionnality.")
+        msg += " <a href='{}'>{}</a>".format(self._cw.user.absolute_url(vid='edition'),
+                                             self._cw._('Edit your settings'))
+        self.w(tags.div(msg))
+
+
 def registration_callback(vreg):
     vreg.register_all(globals().values(), __name__, (EACImportForm, EACImportView))
     vreg.register_and_replace(EACImportForm, eac.EACImportForm)
     vreg.register_and_replace(EACImportView, eac.EACImportView)


More information about the saem-devel mailing list