src/pyams_security/zmi/plugin/group.py
changeset 54 59683c264d94
parent 42 07229ac2497b
child 73 8777986af300
equal deleted inserted replaced
53:68678e37a77a 54:59683c264d94
    18 # import interfaces
    18 # import interfaces
    19 from pyams_security.interfaces import IGroupsFolderPlugin, ISecurityManager, ILocalGroup
    19 from pyams_security.interfaces import IGroupsFolderPlugin, ISecurityManager, ILocalGroup
    20 from pyams_skin.interfaces import IPageHeader, IInnerPage
    20 from pyams_skin.interfaces import IPageHeader, IInnerPage
    21 from pyams_skin.interfaces.viewlet import IToolbarAddingMenu, IWidgetTitleViewletManager
    21 from pyams_skin.interfaces.viewlet import IToolbarAddingMenu, IWidgetTitleViewletManager
    22 from pyams_skin.layer import IPyAMSLayer
    22 from pyams_skin.layer import IPyAMSLayer
       
    23 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION, MANAGE_SYSTEM_PERMISSION
    23 from pyams_zmi.layer import IAdminLayer
    24 from pyams_zmi.layer import IAdminLayer
    24 from z3c.form.interfaces import DISPLAY_MODE, IDataExtractedEvent
    25 from z3c.form.interfaces import DISPLAY_MODE, IDataExtractedEvent
    25 from z3c.table.interfaces import IColumn, IValues
    26 from z3c.table.interfaces import IColumn, IValues
    26 from zope.component.interfaces import ISite
    27 from zope.component.interfaces import ISite
    27 
    28 
    53 # Groups folder views
    54 # Groups folder views
    54 #
    55 #
    55 
    56 
    56 @viewlet_config(name='add-groups-folder.menu', context=ISite, layer=IAdminLayer,
    57 @viewlet_config(name='add-groups-folder.menu', context=ISite, layer=IAdminLayer,
    57                 view=SecurityManagerPluginsTable, manager=IToolbarAddingMenu,
    58                 view=SecurityManagerPluginsTable, manager=IToolbarAddingMenu,
    58                 permission='system.manage', weight=20)
    59                 permission=MANAGE_SYSTEM_PERMISSION, weight=20)
    59 class GroupsFolderAddMenu(ToolbarMenuItem):
    60 class GroupsFolderAddMenu(ToolbarMenuItem):
    60     """Local groups folder add menu"""
    61     """Local groups folder add menu"""
    61 
    62 
    62     label = _("Add local groups folder...")
    63     label = _("Add local groups folder...")
    63     label_css_class = 'fa fa-fw fa-users'
    64     label_css_class = 'fa fa-fw fa-users'
    64     url = 'add-groups-folder.html'
    65     url = 'add-groups-folder.html'
    65     modal_target = True
    66     modal_target = True
    66 
    67 
    67 
    68 
    68 @pagelet_config(name='add-groups-folder.html', context=ISite, layer=IPyAMSLayer,
    69 @pagelet_config(name='add-groups-folder.html', context=ISite, layer=IPyAMSLayer,
    69                 permission='system.manage')
    70                 permission=MANAGE_SYSTEM_PERMISSION)
    70 class GroupsFolderAddForm(AdminDialogAddForm):
    71 class GroupsFolderAddForm(AdminDialogAddForm):
    71     """Groups folder plug-in add form"""
    72     """Groups folder plug-in add form"""
    72 
    73 
    73     title = _("System security manager")
    74     title = _("System security manager")
    74     legend = _("Add local groups folder plug-in")
    75     legend = _("Add local groups folder plug-in")
    97     if prefix in manager:
    98     if prefix in manager:
    98         event.form.widgets.errors += (Invalid(_("Specified prefix is already used!")),)
    99         event.form.widgets.errors += (Invalid(_("Specified prefix is already used!")),)
    99 
   100 
   100 
   101 
   101 @view_config(name='add-groups-folder.json', context=ISite, request_type=IPyAMSLayer,
   102 @view_config(name='add-groups-folder.json', context=ISite, request_type=IPyAMSLayer,
   102              permission='system.manage', renderer='json', xhr=True)
   103              permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
   103 class GroupsFolderAJAXAddForm(AJAXAddForm, GroupsFolderAddForm):
   104 class GroupsFolderAJAXAddForm(AJAXAddForm, GroupsFolderAddForm):
   104     """Groups folder plug-in add form, AJAX handler"""
   105     """Groups folder plug-in add form, AJAX handler"""
   105 
   106 
   106 
   107 
   107 @pagelet_config(name='properties.html', context=IGroupsFolderPlugin, layer=IPyAMSLayer,
   108 @pagelet_config(name='properties.html', context=IGroupsFolderPlugin, layer=IPyAMSLayer,
   108                 permission='system.view')
   109                 permission=VIEW_SYSTEM_PERMISSION)
   109 class GroupsFolderEditForm(AdminDialogEditForm):
   110 class GroupsFolderEditForm(AdminDialogEditForm):
   110     """Groups folder plug-in edit form"""
   111     """Groups folder plug-in edit form"""
   111 
   112 
   112     @property
   113     @property
   113     def title(self):
   114     def title(self):
   116     legend = _("Edit local groups folder plug-in properties")
   117     legend = _("Edit local groups folder plug-in properties")
   117     icon_css_class = 'fa fa-fw fa-users'
   118     icon_css_class = 'fa fa-fw fa-users'
   118 
   119 
   119     fields = field.Fields(IGroupsFolderPlugin).omit('__name__', '__parent__')
   120     fields = field.Fields(IGroupsFolderPlugin).omit('__name__', '__parent__')
   120     ajax_handler = 'properties.json'
   121     ajax_handler = 'properties.json'
   121     edit_permission = 'system.manage'
   122     edit_permission = MANAGE_SYSTEM_PERMISSION
   122 
   123 
   123     def updateWidgets(self, prefix=None):
   124     def updateWidgets(self, prefix=None):
   124         super(GroupsFolderEditForm, self).updateWidgets()
   125         super(GroupsFolderEditForm, self).updateWidgets()
   125         self.widgets['prefix'].mode = DISPLAY_MODE
   126         self.widgets['prefix'].mode = DISPLAY_MODE
   126 
   127 
   127 
   128 
   128 @view_config(name='properties.json', context=IGroupsFolderPlugin, request_type=IPyAMSLayer,
   129 @view_config(name='properties.json', context=IGroupsFolderPlugin, request_type=IPyAMSLayer,
   129              permission='system.manage', renderer='json', xhr=True)
   130              permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
   130 class GroupsFolderAJAXEditForm(AJAXEditForm, GroupsFolderEditForm):
   131 class GroupsFolderAJAXEditForm(AJAXEditForm, GroupsFolderEditForm):
   131     """Groups folder plug-in edit form, AJAX handler"""
   132     """Groups folder plug-in edit form, AJAX handler"""
   132 
   133 
   133 
   134 
   134 #
   135 #
   173 
   174 
   174     def getValue(self, obj):
   175     def getValue(self, obj):
   175         return super(DescriptionColumn, self).getValue(obj) or ''
   176         return super(DescriptionColumn, self).getValue(obj) or ''
   176 
   177 
   177 
   178 
   178 @pagelet_config(name='search.html', context=IGroupsFolderPlugin, layer=IPyAMSLayer, permission='system.view')
   179 @pagelet_config(name='search.html', context=IGroupsFolderPlugin, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
   179 @implementer(IInnerPage)
   180 @implementer(IInnerPage)
   180 class GroupsFolderSearchView(AdminView, ContainerView):
   181 class GroupsFolderSearchView(AdminView, ContainerView):
   181     """Groups folder search view"""
   182     """Groups folder search view"""
   182 
   183 
   183     table_class = GroupsFolderContentsTable
   184     table_class = GroupsFolderContentsTable
   203 # Groups views
   204 # Groups views
   204 #
   205 #
   205 
   206 
   206 @viewlet_config(name='groups-folder.toolbar.adding', context=IGroupsFolderPlugin,
   207 @viewlet_config(name='groups-folder.toolbar.adding', context=IGroupsFolderPlugin,
   207                 view=GroupsFolderContentsTable, layer=IAdminLayer,
   208                 view=GroupsFolderContentsTable, layer=IAdminLayer,
   208                 manager=IWidgetTitleViewletManager, permission='system.manage')
   209                 manager=IWidgetTitleViewletManager, permission=MANAGE_SYSTEM_PERMISSION)
   209 class LocalGroupAddAction(ToolbarAction):
   210 class LocalGroupAddAction(ToolbarAction):
   210     """Groups folder adding action"""
   211     """Groups folder adding action"""
   211 
   212 
   212     label = _("Add group")
   213     label = _("Add group")
   213     url = 'add-group.html'
   214     url = 'add-group.html'
   214     modal_target = True
   215     modal_target = True
   215 
   216 
   216 
   217 
   217 @pagelet_config(name='add-group.html', context=IGroupsFolderPlugin, layer=IPyAMSLayer, permission='system.manage')
   218 @pagelet_config(name='add-group.html', context=IGroupsFolderPlugin, layer=IPyAMSLayer,
       
   219                 permission=MANAGE_SYSTEM_PERMISSION)
   218 class LocalGroupAddForm(AdminDialogAddForm):
   220 class LocalGroupAddForm(AdminDialogAddForm):
   219     """Local group add form"""
   221     """Local group add form"""
   220 
   222 
   221     @property
   223     @property
   222     def title(self):
   224     def title(self):
   228     input_css_class = 'col-md-8'
   230     input_css_class = 'col-md-8'
   229 
   231 
   230     fields = field.Fields(ILocalGroup).omit('__parent__', '__name__')
   232     fields = field.Fields(ILocalGroup).omit('__parent__', '__name__')
   231 
   233 
   232     ajax_handler = 'add-group.json'
   234     ajax_handler = 'add-group.json'
   233     edit_permission = 'system.manage'
   235     edit_permission = MANAGE_SYSTEM_PERMISSION
   234 
   236 
   235     def updateWidgets(self, prefix=None):
   237     def updateWidgets(self, prefix=None):
   236         super(LocalGroupAddForm, self).updateWidgets()
   238         super(LocalGroupAddForm, self).updateWidgets()
   237         self.widgets['description'].label_css_class = 'textarea'
   239         self.widgets['description'].label_css_class = 'textarea'
   238 
   240 
   257     if not folder.check_group_id(data.get('group_id')):
   259     if not folder.check_group_id(data.get('group_id')):
   258         event.form.widgets.errors += (Invalid(_("Specified group ID can't be used!")),)
   260         event.form.widgets.errors += (Invalid(_("Specified group ID can't be used!")),)
   259 
   261 
   260 
   262 
   261 @view_config(name='add-group.json', context=IGroupsFolderPlugin, request_type=IPyAMSLayer,
   263 @view_config(name='add-group.json', context=IGroupsFolderPlugin, request_type=IPyAMSLayer,
   262              permission='system.manage', renderer='json', xhr=True)
   264              permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
   263 class LocalGroupAJAXAddForm(AJAXAddForm, LocalGroupAddForm):
   265 class LocalGroupAJAXAddForm(AJAXAddForm, LocalGroupAddForm):
   264     """Local group add form, AJAX view"""
   266     """Local group add form, AJAX view"""
   265 
   267 
   266     def get_ajax_output(self, changes):
   268     def get_ajax_output(self, changes):
   267         translate = self.request.localizer.translate
   269         translate = self.request.localizer.translate
   268         return {'status': 'reload',
   270         return {'status': 'reload',
   269                 'location': absolute_url(self.context, self.request, 'search.html'),
   271                 'location': absolute_url(self.context, self.request, 'search.html'),
   270                 'message': translate(_("Group was created successfully"))}
   272                 'message': translate(_("Group was created successfully"))}
   271 
   273 
   272 
   274 
   273 @pagelet_config(name='properties.html', context=ILocalGroup, layer=IPyAMSLayer, permission='system.view')
   275 @pagelet_config(name='properties.html', context=ILocalGroup, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
   274 class LocalGroupEditForm(AdminDialogEditForm):
   276 class LocalGroupEditForm(AdminDialogEditForm):
   275     """Local group edit form"""
   277     """Local group edit form"""
   276 
   278 
   277     @property
   279     @property
   278     def title(self):
   280     def title(self):
   284     input_css_class = 'col-md-8'
   286     input_css_class = 'col-md-8'
   285 
   287 
   286     fields = field.Fields(ILocalGroup).omit('__parent__', '__name__')
   288     fields = field.Fields(ILocalGroup).omit('__parent__', '__name__')
   287 
   289 
   288     ajax_handler = 'properties.json'
   290     ajax_handler = 'properties.json'
   289     edit_permission = 'system.manage'
   291     edit_permission = MANAGE_SYSTEM_PERMISSION
   290 
   292 
   291     def updateWidgets(self, prefix=None):
   293     def updateWidgets(self, prefix=None):
   292         super(LocalGroupEditForm, self).updateWidgets()
   294         super(LocalGroupEditForm, self).updateWidgets()
   293         self.widgets['description'].label_css_class = 'textarea'
   295         self.widgets['description'].label_css_class = 'textarea'
   294 
   296 
   295 
   297 
   296 @view_config(name='properties.json', context=ILocalGroup, request_type=IPyAMSLayer,
   298 @view_config(name='properties.json', context=ILocalGroup, request_type=IPyAMSLayer,
   297              permission='system.manage', renderer='json', xhr=True)
   299              permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
   298 class LocalGroupAJAXEditForm(AJAXEditForm, LocalGroupEditForm):
   300 class LocalGroupAJAXEditForm(AJAXEditForm, LocalGroupEditForm):
   299     """Local group edit form, AJAX view"""
   301     """Local group edit form, AJAX view"""
   300 
   302 
   301     def get_ajax_output(self, changes):
   303     def get_ajax_output(self, changes):
   302         if 'title' in changes.get(ILocalGroup, ()):
   304         if 'title' in changes.get(ILocalGroup, ()):