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