src/pyams_security/zmi/utility.py
changeset 54 59683c264d94
parent 49 e4fc19ce77fa
child 71 0a612729eb2f
equal deleted inserted replaced
53:68678e37a77a 54:59683c264d94
    19 from pyams_security.interfaces import ISecurityManager, IDirectorySearchPlugin
    19 from pyams_security.interfaces import ISecurityManager, IDirectorySearchPlugin
    20 from pyams_security.zmi.interfaces import ISecurityManagerMenu
    20 from pyams_security.zmi.interfaces import ISecurityManagerMenu
    21 from pyams_skin.interfaces import IInnerPage, IPageHeader
    21 from pyams_skin.interfaces import IInnerPage, IPageHeader
    22 from pyams_skin.interfaces.container import ITableElementEditor
    22 from pyams_skin.interfaces.container import ITableElementEditor
    23 from pyams_skin.layer import IPyAMSLayer
    23 from pyams_skin.layer import IPyAMSLayer
       
    24 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION, MANAGE_SYSTEM_PERMISSION
    24 from pyams_zmi.interfaces.menu import IControlPanelMenu
    25 from pyams_zmi.interfaces.menu import IControlPanelMenu
    25 from pyams_zmi.layer import IAdminLayer
    26 from pyams_zmi.layer import IAdminLayer
    26 from z3c.table.interfaces import IValues, IColumn
    27 from z3c.table.interfaces import IValues, IColumn
    27 from zope.component.interfaces import ISite
    28 from zope.component.interfaces import ISite
    28 
    29 
    65         site = get_parent(self.context, ISite)
    66         site = get_parent(self.context, ISite)
    66         return resource_url(site, self.request, 'admin.html#{0}'.format(self.view_name))
    67         return resource_url(site, self.request, 'admin.html#{0}'.format(self.view_name))
    67 
    68 
    68 
    69 
    69 @viewlet_config(name='security-manager.menu', context=ISite, layer=IAdminLayer, manager=IControlPanelMenu,
    70 @viewlet_config(name='security-manager.menu', context=ISite, layer=IAdminLayer, manager=IControlPanelMenu,
    70                 permission='system.view', weight=5)
    71                 permission=VIEW_SYSTEM_PERMISSION, weight=5)
    71 @viewletmanager_config(name='security-manager.menu', context=ISite, layer=IAdminLayer)
    72 @viewletmanager_config(name='security-manager.menu', context=ISite, layer=IAdminLayer)
    72 @implementer(ISecurityManagerMenu)
    73 @implementer(ISecurityManagerMenu)
    73 class SecurityManagerMenuItem(MenuItem):
    74 class SecurityManagerMenuItem(MenuItem):
    74     """Security manager menu"""
    75     """Security manager menu"""
    75 
    76 
   125 @adapter_config(name='trash', context=(Interface, IAdminLayer, SecurityManagerPluginsTable), provides=IColumn)
   126 @adapter_config(name='trash', context=(Interface, IAdminLayer, SecurityManagerPluginsTable), provides=IColumn)
   126 class SecurityManagerPluginsTrashColumn(TrashColumn):
   127 class SecurityManagerPluginsTrashColumn(TrashColumn):
   127     """Security manager plugins trash column"""
   128     """Security manager plugins trash column"""
   128 
   129 
   129     icon_hint = _("Delete plug-in")
   130     icon_hint = _("Delete plug-in")
   130     permission = 'system.manage'
   131     permission = MANAGE_SYSTEM_PERMISSION
   131 
   132 
   132     checker = lambda col, x: x.__name__ != '__system__'
   133     checker = lambda col, x: x.__name__ != '__system__'
   133 
   134 
   134 
   135 
   135 @adapter_config(context=(ISite, IAdminLayer, SecurityManagerPluginsTable), provides=IValues)
   136 @adapter_config(context=(ISite, IAdminLayer, SecurityManagerPluginsTable), provides=IValues)
   142         if manager is not None:
   143         if manager is not None:
   143             return list(manager.values())
   144             return list(manager.values())
   144         return ()
   145         return ()
   145 
   146 
   146 
   147 
   147 @pagelet_config(name='security-manager.html', context=ISite, layer=IPyAMSLayer, permission='system.view')
   148 @pagelet_config(name='security-manager.html', context=ISite, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
   148 @implementer(IInnerPage)
   149 @implementer(IInnerPage)
   149 class SecurityManagerView(AdminView, ContainerView):
   150 class SecurityManagerView(AdminView, ContainerView):
   150     """Security manager view"""
   151     """Security manager view"""
   151 
   152 
   152     table_class = SecurityManagerPluginsTable
   153     table_class = SecurityManagerPluginsTable
   160     title = _("Control panel")
   161     title = _("Control panel")
   161     subtitle = _("Security manager")
   162     subtitle = _("Security manager")
   162 
   163 
   163 
   164 
   164 @viewlet_config(name='security-manager.properties.menu', context=ISite, layer=IAdminLayer,
   165 @viewlet_config(name='security-manager.properties.menu', context=ISite, layer=IAdminLayer,
   165                 manager=ISecurityManagerMenu, permission='system.view', weight=1)
   166                 manager=ISecurityManagerMenu, permission=VIEW_SYSTEM_PERMISSION, weight=1)
   166 class SecurityManagerPropertiesMenuItem(MenuItem):
   167 class SecurityManagerPropertiesMenuItem(MenuItem):
   167     """Security manager properties menu"""
   168     """Security manager properties menu"""
   168 
   169 
   169     label = _("Properties...")
   170     label = _("Properties...")
   170     url = 'properties.html'
   171     url = 'properties.html'
   173     def get_url(self):
   174     def get_url(self):
   174         manager = query_utility(ISecurityManager)
   175         manager = query_utility(ISecurityManager)
   175         return resource_url(manager, self.request, self.url)
   176         return resource_url(manager, self.request, self.url)
   176 
   177 
   177 
   178 
   178 @pagelet_config(name='properties.html', context=ISecurityManager, layer=IPyAMSLayer, permission='system.view')
   179 @pagelet_config(name='properties.html', context=ISecurityManager, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
   179 class SecurityManagerEditForm(AdminDialogEditForm):
   180 class SecurityManagerEditForm(AdminDialogEditForm):
   180     """Security manager edit form"""
   181     """Security manager edit form"""
   181 
   182 
   182     title = _("System security manager")
   183     title = _("System security manager")
   183     legend = _("Security manager properties")
   184     legend = _("Security manager properties")
   191     fields['credentials_plugins_names'].widgetFactory = OrderedPluginsFieldWidget
   192     fields['credentials_plugins_names'].widgetFactory = OrderedPluginsFieldWidget
   192     fields['authentication_plugins_names'].widgetFactory = OrderedPluginsFieldWidget
   193     fields['authentication_plugins_names'].widgetFactory = OrderedPluginsFieldWidget
   193     fields['directory_plugins_names'].widgetFactory = OrderedPluginsFieldWidget
   194     fields['directory_plugins_names'].widgetFactory = OrderedPluginsFieldWidget
   194 
   195 
   195     ajax_handler = 'properties.json'
   196     ajax_handler = 'properties.json'
       
   197     edit_permission = MANAGE_SYSTEM_PERMISSION
   196 
   198 
   197     def getContent(self):
   199     def getContent(self):
   198         return query_utility(ISecurityManager)
   200         return query_utility(ISecurityManager)
   199 
   201 
   200     def update(self):
   202     def update(self):
   223         plugins_group.input_css_class = 'col-md-8'
   225         plugins_group.input_css_class = 'col-md-8'
   224         self.add_group(plugins_group)
   226         self.add_group(plugins_group)
   225 
   227 
   226 
   228 
   227 @view_config(name='properties.json', context=ISecurityManager, request_type=IPyAMSLayer,
   229 @view_config(name='properties.json', context=ISecurityManager, request_type=IPyAMSLayer,
   228              permission='system.manage', renderer='json', xhr=True)
   230              permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
   229 class SecurityManagerAJAXEditForm(AJAXEditForm, SecurityManagerEditForm):
   231 class SecurityManagerAJAXEditForm(AJAXEditForm, SecurityManagerEditForm):
   230     """Security manager edit form, AJAX view"""
   232     """Security manager edit form, AJAX view"""
   231 
   233 
   232 
   234 
   233 @view_config(name='delete-plugin.json', context=ISecurityManager, request_type=IPyAMSLayer,
   235 @view_config(name='delete-plugin.json', context=ISecurityManager, request_type=IPyAMSLayer,
   234              permission='system.manage', renderer='json', xhr=True)
   236              permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
   235 def delete_security_manager_plugin(request):
   237 def delete_security_manager_plugin(request):
   236     """Delete plug-in from security manager"""
   238     """Delete plug-in from security manager"""
   237     translate = request.localizer.translate
   239     translate = request.localizer.translate
   238     name = request.params.get('object_name')
   240     name = request.params.get('object_name')
   239     if not name:
   241     if not name: