Updated permission checker for keynumber forms
authorDamien Correia
Mon, 25 Jun 2018 16:03:54 +0200
changeset 737 7482facfce2d
parent 736 4eed94fdf7c3
child 738 046189ebbbd0
Updated permission checker for keynumber forms
src/pyams_content/component/keynumber/__init__.py
src/pyams_content/component/keynumber/zmi/__init__.py
--- a/src/pyams_content/component/keynumber/__init__.py	Mon Jun 25 10:09:38 2018 +0200
+++ b/src/pyams_content/component/keynumber/__init__.py	Mon Jun 25 16:03:54 2018 +0200
@@ -10,7 +10,6 @@
 # FOR A PARTICULAR PURPOSE.
 #
 
-
 __docformat__ = 'restructuredtext'
 
 
@@ -157,6 +156,16 @@
                                   name='++keynumbers++')
 
 
+@adapter_config(context=IKeyNumberContainer, provides=IFormContextPermissionChecker)
+class KeyNumberContainerPermissionChecker(ContextAdapter):
+    """Key number container permission checker"""
+
+    @property
+    def edit_permission(self):
+        content = get_parent(self.context, IKeyNumberContainerTarget)
+        return IFormContextPermissionChecker(content).edit_permission
+
+
 @adapter_config(name='keynumbers', context=IKeyNumberContainerTarget, provides=ITraversable)
 class KeyNumberContainerNamespace(ContextAdapter):
     """Key numbers container ++keynumbers++ namespace"""
--- a/src/pyams_content/component/keynumber/zmi/__init__.py	Mon Jun 25 10:09:38 2018 +0200
+++ b/src/pyams_content/component/keynumber/zmi/__init__.py	Mon Jun 25 16:03:54 2018 +0200
@@ -210,8 +210,8 @@
 #
 
 @viewlet_config(name='add-keynumber.action', context=IKeyNumberContainerTarget, layer=IPyAMSLayer, view=IKeyNumbersView,
-                manager=IWidgetTitleViewletManager, permission=MANAGE_CONTENT_PERMISSION, weight=1)
-class KeyNumberAddAction(ToolbarAction):
+                manager=IWidgetTitleViewletManager, weight=1)
+class KeyNumberAddAction(ProtectedFormObjectMixin, ToolbarAction):
     """Key number add action"""
 
     label = _("Add keynumber")
@@ -220,8 +220,7 @@
     modal_target = True
 
 
-@pagelet_config(name='add-keynumber.html', context=IKeyNumberContainer, layer=IPyAMSLayer,
-                permission=MANAGE_CONTENT_PERMISSION)
+@pagelet_config(name='add-keynumber.html', context=IKeyNumberContainer, layer=IPyAMSLayer)
 @ajax_config(name='add-keynumber.json', context=IKeyNumberContainer, layer=IPyAMSLayer,
              base=AJAXAddForm)
 class KeyNumberAddForm(AdminDialogAddForm):
@@ -231,7 +230,7 @@
     icon_css_class = 'fa fa-fw fa-dashboard'
 
     fields = field.Fields(IKeyNumber).omit('__parent__', '__name__', 'visible')
-    edit_permission = MANAGE_CONTENT_PERMISSION
+    edit_permission = None  # use context permission checker
 
     def create(self, data):
         return KeyNumber()
@@ -249,7 +248,7 @@
         }
 
 
-@pagelet_config(name='properties.html', context=IKeyNumber, layer=IPyAMSLayer, permission=MANAGE_CONTENT_PERMISSION)
+@pagelet_config(name='properties.html', context=IKeyNumber, layer=IPyAMSLayer)
 @ajax_config(name='properties.json', context=IKeyNumber, layer=IPyAMSLayer)
 class KeyNumberPropertiesEditForm(AdminDialogEditForm):
     """Key number properties edit form"""
@@ -260,7 +259,7 @@
     icon_css_class = 'fa fa-fw fa-dashboard'
 
     fields = field.Fields(IKeyNumber).omit('__parent__', '__name__', 'visible')
-    edit_permission = MANAGE_CONTENT_PERMISSION
+    edit_permission = None  # use context permission checker
 
     def get_ajax_output(self, changes):
         output = super(self.__class__, self).get_ajax_output(changes)