~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/app/webservice/marshallers.py

  • Committer: Henning Eggers
  • Date: 2011-07-12 10:02:51 UTC
  • mto: This revision was merged to the branch mainline in revision 13440.
  • Revision ID: henning@canonical.com-20110712100251-8orzcy0ra28y2qxs
Restored r13373.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
    )
 
16
from zope.app.security.interfaces import IUnauthenticatedPrincipal
 
17
 
 
18
from lp.services.utils import obfuscate_email
 
19
 
 
20
 
 
21
class TextFieldMarshaller(LazrTextFieldMarshaller):
 
22
    """Do not expose email addresses for anonymous users."""
 
23
 
 
24
    def unmarshall(self, entry, value):
 
25
        """See `IFieldMarshaller`.
 
26
 
 
27
        Return the value as is.
 
28
        """
 
29
        if (value is not None and
 
30
                IUnauthenticatedPrincipal.providedBy(self.request.principal)):
 
31
            return obfuscate_email(value)
 
32
        return value