|
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 IPrincipalInfo |
|
20 |
|
21 # import packages |
|
22 from zope.interface import implementer |
|
23 from zope.schema.fieldproperty import FieldProperty |
|
24 |
|
25 from pyams_security import _ |
|
26 |
|
27 |
|
28 @implementer(IPrincipalInfo) |
|
29 class PrincipalInfo(object): |
|
30 """Generic principal info""" |
|
31 |
|
32 id = FieldProperty(IPrincipalInfo['id']) |
|
33 title = FieldProperty(IPrincipalInfo['title']) |
|
34 groups = FieldProperty(IPrincipalInfo['groups']) |
|
35 |
|
36 def __init__(self, **kwargs): |
|
37 self.id = kwargs.get('id') |
|
38 self.title = kwargs.get('title') |
|
39 |
|
40 def __eq__(self, other): |
|
41 return isinstance(other, PrincipalInfo) and (self.id == other.id) |
|
42 |
|
43 |
|
44 @implementer(IPrincipalInfo) |
|
45 class UnknownPrincipal(object): |
|
46 """Unknown principal info""" |
|
47 |
|
48 id = None |
|
49 title = _("Not logged in") |
|
50 |
|
51 UnknownPrincipal = UnknownPrincipal() |
|
52 |
|
53 |
|
54 @implementer(IPrincipalInfo) |
|
55 class MissingPrincipal(object): |
|
56 """Missing principal info |
|
57 |
|
58 This class can be used when a stored principal ID |
|
59 references a principal which can't be found anymore |
|
60 """ |
|
61 |
|
62 id = FieldProperty(IPrincipalInfo['id']) |
|
63 |
|
64 def __init__(self, **kwargs): |
|
65 self.id = kwargs.get('id') |
|
66 |
|
67 @property |
|
68 def title(self): |
|
69 return '<MissingPrincipal: {0}>'.format(self.id) |
|
70 |
|
71 def __eq__(self, other): |
|
72 return isinstance(other, PrincipalInfo) and (self.id == other.id) |