~launchpad-pqm/launchpad/devel

11637.3.24 by j.c.sackett
Merged in devel.
1
# Copyright 2010 Canonical Ltd.  This software is licensed under the
11625.2.1 by j.c.sackett
Added errors file with TeamMembershipStatus
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4
__metaclass__ = type
5
__all__ = [
7675.834.61 by Michael Nelson
Exposed package_diff_urls on DistroSeriesDifference.
6
    'DistroSeriesDifferenceError',
7
    'NotADerivedSeriesError',
11637.3.24 by j.c.sackett
Merged in devel.
8
    'CannotTransitionToCountryMirror',
9
    'CountryMirrorAlreadySet',
11746.2.1 by j.c.sackett
Moved JoinNotAllowed error in to registry.errors and added webservice definition for it.
10
    'DeleteSubscriptionError',
11
    'JoinNotAllowed',
11637.3.24 by j.c.sackett
Merged in devel.
12
    'MirrorNotOfficial',
13
    'MirrorHasNoHTTPURL',
14
    'MirrorNotProbed',
11746.2.1 by j.c.sackett
Moved JoinNotAllowed error in to registry.errors and added webservice definition for it.
15
    'NameAlreadyTaken',
16
    'NoSuchDistroSeries',
17
    'NoSuchSourcePackageName',
11889.2.1 by Steve Kowalik
Move PPACreationError to lp.registry.errors
18
    'PPACreationError',
11746.2.1 by j.c.sackett
Moved JoinNotAllowed error in to registry.errors and added webservice definition for it.
19
    'PrivatePersonLinkageError',
20
    'TeamMembershipTransitionError',
12019.9.1 by Curtis Hovey
Added a field to prevent the TeamSubscriptionPolicy to transition to a bad state.
21
    'TeamSubscriptionPolicyError',
11746.2.1 by j.c.sackett
Moved JoinNotAllowed error in to registry.errors and added webservice definition for it.
22
    'UserCannotChangeMembershipSilently',
11637.3.24 by j.c.sackett
Merged in devel.
23
    'UserCannotSubscribePerson',
11625.2.1 by j.c.sackett
Added errors file with TeamMembershipStatus
24
    ]
11625.2.5 by j.c.sackett
Lint fixes.
25
11625.2.3 by j.c.sackett
Updated tests.
26
import httplib
27
13228.3.9 by Francis J. Lacoste
Convert all webservice_error into error_status and use httplib constants.
28
from lazr.restful.declarations import error_status
12019.9.1 by Curtis Hovey
Added a field to prevent the TeamSubscriptionPolicy to transition to a bad state.
29
from zope.schema.interfaces import ConstraintNotSatisfied
11637.3.24 by j.c.sackett
Merged in devel.
30
from zope.security.interfaces import Unauthorized
31
32
from lp.app.errors import NameLookupFailed
33
34
13228.3.9 by Francis J. Lacoste
Convert all webservice_error into error_status and use httplib constants.
35
@error_status(httplib.FORBIDDEN)
11637.3.24 by j.c.sackett
Merged in devel.
36
class PrivatePersonLinkageError(ValueError):
37
    """An attempt was made to link a private person/team to something."""
13228.3.9 by Francis J. Lacoste
Convert all webservice_error into error_status and use httplib constants.
38
39
40
@error_status(httplib.CONFLICT)
11637.3.24 by j.c.sackett
Merged in devel.
41
class NameAlreadyTaken(Exception):
42
    """The name given for a person is already in use by other person."""
43
44
45
class NoSuchDistroSeries(NameLookupFailed):
46
    """Raised when we try to find a DistroSeries that doesn't exist."""
47
    _message_prefix = "No such distribution series"
48
49
13228.3.9 by Francis J. Lacoste
Convert all webservice_error into error_status and use httplib constants.
50
@error_status(httplib.UNAUTHORIZED)
11637.3.24 by j.c.sackett
Merged in devel.
51
class UserCannotChangeMembershipSilently(Unauthorized):
52
    """User not permitted to change membership status silently.
53
54
    Raised when a user tries to change someone's membership silently, and is
55
    not a Launchpad Administrator.
56
    """
57
58
59
class NoSuchSourcePackageName(NameLookupFailed):
60
    """Raised when we can't find a particular sourcepackagename."""
61
    _message_prefix = "No such source package"
62
63
13228.3.9 by Francis J. Lacoste
Convert all webservice_error into error_status and use httplib constants.
64
@error_status(httplib.BAD_REQUEST)
11637.3.24 by j.c.sackett
Merged in devel.
65
class CannotTransitionToCountryMirror(Exception):
66
    """Root exception for transitions to country mirrors."""
67
68
69
class CountryMirrorAlreadySet(CannotTransitionToCountryMirror):
70
    """Distribution mirror cannot be set as a country mirror.
71
72
    Raised when a user tries to change set a distribution mirror as a country
73
    mirror, however there is already one set for that country.
74
    """
75
76
77
class MirrorNotOfficial(CannotTransitionToCountryMirror):
78
    """Distribution mirror is not permitted to become a country mirror.
79
80
    Raised when a user tries to change set a distribution mirror as a country
81
    mirror, however the mirror in question is not official.
82
    """
83
84
85
class MirrorHasNoHTTPURL(CannotTransitionToCountryMirror):
86
    """Distribution mirror has no HTTP URL.
87
88
    Raised when a user tries to make an official mirror a country mirror,
89
    however the mirror has not HTTP URL set.
90
    """
91
92
93
class MirrorNotProbed(CannotTransitionToCountryMirror):
94
    """Distribution mirror has not been probed.
95
96
    Raised when a user tries to set an official mirror as a country mirror,
97
    however the mirror has not been probed yet.
98
    """
99
100
13228.3.9 by Francis J. Lacoste
Convert all webservice_error into error_status and use httplib constants.
101
@error_status(httplib.BAD_REQUEST)
11637.3.24 by j.c.sackett
Merged in devel.
102
class DeleteSubscriptionError(Exception):
103
    """Delete Subscription Error.
104
105
    Raised when an error occurred trying to delete a
106
    structural subscription."""
13228.3.9 by Francis J. Lacoste
Convert all webservice_error into error_status and use httplib constants.
107
108
109
@error_status(httplib.UNAUTHORIZED)
11637.3.24 by j.c.sackett
Merged in devel.
110
class UserCannotSubscribePerson(Exception):
111
    """User does not have permission to subscribe the person or team."""
13228.3.9 by Francis J. Lacoste
Convert all webservice_error into error_status and use httplib constants.
112
113
114
@error_status(httplib.BAD_REQUEST)
7675.834.61 by Michael Nelson
Exposed package_diff_urls on DistroSeriesDifference.
115
class DistroSeriesDifferenceError(Exception):
116
    """Raised when package diffs cannot be created for a difference."""
117
118
119
class NotADerivedSeriesError(Exception):
120
    """A distro series difference must be created with a derived series.
121
122
    This is raised when a DistroSeriesDifference is created with a
123
    non-derived series - that is, a distroseries with a null Parent."""
124
125
13228.3.9 by Francis J. Lacoste
Convert all webservice_error into error_status and use httplib constants.
126
@error_status(httplib.BAD_REQUEST)
11625.2.1 by j.c.sackett
Added errors file with TeamMembershipStatus
127
class TeamMembershipTransitionError(ValueError):
11625.2.6 by j.c.sackett
Added docstring.
128
    """Indicates something has gone wrong with the transtiion.
11625.2.9 by j.c.sackett
Lint fixes.
129
11625.2.6 by j.c.sackett
Added docstring.
130
    Generally, this indicates a bad transition (e.g. approved to proposed)
131
    or an invalid transition (e.g. unicorn).
132
    """
13228.3.9 by Francis J. Lacoste
Convert all webservice_error into error_status and use httplib constants.
133
134
135
@error_status(httplib.BAD_REQUEST)
12019.9.1 by Curtis Hovey
Added a field to prevent the TeamSubscriptionPolicy to transition to a bad state.
136
class TeamSubscriptionPolicyError(ConstraintNotSatisfied):
137
    """The team cannot have the specified TeamSubscriptionPolicy.
138
139
    The error can be raised because a super team or member team prevents
12019.9.6 by Curtis Hovey
Added test and fixed conditional.
140
    this team from setting a specific policy. The error can also be
12019.9.3 by Curtis Hovey
Added doc() to TeamSubscriptionPolicyError so that the specific error message
141
    raised if the team has an active PPA.
12019.9.1 by Curtis Hovey
Added a field to prevent the TeamSubscriptionPolicy to transition to a bad state.
142
    """
143
12019.9.3 by Curtis Hovey
Added doc() to TeamSubscriptionPolicyError so that the specific error message
144
    _default_message = "Team Subscription Policy Error"
145
146
    def __init__(self, message=None):
147
        if message is None:
148
            message = self._default_message
149
        self.message = message
150
151
    def doc(self):
12019.9.4 by Curtis Hovey
Updated docstring.
152
        """See `Invalid`."""
12019.9.3 by Curtis Hovey
Added doc() to TeamSubscriptionPolicyError so that the specific error message
153
        return self.message
154
155
    def __str__(self):
156
        return self.message
157
12019.9.1 by Curtis Hovey
Added a field to prevent the TeamSubscriptionPolicy to transition to a bad state.
158
13228.3.9 by Francis J. Lacoste
Convert all webservice_error into error_status and use httplib constants.
159
@error_status(httplib.BAD_REQUEST)
11746.2.1 by j.c.sackett
Moved JoinNotAllowed error in to registry.errors and added webservice definition for it.
160
class JoinNotAllowed(Exception):
161
    """User is not allowed to join a given team."""
13228.3.9 by Francis J. Lacoste
Convert all webservice_error into error_status and use httplib constants.
162
163
164
@error_status(httplib.BAD_REQUEST)
11889.2.1 by Steve Kowalik
Move PPACreationError to lp.registry.errors
165
class PPACreationError(Exception):
166
    """Raised when there is an issue creating a new PPA."""