Ensure security management action has a consistent selector with the security view
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 22 Feb 2017 22:24:51 +0100
changeset 135 4d836625fe3f
parent 134 a3d5446bb9ee
child 136 44f2f21e5e96
Ensure security management action has a consistent selector with the security view
views/management.py
--- a/views/management.py	Wed Feb 22 21:41:27 2017 +0100
+++ b/views/management.py	Wed Feb 22 22:24:51 2017 +0100
@@ -16,18 +16,18 @@
 
 from logilab.mtconverter import xml_escape
 
-from cubicweb.predicates import relation_possible
-from cubicweb.web import formwidgets
+from cubicweb.predicates import relation_possible, one_line_rset, non_final_entity
+from cubicweb.web import action, formwidgets
 from cubicweb.web.formfields import guess_field
-from cubicweb.web.views.management import SecurityManagementView
+from cubicweb.web.views import actions, management
 
 from cubes.relationwidget.views import RelationFacetWidget
 
 
-class SherpaSecurityManagementView(SecurityManagementView):
+class SherpaSecurityManagementView(management.SecurityManagementView):
     """Security view overriden to hide permissions definitions and using a
     RelationFacetWidget to edit owner"""
-    __select__ = (SecurityManagementView.__select__ &
+    __select__ = (management.SecurityManagementView.__select__ &
                   relation_possible('owned_by', action='add'))
 
     def entity_call(self, entity):
@@ -53,6 +53,11 @@
         form.render(w=w, display_progress_div=False)
 
 
+actions.ManagePermissionsAction.__select__ = (
+    action.Action.__select__ & one_line_rset() & non_final_entity()
+    & relation_possible('owned_by', action='add'))
+
+
 def registration_callback(vreg):
     vreg.register_all(globals().values(), __name__)
-    vreg.unregister(SecurityManagementView)
+    vreg.unregister(management.SecurityManagementView)