Use named permissions
authorThierry Florac <thierry.florac@onf.fr>
Thu, 08 Oct 2015 12:28:57 +0200
changeset 15 d1477fa29943
parent 14 61775c0158f3
child 16 bcf5683b25f5
Use named permissions
src/pyams_media/ffdocument.py
src/pyams_media/zmi/__init__.py
src/pyams_media/zmi/media.py
src/pyams_media/zmi/video.py
--- a/src/pyams_media/ffdocument.py	Wed Sep 09 11:51:38 2015 +0200
+++ b/src/pyams_media/ffdocument.py	Thu Oct 08 12:28:57 2015 +0200
@@ -40,7 +40,7 @@
                 if info:
                     self.__metadata__ = info
                 else:
-                    self.__metadata__ = []
+                    self.__metadata__ = {}
         else:
             self.__metadata__ = metadata
 
--- a/src/pyams_media/zmi/__init__.py	Wed Sep 09 11:51:38 2015 +0200
+++ b/src/pyams_media/zmi/__init__.py	Thu Oct 08 12:28:57 2015 +0200
@@ -20,6 +20,7 @@
 from pyams_media.interfaces import IMediaConversionUtility
 from pyams_skin.interfaces.viewlet import ITableItemColumnActionsMenu
 from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION, MANAGE_SYSTEM_PERMISSION
 
 # import packages
 from pyams_form.form import AJAXEditForm, AJAXAddForm, InnerEditForm
@@ -40,7 +41,8 @@
 from pyams_media import _
 
 
-@pagelet_config(name='properties.html', context=IMediaConversionUtility, layer=IPyAMSLayer, permission='system.view')
+@pagelet_config(name='properties.html', context=IMediaConversionUtility, layer=IPyAMSLayer,
+                permission=VIEW_SYSTEM_PERMISSION)
 class MediaConversionUtilityPropertiesEditForm(AdminDialogEditForm):
     """Medias conversion utility properties edit form"""
 
@@ -55,7 +57,7 @@
     input_css_class = 'col-md-8'
 
     ajax_handler = 'properties.json'
-    edit_permission = 'system.manage'
+    edit_permission = MANAGE_SYSTEM_PERMISSION
 
 
 @adapter_config(name='video-properties',
@@ -92,13 +94,13 @@
 
 
 @view_config(name='properties.json', context=IMediaConversionUtility, request_type=IPyAMSLayer,
-             permission='system.manage', renderer='json', xhr=True)
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
 class MediaConversionUtilityPropertiesAJAXEditForm(AJAXEditForm, MediaConversionUtilityPropertiesEditForm):
     """Medias conversion utility properties edit form, JSON renderer"""
 
 
 @viewlet_config(name='test-conversion-process.menu', context=IMediaConversionUtility, layer=IAdminLayer,
-                view=UtilitiesTable, manager=ITableItemColumnActionsMenu, permission='system.manage')
+                view=UtilitiesTable, manager=ITableItemColumnActionsMenu, permission=MANAGE_SYSTEM_PERMISSION)
 class MediaConversionProcessTestMenu(ToolbarMenuItem):
     """Medias conversion process test menu"""
 
@@ -117,7 +119,7 @@
 
 
 @pagelet_config(name='test-conversion-process.html', context=IMediaConversionUtility, layer=IPyAMSLayer,
-                permission='system.manage')
+                permission=MANAGE_SYSTEM_PERMISSION)
 class MediaConversionProcessTestForm(AdminDialogAddForm):
     """Medias conversion process test form"""
 
@@ -132,7 +134,7 @@
     fields = field.Fields(Interface)
     buttons = button.Buttons(IMediaConversionProcessTestButtons)
     ajax_handler = 'test-conversion-process.json'
-    edit_permission = 'system.manage'
+    edit_permission = MANAGE_SYSTEM_PERMISSION
 
     @property
     def form_target(self):
@@ -155,7 +157,7 @@
 
 
 @view_config(name='test-conversion-process.json', context=IMediaConversionUtility, request_type=IPyAMSLayer,
-             permission='system.manage', renderer='json', xhr=True)
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
 class MediaConversionProcessAJAXTestForm(AJAXAddForm, MediaConversionProcessTestForm):
     """Medias conversion process test form, JSON renderer"""
 
--- a/src/pyams_media/zmi/media.py	Wed Sep 09 11:51:38 2015 +0200
+++ b/src/pyams_media/zmi/media.py	Thu Oct 08 12:28:57 2015 +0200
@@ -9,21 +9,6 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from pyams_file.interfaces import IMediaFile, IVideo, IThumbnail, IAudio
-from pyams_form.interfaces.form import IWidgetsPrefixViewletsManager
-from pyams_media.ffbase import FFmpeg
-from pyams_media.ffdocument import FFDocument
-from pyams_media.interfaces import IMediaConversionUtility, VIDEO_FRAME_SIZE, IMediaConverter, IMediaConversions
-from pyams_pagelet.pagelet import pagelet_config
-from pyams_skin.interfaces.viewlet import IContextActions
-from pyams_skin.layer import IPyAMSLayer
-from pyams_skin.viewlet.toolbar import ToolbarMenuItem
-from pyams_template.template import template_config
-from pyams_utils.property import cached_property
-from pyams_utils.registry import query_utility
-from pyams_viewlet.viewlet import viewlet_config, Viewlet
-from pyams_zmi.form import AdminDialogDisplayForm
-from pyams_zmi.layer import IAdminLayer
 
 __docformat__ = 'restructuredtext'
 
@@ -31,8 +16,21 @@
 # import standard library
 
 # import interfaces
+from pyams_file.interfaces import IVideo, IThumbnail, IAudio
+from pyams_form.interfaces.form import IWidgetsPrefixViewletsManager
+from pyams_media.interfaces import IMediaConversionUtility, VIDEO_FRAME_SIZE, IMediaConverter, IMediaConversions
+from pyams_skin.interfaces.viewlet import IContextActions
+from pyams_skin.layer import IPyAMSLayer
+from pyams_zmi.layer import IAdminLayer
 
 # import packages
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_skin.viewlet.toolbar import ToolbarMenuItem
+from pyams_template.template import template_config
+from pyams_utils.interfaces import MANAGE_PERMISSION
+from pyams_utils.registry import query_utility
+from pyams_viewlet.viewlet import viewlet_config, Viewlet
+from pyams_zmi.form import AdminDialogDisplayForm
 from z3c.form import field
 from zope.interface import Interface
 
@@ -44,7 +42,7 @@
 #
 
 @viewlet_config(name='video.conversions.action', context=IVideo, layer=IPyAMSLayer, view=Interface,
-                manager=IContextActions, permission='manage', weight=15)
+                manager=IContextActions, permission=MANAGE_PERMISSION, weight=15)
 class VideoConversionsAction(ToolbarMenuItem):
     """Video conversions action"""
 
@@ -55,7 +53,7 @@
     modal_target = True
 
 
-@pagelet_config(name='video-conversions.html', context=IVideo, layer=IPyAMSLayer, permission='manage')
+@pagelet_config(name='video-conversions.html', context=IVideo, layer=IPyAMSLayer, permission=MANAGE_PERMISSION)
 class VideoConversionsDisplayForm(AdminDialogDisplayForm):
     """Video conversions display form"""
 
@@ -107,7 +105,7 @@
 #
 
 @viewlet_config(name='audio.conversions.action', context=IAudio, layer=IPyAMSLayer, view=Interface,
-                manager=IContextActions, permission='manage', weight=15)
+                manager=IContextActions, permission=MANAGE_PERMISSION, weight=15)
 class AudioConversionsAction(ToolbarMenuItem):
     """Audio conversions action"""
 
@@ -118,7 +116,7 @@
     modal_target = True
 
 
-@pagelet_config(name='audio-conversions.html', context=IAudio, layer=IPyAMSLayer, permission='manage')
+@pagelet_config(name='audio-conversions.html', context=IAudio, layer=IPyAMSLayer, permission=MANAGE_PERMISSION)
 class AudioConversionsDisplayForm(AdminDialogDisplayForm):
     """Audio conversions display form"""
 
--- a/src/pyams_media/zmi/video.py	Wed Sep 09 11:51:38 2015 +0200
+++ b/src/pyams_media/zmi/video.py	Thu Oct 08 12:28:57 2015 +0200
@@ -9,12 +9,6 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from pyams_form.interfaces.form import IWidgetsPrefixViewletsManager
-from pyams_skin.help import ContentHelp
-from pyams_skin.interfaces import IContentHelp
-from pyams_template.template import template_config
-from pyams_utils.adapter import adapter_config
-from pyams_zmi.layer import IAdminLayer
 
 __docformat__ = 'restructuredtext'
 
@@ -24,15 +18,21 @@
 
 # import interfaces
 from pyams_file.interfaces import IVideo, IThumbnail
+from pyams_form.interfaces.form import IWidgetsPrefixViewletsManager, IFormHelp
 from pyams_skin.interfaces.viewlet import IContextActions
+from pyams_utils.interfaces import MANAGE_PERMISSION
+from pyams_zmi.layer import IAdminLayer
 from z3c.form.interfaces import HIDDEN_MODE
 
 # import packages
 from pyams_form.form import AJAXAddForm
+from pyams_form.help import FormHelp
 from pyams_form.schema import CloseButton
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_skin.layer import IPyAMSLayer
 from pyams_skin.viewlet.toolbar import ToolbarMenuDivider, ToolbarMenuItem
+from pyams_template.template import template_config
+from pyams_utils.adapter import adapter_config
 from pyams_utils.schema import DottedDecimalField
 from pyams_viewlet.viewlet import viewlet_config, Viewlet
 from pyams_zmi.form import AdminDialogAddForm
@@ -44,7 +44,7 @@
 
 
 @viewlet_config(name='video.thumbnail.divider', context=IVideo, layer=IPyAMSLayer, view=Interface,
-                manager=IContextActions, permission='manage', weight=19)
+                manager=IContextActions, permission=MANAGE_PERMISSION, weight=19)
 class VideoDividerAction(ToolbarMenuDivider):
     """Video divider action"""
 
@@ -54,7 +54,7 @@
 #
 
 @viewlet_config(name='video.thumbnail.action', context=IVideo, layer=IPyAMSLayer, view=Interface,
-                manager=IContextActions, permission='manage', weight=20)
+                manager=IContextActions, permission=MANAGE_PERMISSION, weight=20)
 class VideoThumbnailAction(ToolbarMenuItem):
     """Video thumbnail selection action"""
 
@@ -80,7 +80,7 @@
                               default=Decimal(5))
 
 
-@pagelet_config(name='video-thumbnail.html', context=IVideo, layer=IPyAMSLayer, permission='manage')
+@pagelet_config(name='video-thumbnail.html', context=IVideo, layer=IPyAMSLayer, permission=MANAGE_PERMISSION)
 class VideoThumbnailEditForm(AdminDialogAddForm):
     """Video thumbnail selection form"""
 
@@ -116,7 +116,7 @@
 
 
 @view_config(name='video-thumbnail.json', context=IVideo, request_type=IPyAMSLayer,
-             permission='manage', renderer='json', xhr=True)
+             permission=MANAGE_PERMISSION, renderer='json', xhr=True)
 class VideoThumbnailAJAXEditForm(AJAXAddForm, VideoThumbnailEditForm):
     """Video thumbnail selection form, JSON renderer"""
 
@@ -137,8 +137,8 @@
     """Video thumbnail edit form viewlets prefix"""
 
 
-@adapter_config(context=(IVideo, IAdminLayer, VideoThumbnailEditForm), provides=IContentHelp)
-class VideoThumbnailEditFormHelpAdapter(ContentHelp):
+@adapter_config(context=(IVideo, IAdminLayer, VideoThumbnailEditForm), provides=IFormHelp)
+class VideoThumbnailEditFormHelpAdapter(FormHelp):
     """Video thumbnail selection form help adapter"""
 
     message = _("""You can play the video until you display the image you want.