~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Copyright 2011 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Launchpad-specific field marshallers for the web service."""

__metaclass__ = type

__all__ = [
    'TextFieldMarshaller',
    ]


from lazr.restful.marshallers import (
    TextFieldMarshaller as LazrTextFieldMarshaller,
    )
from zope.component import getUtility

from canonical.launchpad.webapp.interfaces import ILaunchBag
from lp.services.utils import obfuscate_email


class TextFieldMarshaller(LazrTextFieldMarshaller):
    """Do not expose email addresses for anonymous users."""

    def unmarshall(self, entry, value):
        """See `IFieldMarshaller`.

        Return the value as is.
        """

        if (value is not None and getUtility(ILaunchBag).user is None):
            return obfuscate_email(value)
        return value