13405.9.1
by Henning Eggers
Restored r13373. |
1 |
# Copyright 2011 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
4 |
"""Launchpad-specific field marshallers for the web service."""
|
|
5 |
||
6 |
__metaclass__ = type |
|
7 |
||
8 |
__all__ = [ |
|
9 |
'TextFieldMarshaller', |
|
10 |
]
|
|
11 |
||
12 |
||
13 |
from lazr.restful.marshallers import ( |
|
14 |
TextFieldMarshaller as LazrTextFieldMarshaller, |
|
15 |
)
|
|
13303.11.18
by Aaron Bentley
Fix email obfuscation. |
16 |
from zope.component import getUtility |
13405.9.1
by Henning Eggers
Restored r13373. |
17 |
|
14550.1.1
by Steve Kowalik
Run format-imports over lib/lp and lib/canonical/launchpad |
18 |
from canonical.launchpad.webapp.interfaces import ILaunchBag |
13405.9.1
by Henning Eggers
Restored r13373. |
19 |
from lp.services.utils import obfuscate_email |
20 |
||
21 |
||
22 |
class TextFieldMarshaller(LazrTextFieldMarshaller): |
|
23 |
"""Do not expose email addresses for anonymous users."""
|
|
24 |
||
25 |
def unmarshall(self, entry, value): |
|
26 |
"""See `IFieldMarshaller`.
|
|
27 |
||
28 |
Return the value as is.
|
|
29 |
"""
|
|
13303.11.18
by Aaron Bentley
Fix email obfuscation. |
30 |
|
31 |
if (value is not None and getUtility(ILaunchBag).user is None): |
|
13405.9.1
by Henning Eggers
Restored r13373. |
32 |
return obfuscate_email(value) |
33 |
return value |