Changed ZMI permissions
authorThierry Florac <thierry.florac@onf.fr>
Wed, 12 Jul 2017 12:24:05 +0200
changeset 40 71ff4ade6995
parent 39 f0ef959855e7
child 41 00358b9d4dad
Changed ZMI permissions
src/pyams_portal/zmi/container.py
src/pyams_portal/zmi/layout.py
src/pyams_portal/zmi/page.py
src/pyams_portal/zmi/portlet.py
--- a/src/pyams_portal/zmi/container.py	Wed Jul 12 12:23:32 2017 +0200
+++ b/src/pyams_portal/zmi/container.py	Wed Jul 12 12:24:05 2017 +0200
@@ -22,7 +22,6 @@
 from pyams_skin.interfaces import IInnerPage, IPageHeader
 from pyams_skin.interfaces.container import ITable, ITableElementEditor
 from pyams_skin.layer import IPyAMSLayer
-from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION, MANAGE_SYSTEM_PERMISSION
 from pyams_zmi.interfaces.menu import IControlPanelMenu
 from pyams_zmi.layer import IAdminLayer
 from z3c.table.interfaces import IColumn, IValues
@@ -69,7 +68,7 @@
 
 
 @viewlet_config(name='portal-templates.menu', context=ISite, layer=IAdminLayer, manager=IControlPanelMenu,
-                permission=VIEW_SYSTEM_PERMISSION, weight=20)
+                permission=MANAGE_TEMPLATE_PERMISSION, weight=20)
 @viewletmanager_config(name='portal-templates.menu', context=ISite, layer=IAdminLayer)
 @implementer(IPortalTemplateContainerMenu)
 class PortalTemplateContainerMenuItem(MenuItem):
@@ -140,7 +139,7 @@
         return ()
 
 
-@pagelet_config(name='portal-templates.html', context=ISite, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
+@pagelet_config(name='portal-templates.html', context=ISite, layer=IPyAMSLayer, permission=MANAGE_TEMPLATE_PERMISSION)
 @implementer(IInnerPage)
 class PortalTemplateContainerView(AdminView, ContainerView):
     """Portal template container view"""
@@ -163,7 +162,7 @@
 #
 
 @viewlet_config(name='templates-container-configuration.menu', context=ISite, layer=IAdminLayer,
-                manager=IPortalTemplateContainerMenu, permission=VIEW_SYSTEM_PERMISSION, weight=1)
+                manager=IPortalTemplateContainerMenu, permission=MANAGE_TEMPLATE_PERMISSION, weight=1)
 class PortalTemplatesContainerPropertiesMenu(MenuItem):
     """Portal template container configuration menu"""
 
@@ -179,7 +178,7 @@
 
 
 @pagelet_config(name='properties.html', context=IPortalTemplateContainer, layer=IPyAMSLayer,
-                permission=VIEW_SYSTEM_PERMISSION)
+                permission=MANAGE_TEMPLATE_PERMISSION)
 class PortalTemplateContainerPropertiesEditForm(AdminDialogEditForm):
     """Portal template container properties edit form"""
 
@@ -189,13 +188,13 @@
 
     fields = field.Fields(IPortalTemplateContainerConfiguration)
     ajax_handler = 'properties.json'
-    edit_permission = MANAGE_SYSTEM_PERMISSION
+    edit_permission = MANAGE_TEMPLATE_PERMISSION
 
     label_css_class = 'control-label col-md-4'
     input_css_class = 'col-md-8'
 
 
 @view_config(name='properties.json', context=IPortalTemplateContainer, request_type=IPyAMSLayer,
-             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
+             permission=MANAGE_TEMPLATE_PERMISSION, renderer='json', xhr=True)
 class PortalTemplateContainerPropertiesAJAXEditForm(AJAXEditForm, PortalTemplateContainerPropertiesEditForm):
     """Portal template container properties edit form, JSON renderer"""
--- a/src/pyams_portal/zmi/layout.py	Wed Jul 12 12:23:32 2017 +0200
+++ b/src/pyams_portal/zmi/layout.py	Wed Jul 12 12:24:05 2017 +0200
@@ -25,7 +25,6 @@
 from pyams_skin.interfaces import IInnerPage, IPageHeader
 from pyams_skin.interfaces.viewlet import IToolbarAddingMenu, IMenuHeader
 from pyams_skin.layer import IPyAMSLayer
-from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
 from pyams_zmi.interfaces.menu import IPropertiesMenu, IContentManagementMenu
 from pyams_zmi.layer import IAdminLayer
 from transaction.interfaces import ITransactionManager
@@ -69,7 +68,7 @@
 
 
 @viewlet_config(name='template-properties.menu', context=IPortalTemplate, layer=IAdminLayer,
-                manager=IContentManagementMenu, permission=VIEW_SYSTEM_PERMISSION, weight=1)
+                manager=IContentManagementMenu, permission=MANAGE_TEMPLATE_PERMISSION, weight=1)
 @viewletmanager_config(name='template-properties.menu', layer=IAdminLayer, provides=IPropertiesMenu)
 @implementer(IPropertiesMenu)
 class PortalTemplatePropertiesMenu(MenuItem):
@@ -80,7 +79,8 @@
     url = '#properties.html'
 
 
-@pagelet_config(name='properties.html', context=IPortalTemplate, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
+@pagelet_config(name='properties.html', context=IPortalTemplate, layer=IPyAMSLayer,
+                permission=MANAGE_TEMPLATE_PERMISSION)
 @template_config(template='templates/layout.pt', layer=IAdminLayer)
 @implementer(IInnerPage)
 class PortalTemplateLayoutView(AdminView):
@@ -271,7 +271,7 @@
 
 
 @view_config(name='get-slots-width.json', context=IPortalTemplate, request_type=IPyAMSLayer,
-             permission=VIEW_SYSTEM_PERMISSION, renderer='json', xhr=True)
+             permission=MANAGE_TEMPLATE_PERMISSION, renderer='json', xhr=True)
 def get_template_slots_width(request):
     """Get template slots width"""
     config = IPortalTemplateConfiguration(request.context)
@@ -290,7 +290,7 @@
 
 
 @pagelet_config(name='slot-properties.html', context=IPortalTemplate, layer=IPyAMSLayer,
-                permission=VIEW_SYSTEM_PERMISSION)
+                permission=MANAGE_TEMPLATE_PERMISSION)
 class PortalTemplateSlotPropertiesEditForm(AdminDialogEditForm):
     """Slot properties edit form"""
 
@@ -444,7 +444,7 @@
 
 
 @view_config(name='portlet-properties.html', context=IPortalTemplate, request_type=IPyAMSLayer,
-             permission=VIEW_SYSTEM_PERMISSION)
+             permission=MANAGE_TEMPLATE_PERMISSION)
 class PortalTemplatePortletEditForm(AdminDialogEditForm):
     """Portal template portlet edit form"""
 
@@ -496,7 +496,7 @@
         changes = editor()
         translate = self.request.localizer.translate
         if changed_override or changes:
-            # we commit before loading previewer to avoid BLOBs "uncommited changes" error
+            # we commit before loading previewer to avoid BLOBs "uncommitted changes" error
             ITransactionManager(self.context).commit()
             previewer = request.registry.queryMultiAdapter((self.context, request, self, portlet_config.settings),
                                                            IPortletPreviewer)
@@ -506,6 +506,7 @@
                                 'message': translate(self.successMessage),
                                 'callback': 'PyAMS_portal.template.editPortletCallback',
                                 'options': {'portlet_id': portlet_id,
+                                            'inherit_parent': portlet_config.inherit_parent,
                                             'preview': previewer.render()}})
         return changes
 
--- a/src/pyams_portal/zmi/page.py	Wed Jul 12 12:23:32 2017 +0200
+++ b/src/pyams_portal/zmi/page.py	Wed Jul 12 12:24:05 2017 +0200
@@ -17,11 +17,12 @@
 
 # import interfaces
 from pyams_form.interfaces.form import IWidgetForm, IFormHelp
-from pyams_portal.interfaces import IPortalContext, IPortalPage, IPortalTemplateConfiguration
+from pyams_portal.interfaces import IPortalContext, IPortalPage, IPortalTemplateConfiguration, \
+    MANAGE_TEMPLATE_PERMISSION
 from pyams_portal.zmi.interfaces import IPortalContextTemplatePropertiesMenu
-from pyams_skin.interfaces import IPageHeader, IInnerPage, IContentHelp
+from pyams_skin.interfaces import IPageHeader, IInnerPage
 from pyams_skin.layer import IPyAMSLayer
-from pyams_utils.interfaces import MANAGE_PERMISSION, VIEW_SYSTEM_PERMISSION
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
 from pyams_zmi.interfaces.menu import ISiteManagementMenu
 from pyams_zmi.layer import IAdminLayer
 
@@ -53,7 +54,7 @@
 #
 
 @viewlet_config(name='template-properties.menu', context=IPortalContext, layer=IAdminLayer,
-                manager=ISiteManagementMenu, permission=MANAGE_PERMISSION, weight=10)
+                manager=ISiteManagementMenu, permission=MANAGE_TEMPLATE_PERMISSION, weight=10)
 @viewletmanager_config(name='template-properties.menu', layer=IAdminLayer, context=IPortalContext,
                        provides=IPortalContextTemplatePropertiesMenu)
 @implementer(IPortalContextTemplatePropertiesMenu)
@@ -66,7 +67,7 @@
 
 
 @pagelet_config(name='template-properties.html', context=IPortalContext, layer=IPyAMSLayer,
-                permission=MANAGE_PERMISSION)
+                permission=MANAGE_TEMPLATE_PERMISSION)
 @implementer(IWidgetForm, IInnerPage)
 class PortalContextTemplatePropertiesEditForm(AdminEditForm):
     """Portal context template properties edit form"""
@@ -86,7 +87,7 @@
         return fields
 
     ajax_handler = 'template-properties.json'
-    edit_permission = MANAGE_PERMISSION
+    edit_permission = MANAGE_TEMPLATE_PERMISSION
 
     def getContent(self):
         return IPortalPage(self.context)
@@ -103,12 +104,13 @@
 
 
 @view_config(name='template-properties.json', context=IPortalContext, request_type=IPyAMSLayer,
-             permission=MANAGE_PERMISSION, renderer='json', xhr=True)
+             permission=MANAGE_TEMPLATE_PERMISSION, renderer='json', xhr=True)
 class PortalContextTemplatePropertiesAJAXEditForm(AJAXEditForm, PortalContextTemplatePropertiesEditForm):
     """Portal context template properties edit form, JSON renderer"""
 
     def get_ajax_output(self, changes):
-        if 'use_shared_template' in changes.get(IPortalPage, ()):
+        if ('inherit_parent' in changes.get(IPortalPage, ())) or \
+           ('use_shared_template' in changes.get(IPortalPage, ())):
             return {'status': 'redirect'}
         else:
             return super(PortalContextTemplatePropertiesAJAXEditForm, self).get_ajax_output(changes)
@@ -137,7 +139,7 @@
 #
 
 @viewlet_config(name='template-config.menu', context=IPortalContext, layer=IAdminLayer,
-                manager=IPortalContextTemplatePropertiesMenu, permission=MANAGE_PERMISSION, weight=50)
+                manager=IPortalContextTemplatePropertiesMenu, permission=MANAGE_TEMPLATE_PERMISSION, weight=50)
 class PortalContextTemplateConfigMenu(MenuItem):
     """Portal context template configuration menu"""
 
@@ -154,13 +156,13 @@
     def get_url(self):
         page = IPortalPage(self.context)
         if page.use_local_template:
-            return absolute_url(page.template, self.request, 'admin#properties.html')
+            return absolute_url(page.local_template, self.request, 'admin#properties.html')
         else:
             return super(PortalContextTemplateConfigMenu, self).get_url()
 
 
 @pagelet_config(name='template-config.html', context=IPortalContext, layer=IPyAMSLayer,
-                permission=MANAGE_PERMISSION)
+                permission=MANAGE_TEMPLATE_PERMISSION)
 class PortalContextTemplateLayoutView(PortalTemplateLayoutView):
     """Portal context template configuration view"""
 
@@ -171,7 +173,7 @@
     def can_change(self):
         if not IPortalPage(self.context).use_local_template:
             return False
-        return self.request.has_permission(MANAGE_PERMISSION)
+        return self.request.has_permission(MANAGE_TEMPLATE_PERMISSION)
 
 
 @adapter_config(context=(IPortalContext, IAdminLayer, PortalContextTemplateLayoutView), provides=IPageHeader)
@@ -192,12 +194,12 @@
 
 
 @view_config(name='portlet-properties.html', context=IPortalContext, request_type=IPyAMSLayer,
-             permission=MANAGE_PERMISSION)
+             permission=MANAGE_TEMPLATE_PERMISSION)
 class PortalContextTemplatePortletEditForm(PortalTemplatePortletEditForm):
     """Portal context template portlet edit form"""
 
 
 @view_config(name='portlet-properties.json', context=IPortalContext, request_type=IPyAMSLayer,
-             permission=MANAGE_PERMISSION, renderer='json', xhr=True)
+             permission=MANAGE_TEMPLATE_PERMISSION, renderer='json', xhr=True)
 class PortalContextTemplatePortletAJAXEditForm(PortalTemplatePortletAJAXEditForm):
     """Portal context template portlet edit form, JSON renderer"""
--- a/src/pyams_portal/zmi/portlet.py	Wed Jul 12 12:23:32 2017 +0200
+++ b/src/pyams_portal/zmi/portlet.py	Wed Jul 12 12:24:05 2017 +0200
@@ -59,10 +59,15 @@
     @property
     def override_label(self):
         translate = self.request.localizer.translate
-        if IPortalContext.providedBy(self.configuration.__parent__.__parent__):
-            return translate(_("Override parent settings"))
+        parent = self.configuration.__parent__
+        if IPortalTemplate.providedBy(parent):
+            return translate(_("Override template settings"))
         else:
-            return translate(_("Override template settings"))
+            page = IPortalPage(parent)
+            if page.inherit_parent:
+                return translate(_("Override parent settings"))
+            else:
+                return translate(_("Override template settings"))
 
     def get_form_action(self):
         return absolute_url(self.configuration.__parent__, self.request, self.request.view_name)
@@ -84,6 +89,8 @@
     tab_label = _("Main properties")
     legend = None
 
+    edit_permission = MANAGE_TEMPLATE_PERMISSION
+
     @property
     def fields(self):
         return field.Fields(self.parent_form.settings).omit('__name__')