~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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Copyright 2010 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

__metaclass__ = type
__all__ = [
    'DistroSeriesDifferenceError',
    'NotADerivedSeriesError',
    'CannotTransitionToCountryMirror',
    'CountryMirrorAlreadySet',
    'DeleteSubscriptionError',
    'InvalidName',
    'JoinNotAllowed',
    'MirrorNotOfficial',
    'MirrorHasNoHTTPURL',
    'MirrorNotProbed',
    'NameAlreadyTaken',
    'NoSuchDistroSeries',
    'NoSuchSourcePackageName',
    'OpenTeamLinkageError',
    'PPACreationError',
    'PrivatePersonLinkageError',
    'TeamMembershipTransitionError',
    'TeamSubscriptionPolicyError',
    'UserCannotChangeMembershipSilently',
    'UserCannotSubscribePerson',
    ]

import httplib

from lazr.restful.declarations import error_status
from zope.schema.interfaces import ConstraintNotSatisfied
from zope.security.interfaces import Unauthorized

from lp.app.errors import NameLookupFailed


@error_status(httplib.FORBIDDEN)
class PrivatePersonLinkageError(ValueError):
    """An attempt was made to link a private person/team to something."""


@error_status(httplib.FORBIDDEN)
class OpenTeamLinkageError(ValueError):
    """An attempt was made to link an open team to something."""


@error_status(httplib.CONFLICT)
class NameAlreadyTaken(Exception):
    """The name given for a person is already in use by other person."""


class InvalidName(Exception):
    """The name given for a person is not valid."""


class NoSuchDistroSeries(NameLookupFailed):
    """Raised when we try to find a DistroSeries that doesn't exist."""
    _message_prefix = "No such distribution series"


@error_status(httplib.UNAUTHORIZED)
class UserCannotChangeMembershipSilently(Unauthorized):
    """User not permitted to change membership status silently.

    Raised when a user tries to change someone's membership silently, and is
    not a Launchpad Administrator.
    """


class NoSuchSourcePackageName(NameLookupFailed):
    """Raised when we can't find a particular sourcepackagename."""
    _message_prefix = "No such source package"


@error_status(httplib.BAD_REQUEST)
class CannotTransitionToCountryMirror(Exception):
    """Root exception for transitions to country mirrors."""


class CountryMirrorAlreadySet(CannotTransitionToCountryMirror):
    """Distribution mirror cannot be set as a country mirror.

    Raised when a user tries to change set a distribution mirror as a country
    mirror, however there is already one set for that country.
    """


class MirrorNotOfficial(CannotTransitionToCountryMirror):
    """Distribution mirror is not permitted to become a country mirror.

    Raised when a user tries to change set a distribution mirror as a country
    mirror, however the mirror in question is not official.
    """


class MirrorHasNoHTTPURL(CannotTransitionToCountryMirror):
    """Distribution mirror has no HTTP URL.

    Raised when a user tries to make an official mirror a country mirror,
    however the mirror has not HTTP URL set.
    """


class MirrorNotProbed(CannotTransitionToCountryMirror):
    """Distribution mirror has not been probed.

    Raised when a user tries to set an official mirror as a country mirror,
    however the mirror has not been probed yet.
    """


@error_status(httplib.BAD_REQUEST)
class DeleteSubscriptionError(Exception):
    """Delete Subscription Error.

    Raised when an error occurred trying to delete a
    structural subscription."""


@error_status(httplib.UNAUTHORIZED)
class UserCannotSubscribePerson(Exception):
    """User does not have permission to subscribe the person or team."""


@error_status(httplib.BAD_REQUEST)
class DistroSeriesDifferenceError(Exception):
    """Raised when package diffs cannot be created for a difference."""


class NotADerivedSeriesError(Exception):
    """A distro series difference must be created with a derived series.

    This is raised when a DistroSeriesDifference is created with a
    non-derived series - that is, a distroseries with a null Parent."""


@error_status(httplib.BAD_REQUEST)
class TeamMembershipTransitionError(ValueError):
    """Indicates something has gone wrong with the transtiion.

    Generally, this indicates a bad transition (e.g. approved to proposed)
    or an invalid transition (e.g. unicorn).
    """


@error_status(httplib.BAD_REQUEST)
class TeamSubscriptionPolicyError(ConstraintNotSatisfied):
    """The team cannot have the specified TeamSubscriptionPolicy.

    The error can be raised because a super team or member team prevents
    this team from setting a specific policy. The error can also be
    raised if the team has an active PPA.
    """

    _default_message = "Team Subscription Policy Error"

    def __init__(self, message=None):
        if message is None:
            message = self._default_message
        self.message = message

    def doc(self):
        """See `Invalid`."""
        return self.message

    def __str__(self):
        return self.message


@error_status(httplib.BAD_REQUEST)
class JoinNotAllowed(Exception):
    """User is not allowed to join a given team."""


@error_status(httplib.BAD_REQUEST)
class PPACreationError(Exception):
    """Raised when there is an issue creating a new PPA."""