Use named permissions
authorThierry Florac <thierry.florac@onf.fr>
Thu, 08 Oct 2015 09:56:56 +0200
changeset 10 40da2c735c26
parent 9 3544949bb01a
child 11 7d61342c7a59
Use named permissions
src/pyams_ldap/zmi/plugin.py
--- a/src/pyams_ldap/zmi/plugin.py	Wed Jun 17 09:57:32 2015 +0200
+++ b/src/pyams_ldap/zmi/plugin.py	Thu Oct 08 09:56:56 2015 +0200
@@ -24,6 +24,7 @@
 from pyams_skin.interfaces import IPageHeader
 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 pyams_zmi.interfaces import IAdminView
 from pyams_zmi.layer import IAdminLayer
 from z3c.form.interfaces import DISPLAY_MODE
@@ -42,7 +43,7 @@
 from pyams_skin.table import I18nColumn
 from pyams_skin.viewlet.toolbar import ToolbarMenuItem
 from pyams_template.template import template_config
-from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter
+from pyams_utils.adapter import adapter_config
 from pyams_utils.registry import query_utility
 from pyams_utils.url import absolute_url
 from pyams_viewlet.viewlet import viewlet_config, Viewlet
@@ -62,7 +63,7 @@
 
 @viewlet_config(name='add-ldap-folder.menu', context=ISite, layer=IAdminLayer,
                 view=SecurityManagerPluginsTable, manager=IToolbarAddingMenu,
-                permission='system.manage', weight=60)
+                permission=MANAGE_SYSTEM_PERMISSION, weight=60)
 class LDAPPluginAddMenu(ToolbarMenuItem):
     """LDAP users folder add menu"""
 
@@ -81,7 +82,7 @@
 #
 
 @pagelet_config(name='add-ldap-folder.html', context=ISite, layer=IPyAMSLayer,
-                permission='system.manage')
+                permission=MANAGE_SYSTEM_PERMISSION)
 @implementer(ILDAPForm)
 class LDAPPluginAddForm(AdminDialogAddForm):
     """LDAP users folder plug-in add form"""
@@ -92,7 +93,7 @@
 
     fields = field.Fields(IPlugin).omit('__name__', '__parent__')
     ajax_handler = 'add-ldap-folder.json'
-    edit_permission = 'system.manage'
+    edit_permission = MANAGE_SYSTEM_PERMISSION
 
     def create(self, data):
         return LDAPPlugin()
@@ -106,7 +107,7 @@
 
 
 @view_config(name='add-ldap-folder.json', context=ISite, request_type=IPyAMSLayer,
-             permission='system.manage', renderer='json', xhr=True)
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
 class LDAPPluginAJAXAddForm(AJAXAddForm, LDAPPluginAddForm):
     """LDAP users folder plug-in add form, AJAX handler"""
 
@@ -168,7 +169,7 @@
 #
 
 @pagelet_config(name='properties.html', context=ILDAPPlugin, layer=IPyAMSLayer,
-                permission='system.view')
+                permission=VIEW_SYSTEM_PERMISSION)
 @implementer(ILDAPForm)
 class LDAPPluginEditForm(AdminDialogEditForm):
     """LDAP users folder plug-in edit form"""
@@ -183,7 +184,7 @@
     fields = field.Fields(IPlugin).omit('__parent__', '__name__')
 
     ajax_handler = 'properties.json'
-    edit_permission = 'system.manage'
+    edit_permission = MANAGE_SYSTEM_PERMISSION
 
     def updateWidgets(self, prefix=None):
         super(LDAPPluginEditForm, self).updateWidgets()
@@ -197,7 +198,7 @@
 
 
 @view_config(name='properties.json', context=ILDAPPlugin, request_type=IPyAMSLayer,
-             permission='system.manage', renderer='json', xhr=True)
+             permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
 @implementer(IAdminView)
 class LDAPPluginAJAXEditForm(AJAXEditForm, LDAPPluginEditForm):
     """LDAP users folder plug-in edit form, AJAX handler"""
@@ -262,7 +263,7 @@
 # Users folder search views
 #
 
-@pagelet_config(name='search.html', context=ILDAPPlugin, layer=IPyAMSLayer, permission='system.view')
+@pagelet_config(name='search.html', context=ILDAPPlugin, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
 class LDAPPluginSearchView(AdminView, SearchView):
     """LDAP users folder search view"""
 
@@ -284,7 +285,7 @@
 
 
 @view_config(name='search-results.html', context=ILDAPPlugin, request_type=IPyAMSLayer,
-             permission='system.view')
+             permission=VIEW_SYSTEM_PERMISSION)
 class LDAPPluginSearchResultsView(AdminView, SearchResultsView):
     """LDAP users folder search results view table"""
 
@@ -294,10 +295,12 @@
 
     @property
     def data_attributes(self):
-        return {'tr': {'data-ams-element-name': lambda x: x[0],
-                       'data-ams-url': lambda x: '{url}?dn={dn}'.format(url=absolute_url(self.context, self.request,
-                                                                                         'user-properties.html'),
-                                                                        dn=x[0]),
+        return {'tr': {'data-ams-element-name': lambda x, col: x[0],
+                       'data-ams-url':
+                           lambda x, col: '{url}?dn={dn}'.format(url=absolute_url(self.context,
+                                                                                  self.request,
+                                                                                  'user-properties.html'),
+                                                                 dn=x[0]),
                        'data-toggle': 'modal'}}
 
     def __init__(self, context, request):