Use named permissions
authorThierry Florac <thierry.florac@onf.fr>
Thu, 08 Oct 2015 11:31:03 +0200
changeset 22 b1a1ccc1fa26
parent 21 8b3250991530
child 23 a94173c4f60f
Use named permissions
src/pyams_scheduler/zmi/scheduler.py
src/pyams_scheduler/zmi/ssh.py
src/pyams_scheduler/zmi/task.py
src/pyams_scheduler/zmi/url.py
src/pyams_scheduler/zmi/zodb.py
--- a/src/pyams_scheduler/zmi/scheduler.py	Thu Oct 08 11:12:35 2015 +0200
+++ b/src/pyams_scheduler/zmi/scheduler.py	Thu Oct 08 11:31:03 2015 +0200
@@ -26,6 +26,7 @@
 from pyams_skin.interfaces import IInnerPage, IPageHeader
 from pyams_skin.interfaces.container import 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
@@ -72,7 +73,7 @@
 
 
 @viewlet_config(name='scheduler.menu', context=ISite, layer=IAdminLayer, manager=IControlPanelMenu,
-                permission='system.view', weight=10)
+                permission=VIEW_SYSTEM_PERMISSION, weight=10)
 @viewletmanager_config(name='scheduler.menu', context=ISite, layer=IAdminLayer)
 @implementer(ISchedulerMenu)
 class SchedulerMenuItem(MenuItem):
@@ -120,7 +121,7 @@
     target = None
     modal_target = True
 
-    permission = 'system.view'
+    permission = VIEW_SYSTEM_PERMISSION
     weight = 1
 
 
@@ -134,7 +135,7 @@
     target = None
     modal_target = True
 
-    permission = 'system.view'
+    permission = VIEW_SYSTEM_PERMISSION
     weight = 2
 
 
@@ -157,7 +158,7 @@
     target = None
     modal_target = True
 
-    permission = 'system.manage'
+    permission = MANAGE_SYSTEM_PERMISSION
     weight = 20
 
 
@@ -171,7 +172,7 @@
     target = None
     modal_target = True
 
-    permission = 'system.view'
+    permission = VIEW_SYSTEM_PERMISSION
     weight = 30
 
 
@@ -180,11 +181,11 @@
     """Scheduler tasks trash column"""
 
     icon_hint = _("Delete task")
-    permission = 'system.manage'
+    permission = MANAGE_SYSTEM_PERMISSION
 
 
 @view_config(name='delete-task.json', context=IScheduler, request_type=IPyAMSLayer,
-             permission='system.manage', renderer='json', xhr=True)
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
 def delete_scheduler_task(request):
     """Delete task from scheduler utility"""
     translate = request.localizer.translate
@@ -213,7 +214,7 @@
         return ()
 
 
-@pagelet_config(name='scheduler-tasks.html', context=ISite, layer=IPyAMSLayer, permission='system.view')
+@pagelet_config(name='scheduler-tasks.html', context=ISite, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
 @implementer(IInnerPage)
 class SchedulerTasksView(AdminView, ContainerView):
     """Scheduler tasks view"""
@@ -234,7 +235,7 @@
 
 
 @viewlet_config(name='scheduler.properties.menu', context=ISite, layer=IAdminLayer,
-                manager=ISchedulerMenu, permission='system.view', weight=1)
+                manager=ISchedulerMenu, permission=VIEW_SYSTEM_PERMISSION, weight=1)
 class SchedulerPropertiesMenuItem(MenuItem):
     """Scheduler properties menu"""
 
@@ -247,7 +248,7 @@
         return resource_url(manager, self.request, self.url)
 
 
-@pagelet_config(name='properties.html', context=IScheduler, layer=IPyAMSLayer, permission='system.view')
+@pagelet_config(name='properties.html', context=IScheduler, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
 class SchedulerPropertiesEditForm(AdminDialogEditForm):
     """Scheduler properties edit form"""
 
@@ -259,17 +260,17 @@
 
     fields = field.Fields(IScheduler).omit('__parent__', '__name__', 'tasks', 'history')
     ajax_handler = 'properties.json'
-    edit_permission = 'system.manage'
+    edit_permission = MANAGE_SYSTEM_PERMISSION
 
 
 @view_config(name='properties.json', context=IScheduler, request_type=IPyAMSLayer,
-             permission='system.manage', renderer='json', xhr=True)
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
 class SchedulerPropertiesAJAXEditForm(AJAXEditForm, SchedulerPropertiesEditForm):
     """Scheduler properties edit form, AJAX view"""
 
 
 @viewlet_config(name='scheduler.jobs.menu', context=ISite, layer=IAdminLayer,
-                manager=ISchedulerMenu, permission='system.view', weight=5)
+                manager=ISchedulerMenu, permission=VIEW_SYSTEM_PERMISSION, weight=5)
 class SchedulerJobsMenuItem(MenuItem):
     """Scheduler jobs menu"""
 
@@ -282,7 +283,7 @@
         return resource_url(manager, self.request, self.url)
 
 
-@pagelet_config(name='jobs.html', context=IScheduler, layer=IPyAMSLayer, permission='system.view')
+@pagelet_config(name='jobs.html', context=IScheduler, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
 class SchedulerJobsDisplayForm(AdminDialogDisplayForm):
     """Scheduler jobs display form"""
 
--- a/src/pyams_scheduler/zmi/ssh.py	Thu Oct 08 11:12:35 2015 +0200
+++ b/src/pyams_scheduler/zmi/ssh.py	Thu Oct 08 11:31:03 2015 +0200
@@ -19,6 +19,7 @@
 from pyams_scheduler.interfaces.ssh import ISSHCallerTask, ISSHCallerTaskInfo
 from pyams_skin.interfaces.viewlet import IToolbarAddingMenu
 from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION, MANAGE_SYSTEM_PERMISSION
 from zope.component.interfaces import ISite
 
 # import packages
@@ -38,7 +39,7 @@
 
 @viewlet_config(name='add-scheduler-ssh-task.menu', context=ISite, layer=IPyAMSLayer,
                 view=SchedulerTasksTable, manager=IToolbarAddingMenu,
-                permission='system.manage', weight=5)
+                permission=MANAGE_SYSTEM_PERMISSION, weight=5)
 class SSHTaskAddMenu(ToolbarMenuItem):
     """SSH caller task add menu"""
 
@@ -49,7 +50,7 @@
 
 
 @pagelet_config(name='add-scheduler-ssh-task.html', context=ISite, layer=IPyAMSLayer,
-                permission='system.manage')
+                permission=MANAGE_SYSTEM_PERMISSION)
 class SSHTaskAddForm(TaskBaseAddForm):
     """SSH command task add form"""
 
@@ -61,12 +62,12 @@
 
 
 @view_config(name='add-scheduler-ssh-task.json', context=ISite, request_type=IPyAMSLayer,
-             permission='system.manage', renderer='json', xhr=True)
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
 class SSHTaskAJAXAddForm(AJAXAddForm, SSHTaskAddForm):
     """SSH command task add form, AJAX view"""
 
 
-@pagelet_config(name='settings.html', context=ISSHCallerTask, layer=IPyAMSLayer, permission='system.view')
+@pagelet_config(name='settings.html', context=ISSHCallerTask, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
 class SSHTaskEditForm(AdminDialogEditForm):
     """SSH command task edit form"""
 
@@ -82,10 +83,10 @@
 
     fields = field.Fields(ISSHCallerTaskInfo)
     ajax_handler = 'settings.json'
-    edit_permission = 'system.manage'
+    edit_permission = MANAGE_SYSTEM_PERMISSION
 
 
 @view_config(name='settings.json', context=ISSHCallerTask, request_type=IPyAMSLayer,
-             permission='system.manage', renderer='json', xhr=True)
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
 class SSHTaskAJAXEditForm(AJAXEditForm, SSHTaskEditForm):
     """SSH command task edit form, AJAX view"""
--- a/src/pyams_scheduler/zmi/task.py	Thu Oct 08 11:12:35 2015 +0200
+++ b/src/pyams_scheduler/zmi/task.py	Thu Oct 08 11:31:03 2015 +0200
@@ -16,11 +16,11 @@
 from io import StringIO
 
 # import interfaces
-from pyams_form.interfaces.form import IWidgetsSuffixViewletsManager, IWidgetsPrefixViewletsManager
+from pyams_form.interfaces.form import IWidgetsSuffixViewletsManager, IWidgetsPrefixViewletsManager, IFormHelp
 from pyams_scheduler.interfaces import ITaskInfo, IScheduler, ITask, ICronTask, ICronTaskScheduling, IDateTask, \
     IDateTaskScheduling, ILoopTask, ILoopTaskScheduling, ITaskHistory, IBaseTaskScheduling
-from pyams_skin.interfaces import IContentHelp
 from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION, MANAGE_SYSTEM_PERMISSION
 from pyams_zmi.layer import IAdminLayer
 from z3c.form.interfaces import IDataExtractedEvent, DISPLAY_MODE
 from z3c.table.interfaces import IValues, IColumn
@@ -28,9 +28,9 @@
 
 # import packages
 from pyams_form.form import AJAXEditForm
+from pyams_form.help import FormHelp
 from pyams_form.schema import CloseButton
 from pyams_pagelet.pagelet import pagelet_config
-from pyams_skin.help import ContentHelp
 from pyams_skin.table import BaseTable, I18nColumn
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config, ContextAdapter, ContextRequestViewAdapter
@@ -66,7 +66,7 @@
     input_css_class = 'col-md-8'
 
     fields = field.Fields(ITaskInfo).omit('__parent__', '__name__')
-    edit_permission = 'system.manage'
+    edit_permission = MANAGE_SYSTEM_PERMISSION
     task_factory = None
 
     def updateWidgets(self, prefix=None):
@@ -94,7 +94,7 @@
         event.form.widgets.errors += (Invalid(_("Specified task name is already used!")),)
 
 
-@pagelet_config(name='properties.html', context=ITask, layer=IPyAMSLayer, permission='system.view')
+@pagelet_config(name='properties.html', context=ITask, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
 class TaskPropertiesEditForm(AdminDialogEditForm):
     """Scheduler task properties edit form"""
 
@@ -110,7 +110,7 @@
 
     fields = field.Fields(ITaskInfo).omit('__parent__', '__name__')
     ajax_handler = 'properties.json'
-    edit_permission = 'system.manage'
+    edit_permission = MANAGE_SYSTEM_PERMISSION
 
     def updateWidgets(self, prefix=None):
         super(TaskPropertiesEditForm, self).updateWidgets(prefix)
@@ -118,7 +118,7 @@
 
 
 @view_config(name='properties.json', context=ITask, request_type=IPyAMSLayer,
-             permission='system.manage', renderer='json', xhr=True)
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
 class SchedulerTaskPropertiesAJAXEditForm(AJAXEditForm, TaskPropertiesEditForm):
     """Scheduler task properties edit form, AJAX view"""
 
@@ -137,7 +137,7 @@
     input_css_class = 'col-md-8'
 
     ajax_handler = 'schedule.json'
-    edit_permission = 'system.manage'
+    edit_permission = MANAGE_SYSTEM_PERMISSION
 
     def update_content(self, content, data):
         changes = super(TaskScheduleEditForm, self).update_content(content, data)
@@ -156,7 +156,7 @@
             return super(TaskSchedulerAJAXEditForm, self).get_ajax_output(changes)
 
 
-@pagelet_config(name='schedule.html', context=ICronTask, layer=IPyAMSLayer, permission='system.view')
+@pagelet_config(name='schedule.html', context=ICronTask, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
 class CronTaskScheduleEditForm(TaskScheduleEditForm):
     """Cron-style task schedule edit form"""
 
@@ -164,12 +164,12 @@
 
 
 @view_config(name='schedule.json', context=ICronTask, request_type=IPyAMSLayer,
-             permission='system.manage', renderer='json', xhr=True)
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
 class CronTaskScheduleAJAXEditForm(TaskSchedulerAJAXEditForm, CronTaskScheduleEditForm):
     """Cron-style task schedule edit form, AJAX view"""
 
 
-@pagelet_config(name='schedule.html', context=IDateTask, layer=IPyAMSLayer, permission='system.view')
+@pagelet_config(name='schedule.html', context=IDateTask, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
 class DateTaskScheduleEditForm(TaskScheduleEditForm):
     """Date-style task schedule edit form"""
 
@@ -177,12 +177,12 @@
 
 
 @view_config(name='schedule.json', context=IDateTask, request_type=IPyAMSLayer,
-             permission='system.manage', renderer='json', xhr=True)
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
 class DateTaskScheduleAJAXEditForm(TaskSchedulerAJAXEditForm, DateTaskScheduleEditForm):
     """Date-style task schedule edit form, AJAX view"""
 
 
-@pagelet_config(name='schedule.html', context=ILoopTask, layer=IPyAMSLayer, permission='system.view')
+@pagelet_config(name='schedule.html', context=ILoopTask, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
 class LoopTaskScheduleEditForm(TaskScheduleEditForm):
     """Loop-style task schedule edit form"""
 
@@ -190,7 +190,7 @@
 
 
 @view_config(name='schedule.json', context=ILoopTask, request_type=IPyAMSLayer,
-             permission='system.manage', renderer='json', xhr=True)
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
 class LoopTaskScheduleAJAXEditForm(TaskSchedulerAJAXEditForm, LoopTaskScheduleEditForm):
     """Loop-style task schedule edit form, AJAX view"""
 
@@ -203,7 +203,7 @@
     execute = button.Button(name='execute', title=_("Run in normal mode"))
 
 
-@pagelet_config(name='run.html', context=ITask, layer=IPyAMSLayer, permission='system.manage')
+@pagelet_config(name='run.html', context=ITask, layer=IPyAMSLayer, permission=MANAGE_SYSTEM_PERMISSION)
 class TaskRunForm(AdminDialogEditForm):
     """Task runner form"""
 
@@ -237,7 +237,7 @@
 
 
 @view_config(name='run.json', context=ITask, request_type=IPyAMSLayer,
-             permission='system.manage', renderer='json', xhr=True)
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
 class TaskRunAJAXForm(AJAXEditForm, TaskRunForm):
     """Task runner form, AJAX view"""
 
@@ -255,8 +255,8 @@
                     'close_form': False}
 
 
-@adapter_config(context=(ITask, IAdminLayer, TaskRunForm), provides=IContentHelp)
-class TaskRunFormHelpAdapter(ContentHelp):
+@adapter_config(context=(ITask, IAdminLayer, TaskRunForm), provides=IFormHelp)
+class TaskRunFormHelpAdapter(FormHelp):
     """Task run form help adapter"""
 
     status = 'warning'
@@ -279,7 +279,7 @@
     """Task debug report viewlet"""
 
 
-@pagelet_config(name='history.html', context=ITask, layer=IPyAMSLayer, permission='system.view')
+@pagelet_config(name='history.html', context=ITask, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
 class TaskHistoryDisplayForm(AdminDialogDisplayForm):
     """Task history display form"""
 
@@ -316,7 +316,7 @@
                           'data-ams-datatable-sdom': "t<'dt-row dt-bottom-row'<'text-right'p>>",
                           'data-ams-datatable-display-length': '20',
                           'data-ams-datatable-pagination-type': 'bootstrap_prevnext'},
-                'tr': {'data-ams-url': lambda x: absolute_url(x, self.request, 'info.json'),
+                'tr': {'data-ams-url': lambda x, col: absolute_url(x, self.request, 'info.json'),
                        'data-ams-target': '#task-history-report'}}
 
     def getCSSHighlightClass(self, column, item, cssClass):
@@ -363,7 +363,7 @@
 
 
 @view_config(name='info.json', context=ITaskHistory, request_type=IPyAMSLayer,
-             permission='system.view', renderer='json', xhr=True)
+             permission=VIEW_SYSTEM_PERMISSION, renderer='json', xhr=True)
 def TaskHistoryInfoView(request):
     return {'status': 'success',
             'close_form': False,
--- a/src/pyams_scheduler/zmi/url.py	Thu Oct 08 11:12:35 2015 +0200
+++ b/src/pyams_scheduler/zmi/url.py	Thu Oct 08 11:31:03 2015 +0200
@@ -19,6 +19,7 @@
 from pyams_scheduler.interfaces.url import IURLCallerTask, IURLCallerTaskInfo
 from pyams_skin.interfaces.viewlet import IToolbarAddingMenu
 from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION, MANAGE_SYSTEM_PERMISSION
 from zope.component.interfaces import ISite
 
 # import packages
@@ -38,7 +39,7 @@
 
 @viewlet_config(name='add-scheduler-url-task.menu', context=ISite, layer=IPyAMSLayer,
                 view=SchedulerTasksTable, manager=IToolbarAddingMenu,
-                permission='system.manage', weight=5)
+                permission=MANAGE_SYSTEM_PERMISSION, weight=5)
 class URLTaskAddMenu(ToolbarMenuItem):
     """URL caller task add menu"""
 
@@ -49,7 +50,7 @@
 
 
 @pagelet_config(name='add-scheduler-url-task.html', context=ISite, layer=IPyAMSLayer,
-                permission='system.manage')
+                permission=MANAGE_SYSTEM_PERMISSION)
 class URLTaskAddForm(TaskBaseAddForm):
     """URL caller task add form"""
 
@@ -61,12 +62,12 @@
 
 
 @view_config(name='add-scheduler-url-task.json', context=ISite, request_type=IPyAMSLayer,
-             permission='system.manage', renderer='json', xhr=True)
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
 class URLTaskAJAXAddForm(AJAXAddForm, URLTaskAddForm):
     """URL caller task add form, AJAX view"""
 
 
-@pagelet_config(name='settings.html', context=IURLCallerTask, layer=IPyAMSLayer, permission='system.view')
+@pagelet_config(name='settings.html', context=IURLCallerTask, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
 class URLTaskEditForm(AdminDialogEditForm):
     """URL caller task edit form"""
 
@@ -80,10 +81,10 @@
 
     fields = field.Fields(IURLCallerTaskInfo)
     ajax_handler = 'settings.json'
-    edit_permission = 'system.manage'
+    edit_permission = MANAGE_SYSTEM_PERMISSION
 
 
 @view_config(name='settings.json', context=IURLCallerTask, request_type=IPyAMSLayer,
-             permission='system.manage', renderer='json', xhr=True)
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
 class URLTaskAJAXEditForm(AJAXEditForm, URLTaskEditForm):
     """URL caller task edit form, AJAX view"""
--- a/src/pyams_scheduler/zmi/zodb.py	Thu Oct 08 11:12:35 2015 +0200
+++ b/src/pyams_scheduler/zmi/zodb.py	Thu Oct 08 11:31:03 2015 +0200
@@ -19,6 +19,7 @@
 from pyams_scheduler.interfaces.zodb import IZODBPackingTask, IZODBPackingTaskInfo
 from pyams_skin.interfaces.viewlet import IToolbarAddingMenu
 from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION, MANAGE_SYSTEM_PERMISSION
 from zope.component.interfaces import ISite
 
 # import packages
@@ -38,7 +39,7 @@
 
 @viewlet_config(name='add-scheduler-zodb-task.menu', context=ISite, layer=IPyAMSLayer,
                 view=SchedulerTasksTable, manager=IToolbarAddingMenu,
-                permission='system.manage', weight=5)
+                permission=MANAGE_SYSTEM_PERMISSION, weight=5)
 class ZODBTaskAddMenu(ToolbarMenuItem):
     """ZODB packing task add menu"""
 
@@ -49,7 +50,7 @@
 
 
 @pagelet_config(name='add-scheduler-zodb-task.html', context=ISite, layer=IPyAMSLayer,
-                permission='system.manage')
+                permission=MANAGE_SYSTEM_PERMISSION)
 class ZODBTaskAddForm(TaskBaseAddForm):
     """ZODB packing task add form"""
 
@@ -61,12 +62,12 @@
 
 
 @view_config(name='add-scheduler-zodb-task.json', context=ISite, request_type=IPyAMSLayer,
-             permission='system.manage', renderer='json', xhr=True)
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
 class ZODBTaskAJAXAddForm(AJAXAddForm, ZODBTaskAddForm):
     """ZODB packing task add form, AJAX view"""
 
 
-@pagelet_config(name='settings.html', context=IZODBPackingTask, layer=IPyAMSLayer, permission='system.view')
+@pagelet_config(name='settings.html', context=IZODBPackingTask, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
 class ZODBTaskEditForm(AdminDialogEditForm):
     """ZODB packing task edit form"""
 
@@ -80,10 +81,10 @@
 
     fields = field.Fields(IZODBPackingTaskInfo)
     ajax_handler = 'settings.json'
-    edit_permission = 'system.manage'
+    edit_permission = MANAGE_SYSTEM_PERMISSION
 
 
 @view_config(name='settings.json', context=IZODBPackingTask, request_type=IPyAMSLayer,
-             permission='system.manage', renderer='json', xhr=True)
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
 class ZODBTaskAJAXEditForm(AJAXEditForm, ZODBTaskEditForm):
     """ZODB packing task edit form, AJAX view"""