Use named permissions
authorThierry Florac <thierry.florac@onf.fr>
Thu, 08 Oct 2015 09:21:58 +0200
changeset 24 0ae2f9d50bb6
parent 23 3dbc8df88f2d
child 25 1e65ba8b2bcf
Use named permissions
src/pyams_file/zmi/file.py
src/pyams_file/zmi/image.py
--- a/src/pyams_file/zmi/file.py	Tue Sep 08 17:17:08 2015 +0200
+++ b/src/pyams_file/zmi/file.py	Thu Oct 08 09:21:58 2015 +0200
@@ -19,6 +19,7 @@
 from pyams_file.interfaces import IFile, IFileInfo
 from pyams_skin.interfaces.viewlet import IContextActions
 from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.interfaces import MANAGE_PERMISSION, VIEW_PERMISSION
 
 # import packages
 from pyams_form.form import AJAXEditForm
@@ -34,7 +35,7 @@
 
 
 @viewlet_config(name='file.properties.action', context=IFile, layer=IPyAMSLayer, view=Interface,
-                manager=IContextActions, permission='view', weight=1)
+                manager=IContextActions, permission=VIEW_PERMISSION, weight=1)
 class FilePropertiesAction(ToolbarMenuItem):
     """File properties action"""
 
@@ -45,7 +46,7 @@
     modal_target = True
 
 
-@pagelet_config(name='properties.html', context=IFile, layer=IPyAMSLayer, permission='view')
+@pagelet_config(name='properties.html', context=IFile, layer=IPyAMSLayer, permission=VIEW_PERMISSION)
 class FilePropertiesEditForm(AdminDialogEditForm):
     """File properties edit form"""
 
@@ -65,7 +66,7 @@
 
 
 @view_config(name='properties.json', context=IFile, request_type=IPyAMSLayer,
-             permission='manage', renderer='json', xhr=True)
+             permission=MANAGE_PERMISSION, renderer='json', xhr=True)
 class FilePropertiesAJAXEditForm(AJAXEditForm, FilePropertiesEditForm):
     """File properties edit form, AJAX renderer"""
 
--- a/src/pyams_file/zmi/image.py	Tue Sep 08 17:17:08 2015 +0200
+++ b/src/pyams_file/zmi/image.py	Thu Oct 08 09:21:58 2015 +0200
@@ -17,18 +17,18 @@
 
 # import interfaces
 from pyams_file.interfaces import IImage, IThumnailImageWidget, IThumbnail
-from pyams_form.interfaces.form import IWidgetsPrefixViewletsManager
-from pyams_skin.interfaces import IContentHelp
+from pyams_form.interfaces.form import IWidgetsPrefixViewletsManager, IFormHelp
 from pyams_skin.interfaces.viewlet import IContextActions
 from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.interfaces import MANAGE_PERMISSION
 from pyams_zmi.layer import IAdminLayer
 
 # import packages
 from pyams_file.image import ThumbnailGeometrry
 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.viewlet.toolbar import ToolbarMenuItem, ToolbarMenuDivider
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
@@ -44,7 +44,7 @@
 
 
 @viewlet_config(name='image.resize.divider', context=IImage, layer=IPyAMSLayer, view=Interface,
-                manager=IContextActions, permission='manage', weight=19)
+                manager=IContextActions, permission=MANAGE_PERMISSION, weight=19)
 class ImageDividerAction(ToolbarMenuDivider):
     """Image divider action"""
 
@@ -54,7 +54,7 @@
 #
 
 @viewlet_config(name='image.resize.action', context=IImage, layer=IPyAMSLayer, view=Interface,
-                manager=IContextActions, permission='manage', weight=20)
+                manager=IContextActions, permission=MANAGE_PERMISSION, weight=20)
 class ImageResizeAction(ToolbarMenuItem):
     """Image resize action"""
 
@@ -104,7 +104,7 @@
     return info
 
 
-@pagelet_config(name='resize.html', context=IImage, layer=IPyAMSLayer, permission='manage')
+@pagelet_config(name='resize.html', context=IImage, layer=IPyAMSLayer, permission=MANAGE_PERMISSION)
 class ImageResizeForm(AdminDialogEditForm):
     """Image resize form"""
 
@@ -126,7 +126,7 @@
 
 
 @view_config(name='resize.json', context=IImage, request_type=IPyAMSLayer,
-             permission='manage', renderer='json', xhr=True)
+             permission=MANAGE_PERMISSION, renderer='json', xhr=True)
 class ImageResizeAJAXForm(AJAXEditForm, ImageResizeForm):
     """Image resize form, AJAX renderer"""
 
@@ -139,8 +139,8 @@
                 'smallbox_status': 'success'}
 
 
-@adapter_config(context=(IImage, IAdminLayer, ImageResizeForm), provides=IContentHelp)
-class ImageResizeFormHelpAdapter(ContentHelp):
+@adapter_config(context=(IImage, IAdminLayer, ImageResizeForm), provides=IFormHelp)
+class ImageResizeFormHelpAdapter(FormHelp):
     """Image resize form help adapter"""
 
     message = _("""You can use this form to change image dimensions.
@@ -154,7 +154,7 @@
 #
 
 @viewlet_config(name='image.crop.action', context=IImage, layer=IPyAMSLayer, view=Interface,
-                manager=IContextActions, permission='manage', weight=21)
+                manager=IContextActions, permission=MANAGE_PERMISSION, weight=21)
 class ImageCropAction(ToolbarMenuItem):
     """Image crop action"""
 
@@ -172,7 +172,7 @@
     crop = button.Button(name='crop', title=_("Crop"))
 
 
-@pagelet_config(name='crop.html', context=IImage, layer=IPyAMSLayer, permission='manage')
+@pagelet_config(name='crop.html', context=IImage, layer=IPyAMSLayer, permission=MANAGE_PERMISSION)
 class ImageCropForm(AdminDialogEditForm):
     """Image crop form"""
 
@@ -195,7 +195,7 @@
 
 
 @view_config(name='crop.json', context=IImage, request_type=IPyAMSLayer,
-             permission='manage', renderer='json', xhr=True)
+             permission=MANAGE_PERMISSION, renderer='json', xhr=True)
 class ImageCropAJAXForm(AJAXEditForm, ImageCropForm):
     """Image crop form, AJAX renderer"""
 
@@ -225,7 +225,7 @@
 #
 
 @viewlet_config(name='image.thumb.divider', context=IImage, layer=IPyAMSLayer, view=IThumnailImageWidget,
-                manager=IContextActions, permission='manage', weight=30)
+                manager=IContextActions, permission=MANAGE_PERMISSION, weight=30)
 class ImageThumbnailsDividerAction(ToolbarMenuDivider):
     """Image divider action"""
 
@@ -238,7 +238,7 @@
 
 
 @viewlet_config(name='image.thumb.square.action', context=IImage, layer=IPyAMSLayer, view=IThumnailImageWidget,
-                manager=IContextActions, permission='manage', weight=31)
+                manager=IContextActions, permission=MANAGE_PERMISSION, weight=31)
 class ImageSquareThumbnailAction(ToolbarMenuItem):
     """Square thumbnail image selection"""
 
@@ -249,7 +249,7 @@
     modal_target = True
 
 
-@pagelet_config(name='square-thumbnail.html', context=IImage, layer=IPyAMSLayer, permission='manage')
+@pagelet_config(name='square-thumbnail.html', context=IImage, layer=IPyAMSLayer, permission=MANAGE_PERMISSION)
 class ImageSquareThumbnailEditForm(AdminDialogEditForm):
     """Image square thumbnail edit form"""
 
@@ -272,7 +272,7 @@
 
 
 @view_config(name='square-thumbnail.json', context=IImage, request_type=IPyAMSLayer,
-             permission='manage', renderer='json', xhr=True)
+             permission=MANAGE_PERMISSION, renderer='json', xhr=True)
 class ImageSquareThumbnailAJAXEditForm(AJAXEditForm, ImageSquareThumbnailEditForm):
     """Image square thumbnail edit form, AJAX renderer"""
 
@@ -302,7 +302,7 @@
 #
 
 @viewlet_config(name='image.thumb.pano.action', context=IImage, layer=IAdminLayer, view=IThumnailImageWidget,
-                manager=IContextActions, permission='manage', weight=32)
+                manager=IContextActions, permission=MANAGE_PERMISSION, weight=32)
 class ImagePanoThumbnailAction(ToolbarMenuItem):
     """Panoramic thumbnail image selection"""
 
@@ -318,7 +318,7 @@
             self.actions['crop'].addClass('btn-primary')
 
 
-@pagelet_config(name='pano-thumbnail.html', context=IImage, layer=IPyAMSLayer, permission='manage')
+@pagelet_config(name='pano-thumbnail.html', context=IImage, layer=IPyAMSLayer, permission=MANAGE_PERMISSION)
 class ImagePanoThumbnailEditForm(AdminDialogEditForm):
     """Image panoramic thumbnail edit form"""
 
@@ -341,7 +341,7 @@
 
 
 @view_config(name='pano-thumbnail.json', context=IImage, request_type=IPyAMSLayer,
-             permission='manage', renderer='json', xhr=True)
+             permission=MANAGE_PERMISSION, renderer='json', xhr=True)
 class ImagePanoThumbnailAJAXEditForm(AJAXEditForm, ImagePanoThumbnailEditForm):
     """Image panoramic thumbnail edit form, AJAX renderer"""