~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-07-05 14:31:38 UTC
  • mfrom: (13316.10.21 bug-740208-obfuscate-ws)
  • Revision ID: launchpad@pqm.canonical.com-20110705143138-yd0hdrvbeslquzfm
[r=deryck][bug=740208] obfuscated email addresses for anonymous
 webservice requests

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