|
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 # import standard library |
|
16 |
|
17 # import interfaces |
|
18 from pyams_security.interfaces import IPermission |
|
19 |
|
20 # import packages |
|
21 from zope.interface import implementer |
|
22 from zope.schema.fieldproperty import FieldProperty |
|
23 |
|
24 |
|
25 @implementer(IPermission) |
|
26 class Permission(object): |
|
27 """Permission utility class""" |
|
28 |
|
29 id = FieldProperty(IPermission['id']) |
|
30 title = FieldProperty(IPermission['title']) |
|
31 description = FieldProperty(IPermission['description']) |
|
32 |
|
33 def __init__(self, values=None, **args): |
|
34 if not isinstance(values, dict): |
|
35 values = args |
|
36 self.id = values.get('id') |
|
37 self.title = values.get('title') |
|
38 self.description = values.get('description') |
|
39 |
|
40 |
|
41 def register_permission(config, permission): |
|
42 """Register a new permission |
|
43 |
|
44 Permissions registry is not required. |
|
45 But only registered permissions can be applied via default |
|
46 ZMI features |
|
47 """ |
|
48 if not IPermission.providedBy(permission): |
|
49 permission = Permission(permission) |
|
50 config.registry.registerUtility(permission, IPermission, name=permission.id) |