src/pyams_security/views/utility.py
changeset 2 94e76f8e9828
child 54 59683c264d94
equal deleted inserted replaced
1:5595823c66f1 2:94e76f8e9828
       
     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 from pyams_security.interfaces import ISecurityManager
       
    20 from pyams_skin.layer import IPyAMSLayer
       
    21 
       
    22 # import packages
       
    23 from pyams_utils.registry import query_utility
       
    24 from pyramid.view import view_config
       
    25 
       
    26 
       
    27 @view_config(name='find-principals.json', request_type=IPyAMSLayer,
       
    28              permission='system.view', renderer='json', xhr=True)
       
    29 def find_principals(request):
       
    30     """Find all principals matching given query"""
       
    31     query = request.params.get('query')
       
    32     if not query:
       
    33         return []
       
    34     manager = query_utility(ISecurityManager)
       
    35     return [{'id': principal.id,
       
    36              'text': principal.title} for principal in manager.find_principals(query)]