merge default
authorDamien Correia
Mon, 25 Jun 2018 17:05:08 +0200
changeset 750 b99892d5fa71
parent 740 d6548428279d (diff)
parent 734 ccf4175fb71f (current diff)
child 768 564d1b8aad61
merge default
--- a/src/pyams_content/component/keynumber/__init__.py	Mon Jun 25 16:53:51 2018 +0200
+++ b/src/pyams_content/component/keynumber/__init__.py	Mon Jun 25 17:05:08 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 16:53:51 2018 +0200
+++ b/src/pyams_content/component/keynumber/zmi/__init__.py	Mon Jun 25 17:05:08 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)