src/pyams_security/include.py
changeset 0 f04e1d0a0723
child 2 94e76f8e9828
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_security/include.py	Thu Feb 19 10:53:29 2015 +0100
@@ -0,0 +1,58 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+
+# import packages
+from pyams_security.permission import register_permission
+from pyams_security.plugin import PluginSelector
+from pyams_security.role import register_role
+from pyams_security.utility import get_principal
+
+
+def include_package(config):
+    """Pyramid include"""
+    # add translations
+    config.add_translation_dirs('pyams_security:locales')
+
+    # add configuration directives
+    config.add_directive('register_permission', register_permission)
+    config.add_directive('register_role', register_role)
+    config.add_request_method(get_principal, 'principal', reify=True)
+
+    # add subscribers predicate
+    config.add_subscriber_predicate('plugin_selector', PluginSelector)
+
+    # add custom routes
+    config.add_route('login', '/login/{provider_name}')
+
+    # register custom permissions
+    config.register_permission({'id': 'system.manage',
+                                'title': "Manage system"})
+    config.register_permission({'id': 'system.view',
+                                'title': "View management screens"})
+
+    # load registry components
+    try:
+        import pyams_zmi
+    except ImportError:
+        config.scan(ignore='pyams_security.zmi')
+    else:
+        config.scan()
+
+    if hasattr(config, 'load_zcml'):
+        config.load_zcml('configure.zcml')