Updated ZMI
authorThierry Florac <tflorac@ulthar.net>
Sat, 28 Feb 2015 15:26:27 +0100
changeset 8 67acb59f115e
parent 7 7920b5e679ec
child 9 22f742b01ece
Updated ZMI
src/pyams_security/zmi/plugin/admin.py
src/pyams_security/zmi/plugin/group.py
src/pyams_security/zmi/plugin/social.py
src/pyams_security/zmi/plugin/userfolder.py
--- a/src/pyams_security/zmi/plugin/admin.py	Sat Feb 28 15:25:05 2015 +0100
+++ b/src/pyams_security/zmi/plugin/admin.py	Sat Feb 28 15:26:27 2015 +0100
@@ -19,7 +19,7 @@
 from pyams_security.zmi.interfaces import ISecurityManagerToolbarAddingMenu
 from pyams_skin.interfaces import IContentHelp
 from pyams_skin.layer import IPyAMSLayer
-from z3c.form.interfaces import DISPLAY_MODE
+from z3c.form.interfaces import DISPLAY_MODE, IDataExtractedEvent
 from zope.component.interfaces import ISite
 
 # import packages
@@ -34,9 +34,11 @@
 from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.form import AdminDialogEditForm, AdminDialogAddForm
 from pyams_zmi.layer import IAdminLayer
+from pyramid.events import subscriber
 from pyramid.url import resource_url
 from pyramid.view import view_config
 from z3c.form import field
+from zope.interface import Invalid
 
 from pyams_security import _
 
@@ -77,6 +79,15 @@
         return resource_url(self.context, self.request, 'security-manager.html')
 
 
+@subscriber(IDataExtractedEvent, form_selector=AdminAuthenticationAddForm)
+def handle_new_admin_folder_data_extraction(event):
+    """Handle new admin authentication plug-in form data extraction"""
+    manager = query_utility(ISecurityManager)
+    prefix = event.data.get('prefix')
+    if prefix in manager:
+        event.form.widgets.errors += (Invalid(_("Specified prefix is already used!")),)
+
+
 @view_config(name='add_admin_authentication.json', context=ISite, request_type=IPyAMSLayer,
              permission='system.manage', renderer='json', xhr=True)
 class AdminAuthenticationAJAXAddForm(AJAXAddForm, AdminAuthenticationAddForm):
--- a/src/pyams_security/zmi/plugin/group.py	Sat Feb 28 15:25:05 2015 +0100
+++ b/src/pyams_security/zmi/plugin/group.py	Sat Feb 28 15:26:27 2015 +0100
@@ -89,6 +89,15 @@
         return absolute_url(self.context, self.request, 'security-manager.html')
 
 
+@subscriber(IDataExtractedEvent, form_selector=GroupsFolderAddForm)
+def handle_new_user_folder_data_extraction(event):
+    """Handle new groups folder plug-in form data extraction"""
+    manager = query_utility(ISecurityManager)
+    prefix = event.data.get('prefix')
+    if prefix in manager:
+        event.form.widgets.errors += (Invalid(_("Specified prefix is already used!")),)
+
+
 @view_config(name='add-groups-folder.json', context=ISite, request_type=IPyAMSLayer,
              permission='system.manage', renderer='json', xhr=True)
 class GroupsFolderAJAXAddForm(AJAXAddForm, GroupsFolderAddForm):
--- a/src/pyams_security/zmi/plugin/social.py	Sat Feb 28 15:25:05 2015 +0100
+++ b/src/pyams_security/zmi/plugin/social.py	Sat Feb 28 15:26:27 2015 +0100
@@ -95,6 +95,15 @@
         return absolute_url(self.context, self.request, 'security-manager.html')
 
 
+@subscriber(IDataExtractedEvent, form_selector=SocialUsersFolderAddForm)
+def handle_new_user_folder_data_extraction(event):
+    """Handle new social users folder form data extraction"""
+    manager = query_utility(ISecurityManager)
+    prefix = event.data.get('prefix')
+    if prefix in manager:
+        event.form.widgets.errors += (Invalid(_("Specified prefix is already used!")),)
+
+
 @view_config(name='add-social-users-folder.json', context=ISite, request_type=IPyAMSLayer,
              permission='system.manage', renderer='json', xhr=True)
 class SocialUsersFolderAJAXAddForm(AJAXAddForm, SocialUsersFolderAddForm):
--- a/src/pyams_security/zmi/plugin/userfolder.py	Sat Feb 28 15:25:05 2015 +0100
+++ b/src/pyams_security/zmi/plugin/userfolder.py	Sat Feb 28 15:26:27 2015 +0100
@@ -93,6 +93,15 @@
         return absolute_url(self.context, self.request, 'security-manager.html')
 
 
+@subscriber(IDataExtractedEvent, form_selector=UsersFolderAddForm)
+def handle_new_user_folder_data_extraction(event):
+    """Handle new user folder form data extraction"""
+    manager = query_utility(ISecurityManager)
+    prefix = event.data.get('prefix')
+    if prefix in manager:
+        event.form.widgets.errors += (Invalid(_("Specified prefix is already used!")),)
+
+
 @view_config(name='add-users-folder.json', context=ISite, request_type=IPyAMSLayer,
              permission='system.manage', renderer='json', xhr=True)
 class UsersFolderAJAXAddForm(AJAXAddForm, UsersFolderAddForm):