src/pyams_security/include.py
changeset 0 f04e1d0a0723
child 2 94e76f8e9828
equal deleted inserted replaced
-1:000000000000 0:f04e1d0a0723
       
     1 #
       
     2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
       
     3 # All Rights Reserved.
       
     4 #
       
     5 # This software is subject to the provisions of the Zope Public License,
       
     6 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
       
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
       
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
       
    10 # FOR A PARTICULAR PURPOSE.
       
    11 #
       
    12 
       
    13 __docformat__ = 'restructuredtext'
       
    14 
       
    15 
       
    16 # import standard library
       
    17 
       
    18 # import interfaces
       
    19 
       
    20 # import packages
       
    21 from pyams_security.permission import register_permission
       
    22 from pyams_security.plugin import PluginSelector
       
    23 from pyams_security.role import register_role
       
    24 from pyams_security.utility import get_principal
       
    25 
       
    26 
       
    27 def include_package(config):
       
    28     """Pyramid include"""
       
    29     # add translations
       
    30     config.add_translation_dirs('pyams_security:locales')
       
    31 
       
    32     # add configuration directives
       
    33     config.add_directive('register_permission', register_permission)
       
    34     config.add_directive('register_role', register_role)
       
    35     config.add_request_method(get_principal, 'principal', reify=True)
       
    36 
       
    37     # add subscribers predicate
       
    38     config.add_subscriber_predicate('plugin_selector', PluginSelector)
       
    39 
       
    40     # add custom routes
       
    41     config.add_route('login', '/login/{provider_name}')
       
    42 
       
    43     # register custom permissions
       
    44     config.register_permission({'id': 'system.manage',
       
    45                                 'title': "Manage system"})
       
    46     config.register_permission({'id': 'system.view',
       
    47                                 'title': "View management screens"})
       
    48 
       
    49     # load registry components
       
    50     try:
       
    51         import pyams_zmi
       
    52     except ImportError:
       
    53         config.scan(ignore='pyams_security.zmi')
       
    54     else:
       
    55         config.scan()
       
    56 
       
    57     if hasattr(config, 'load_zcml'):
       
    58         config.load_zcml('configure.zcml')