~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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""XMLRPC APIs for person set."""

__metaclass__ = type
__all__ = [
    'SoftwareCenterAgentAPI',
    ]


from zope.component import getUtility
from zope.interface import implements

from lp.registry.interfaces.person import (
    IPersonSet,
    ISoftwareCenterAgentAPI,
    ISoftwareCenterAgentApplication,
    PersonCreationRationale,
    )
from lp.services.identity.interfaces.account import AccountSuspendedError
from lp.services.webapp import LaunchpadXMLRPCView
from lp.xmlrpc import faults


class SoftwareCenterAgentAPI(LaunchpadXMLRPCView):
    """See `ISoftwareCenterAgentAPI`."""

    implements(ISoftwareCenterAgentAPI)

    def getOrCreateSoftwareCenterCustomer(self, openid_identifier, email,
                                      full_name):
        try:
            person, db_updated = getUtility(
                IPersonSet).getOrCreateByOpenIDIdentifier(
                    openid_identifier.decode('ASCII'), email, full_name,
                    PersonCreationRationale.SOFTWARE_CENTER_PURCHASE,
                    "when purchasing an application via Software Center.")
        except AccountSuspendedError:
            return faults.AccountSuspended(openid_identifier)

        return person.name


class SoftwareCenterAgentApplication:
    """Software center agent end-point."""
    implements(ISoftwareCenterAgentApplication)

    title = "Software Center Agent API"