Changed vocabulary declaration
authorThierry Florac <thierry.florac@onf.fr>
Tue, 15 Nov 2016 10:34:41 +0100
changeset 72 6dd8bc7bb7b5
parent 71 0a612729eb2f
child 73 8777986af300
Changed vocabulary declaration
src/pyams_security/permission.py
src/pyams_security/plugin/group.py
src/pyams_security/plugin/social.py
src/pyams_security/plugin/userfolder.py
src/pyams_security/role.py
src/pyams_security/vocabulary.py
--- a/src/pyams_security/permission.py	Tue Oct 11 16:09:19 2016 +0200
+++ b/src/pyams_security/permission.py	Tue Nov 15 10:34:41 2016 +0100
@@ -16,13 +16,13 @@
 
 # import interfaces
 from pyams_security.interfaces import IPermission
-from zope.schema.interfaces import IVocabularyFactory
 
 # import packages
 from pyams_utils.request import check_request
-from zope.interface import implementer, provider
+from pyams_utils.vocabulary import vocabulary_config
+from zope.interface import implementer
 from zope.schema.fieldproperty import FieldProperty
-from zope.schema.vocabulary import getVocabularyRegistry, SimpleTerm, SimpleVocabulary
+from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
 
 
 @implementer(IPermission)
@@ -53,7 +53,7 @@
     config.registry.registerUtility(permission, IPermission, name=permission.id)
 
 
-@provider(IVocabularyFactory)
+@vocabulary_config(name='PyAMS permissions')
 class PermissionsVocabulary(SimpleVocabulary):
     """Permissions vocabulary"""
 
@@ -67,5 +67,3 @@
                  for n, p in registry.getUtilitiesFor(self.interface)]
         terms.sort(key=lambda x: x.title)
         super(PermissionsVocabulary, self).__init__(terms)
-
-getVocabularyRegistry().register('PyAMS permissions', PermissionsVocabulary)
--- a/src/pyams_security/plugin/group.py	Tue Oct 11 16:09:19 2016 +0200
+++ b/src/pyams_security/plugin/group.py	Tue Nov 15 10:34:41 2016 +0100
@@ -21,7 +21,6 @@
 from pyams_security.interfaces import IGroupsFolderPlugin, ILocalGroup, IPrincipalsAddedToGroupEvent, \
     IPrincipalsRemovedFromGroupEvent, PrincipalsAddedToGroupEvent, PrincipalsRemovedFromGroupEvent, ISecurityManager
 from zope.lifecycleevent.interfaces import IObjectAddedEvent
-from zope.schema.interfaces import IVocabularyFactory
 
 # import packages
 from BTrees import OOBTree
@@ -29,12 +28,13 @@
 from pyams_security.principal import PrincipalInfo
 from pyams_utils.registry import query_utility
 from pyams_utils.request import check_request
+from pyams_utils.vocabulary import vocabulary_config
 from pyramid.events import subscriber
 from zope.container.contained import Contained
 from zope.container.folder import Folder
-from zope.interface import implementer, provider
+from zope.interface import implementer
 from zope.schema.fieldproperty import FieldProperty
-from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm, getVocabularyRegistry
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
 
 @implementer(ILocalGroup)
@@ -68,7 +68,7 @@
                 registry.notify(PrincipalsRemovedFromGroupEvent(self, removed))
 
 
-@provider(IVocabularyFactory)
+@vocabulary_config(name='PyAMS local groups')
 class LocalGroupsVocabulary(SimpleVocabulary):
     """'PyAMS local groups vocabulary"""
 
@@ -84,8 +84,6 @@
                                                 title=group.title))
         super(LocalGroupsVocabulary, self).__init__(terms)
 
-getVocabularyRegistry().register('PyAMS local groups', LocalGroupsVocabulary)
-
 
 @implementer(IGroupsFolderPlugin)
 class GroupsFolder(Folder):
--- a/src/pyams_security/plugin/social.py	Tue Oct 11 16:09:19 2016 +0200
+++ b/src/pyams_security/plugin/social.py	Tue Nov 15 10:34:41 2016 +0100
@@ -20,7 +20,6 @@
 from pyams_security.interfaces import ISocialUser, IPrincipalInfo, ISocialUsersFolderPlugin, ISecurityManager, \
     IAuthenticatedPrincipalEvent, ISocialLoginConfiguration, ISocialLoginProviderInfo, ISocialLoginProviderConnection
 from zope.annotation.interfaces import IAnnotations
-from zope.schema.interfaces import IVocabularyFactory
 from zope.traversing.interfaces import ITraversable
 
 # import packages
@@ -30,14 +29,15 @@
 from pyams_utils.adapter import adapter_config, ContextAdapter
 from pyams_utils.registry import query_utility
 from pyams_utils.request import check_request
+from pyams_utils.vocabulary import vocabulary_config
 from pyramid.events import subscriber
 from zope.container.contained import Contained
 from zope.container.folder import Folder
-from zope.interface import implementer, provider
+from zope.interface import implementer
 from zope.lifecycleevent import ObjectCreatedEvent
 from zope.location import locate
 from zope.schema.fieldproperty import FieldProperty
-from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm, getVocabularyRegistry
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
 
 @implementer(ISocialUser)
@@ -143,7 +143,7 @@
                 yield user
 
 
-@provider(IVocabularyFactory)
+@vocabulary_config(name='PyAMS social users folders')
 class SocialUsersFolderVocabulary(SimpleVocabulary):
     """'PyAMS users folders' vocabulary"""
 
@@ -156,8 +156,6 @@
                     terms.append(SimpleTerm(name, title=plugin.title))
         super(SocialUsersFolderVocabulary, self).__init__(terms)
 
-getVocabularyRegistry().register('PyAMS social users folders', SocialUsersFolderVocabulary)
-
 
 @subscriber(IAuthenticatedPrincipalEvent, plugin_selector='oauth')
 def handle_authenticated_principal(event):
@@ -347,7 +345,7 @@
     return PROVIDERS_INFO.get(provider_name)
 
 
-@provider(IVocabularyFactory)
+@vocabulary_config(name='PyAMS OAuth providers')
 class OAuthProvidersVocabulary(SimpleVocabulary):
     """OAuth providers vocabulary"""
 
@@ -358,8 +356,6 @@
         terms.sort(key=lambda x: x.title)
         super(OAuthProvidersVocabulary, self).__init__(terms)
 
-getVocabularyRegistry().register('PyAMS OAuth providers', OAuthProvidersVocabulary)
-
 
 @implementer(ISocialLoginConfiguration)
 class SocialLoginConfiguration(Folder):
--- a/src/pyams_security/plugin/userfolder.py	Tue Oct 11 16:09:19 2016 +0200
+++ b/src/pyams_security/plugin/userfolder.py	Tue Nov 15 10:34:41 2016 +0100
@@ -31,7 +31,6 @@
 from zope.component.interfaces import ISite
 from zope.lifecycleevent.interfaces import IObjectAddedEvent
 from zope.password.interfaces import IPasswordManager
-from zope.schema.interfaces import IVocabularyRegistry
 
 # import packages
 from chameleon.zpt.template import PageTemplateFile
@@ -42,13 +41,14 @@
 from pyams_utils.registry import query_utility, get_utility
 from pyams_utils.request import check_request
 from pyams_utils.traversing import get_parent
+from pyams_utils.vocabulary import vocabulary_config
 from pyramid.events import subscriber
 from pyramid_mailer.message import Message, Attachment
 from zope.container.contained import Contained
 from zope.container.folder import Folder
-from zope.interface import implementer, provider, Invalid
+from zope.interface import implementer, Invalid
 from zope.schema.fieldproperty import FieldProperty
-from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm, getVocabularyRegistry
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
 from pyams_security import _
 
@@ -210,7 +210,7 @@
                 yield user
 
 
-@provider(IVocabularyRegistry)
+@vocabulary_config(name='PyAMS users folders')
 class UsersFolderVocabulary(SimpleVocabulary):
     """'PyAMS users folders' vocabulary"""
 
@@ -223,8 +223,6 @@
                     terms.append(SimpleTerm(name, title=plugin.title))
         super(UsersFolderVocabulary, self).__init__(terms)
 
-getVocabularyRegistry().register('PyAMS users folders', UsersFolderVocabulary)
-
 
 @subscriber(IObjectAddedEvent, context_selector=ILocalUser)
 def handle_new_local_user(event):
--- a/src/pyams_security/role.py	Tue Oct 11 16:09:19 2016 +0200
+++ b/src/pyams_security/role.py	Tue Nov 15 10:34:41 2016 +0100
@@ -17,13 +17,13 @@
 
 # import interfaces
 from pyams_security.interfaces import IRole
-from zope.schema.interfaces import IVocabularyFactory
 
 # import packages
 from pyams_utils.request import check_request
-from zope.interface import implementer, provider
+from pyams_utils.vocabulary import vocabulary_config
+from zope.interface import implementer
 from zope.schema.fieldproperty import FieldProperty
-from zope.schema.vocabulary import getVocabularyRegistry, SimpleVocabulary, SimpleTerm
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
 
 @implementer(IRole)
@@ -74,7 +74,7 @@
         registry.registerUtility(role, IRole, name=role.id)
 
 
-@provider(IVocabularyFactory)
+@vocabulary_config(name='PyAMS roles')
 class RolesVocabulary(SimpleVocabulary):
     """Roles vocabulary"""
 
@@ -88,5 +88,3 @@
                  for n, r in registry.getUtilitiesFor(self.interface)]
         terms.sort(key=lambda x: x.title)
         super(RolesVocabulary, self).__init__(terms)
-
-getVocabularyRegistry().register('PyAMS roles', RolesVocabulary)
--- a/src/pyams_security/vocabulary.py	Tue Oct 11 16:09:19 2016 +0200
+++ b/src/pyams_security/vocabulary.py	Tue Nov 15 10:34:41 2016 +0100
@@ -19,14 +19,13 @@
 from zope.password.interfaces import IPasswordManager
 
 # import packages
+from pyams_utils.vocabulary import vocabulary_config
 from zope.componentvocabulary.vocabulary import UtilityVocabulary
-from zope.schema.vocabulary import getVocabularyRegistry
 
 
+@vocabulary_config(name='PyAMS password managers')
 class PasswordManagerVocabulary(UtilityVocabulary):
     """Password managers vocabulary"""
 
     interface = IPasswordManager
     nameOnly = True
-
-getVocabularyRegistry().register('PyAMS password managers', PasswordManagerVocabulary)