Mercurial > p > roundup > code
annotate roundup/cgi/exceptions.py @ 5630:07abc8d36940
Add etag support to rest interface to prevent multiple users from
overwriting other users changes.
All GET requests for an object (issue, user, keyword etc.) or a
property of an object (e.g the title of an issue) return the etag for
the object in the ETag header as well as the @etag field in the
returned object.
All requests that change existing objects (DELETE, PUT or PATCH)
require:
1 A request include an ETag header with the etag value retrieved
for the object.
2 A submits a form that includes the field @etag that must have
the value retrieved for the object.
If an etag is not supplied by one of these methods, or any supplied
etag does not match the etag calculated at the time the DELETE, PUT or
PATCH request is made, HTTP error 412 (Precondition Failed) is
returned and no change is made. At that time the client code should
retrieve the object again, reconcile the changes and can try to send a
new update.
The etag is the md5 hash of the representation (repr()) of the object
retrieved from the database.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Fri, 01 Mar 2019 22:57:07 -0500 |
| parents | 32f95ec6bd8e |
| children | 1a835db41674 |
| rev | line source |
|---|---|
| 4083 | 1 """Exceptions for use in Roundup's web interface. |
| 2 """ | |
|
2129
3fd672293712
add and use Reject exception [SF#700265]
Richard Jones <richard@users.sourceforge.net>
parents:
2062
diff
changeset
|
3 |
|
3fd672293712
add and use Reject exception [SF#700265]
Richard Jones <richard@users.sourceforge.net>
parents:
2062
diff
changeset
|
4 __docformat__ = 'restructuredtext' |
|
3fd672293712
add and use Reject exception [SF#700265]
Richard Jones <richard@users.sourceforge.net>
parents:
2062
diff
changeset
|
5 |
| 4083 | 6 from roundup.exceptions import LoginError, Unauthorised |
|
2062
f6d7ccce8d96
cgi exceptions fix
Richard Jones <richard@users.sourceforge.net>
parents:
2052
diff
changeset
|
7 import cgi |
|
f6d7ccce8d96
cgi exceptions fix
Richard Jones <richard@users.sourceforge.net>
parents:
2052
diff
changeset
|
8 |
|
5264
32f95ec6bd8e
Python 2 and 3 support. Convert Exception into BaseException in core code.
John Rouillard <rouilj@ieee.org>
parents:
5079
diff
changeset
|
9 class HTTPException(BaseException): |
|
2004
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
10 pass |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
11 |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
12 class Redirect(HTTPException): |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
13 pass |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
14 |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
15 class NotFound(HTTPException): |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
16 pass |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
17 |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
18 class NotModified(HTTPException): |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
19 pass |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
20 |
|
5630
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5264
diff
changeset
|
21 class PreconditionFailed(HTTPException): |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5264
diff
changeset
|
22 pass |
|
07abc8d36940
Add etag support to rest interface to prevent multiple users from
John Rouillard <rouilj@ieee.org>
parents:
5264
diff
changeset
|
23 |
|
5264
32f95ec6bd8e
Python 2 and 3 support. Convert Exception into BaseException in core code.
John Rouillard <rouilj@ieee.org>
parents:
5079
diff
changeset
|
24 class DetectorError(BaseException): |
|
5079
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
4083
diff
changeset
|
25 """Raised when a detector throws an exception. |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
4083
diff
changeset
|
26 Contains details of the exception.""" |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
4083
diff
changeset
|
27 def __init__(self, subject, html, txt): |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
4083
diff
changeset
|
28 self.subject = subject |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
4083
diff
changeset
|
29 self.html = html |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
4083
diff
changeset
|
30 self.txt = txt |
|
65fef7858606
issue2550826 IOError in detector causes apache 'premature end of script headers' error
John Rouillard <rouilj@ieee.org>
parents:
4083
diff
changeset
|
31 |
|
2004
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
32 class FormError(ValueError): |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
33 """An 'expected' exception occurred during form parsing. |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
34 |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
35 That is, something we know can go wrong, and don't want to alarm the user |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
36 with. |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
37 |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
38 We trap this at the user interface level and feed back a nice error to the |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
39 user. |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
40 |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
41 """ |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
42 pass |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
43 |
|
5264
32f95ec6bd8e
Python 2 and 3 support. Convert Exception into BaseException in core code.
John Rouillard <rouilj@ieee.org>
parents:
5079
diff
changeset
|
44 class SendFile(BaseException): |
|
2004
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
45 """Send a file from the database.""" |
|
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
46 |
|
5264
32f95ec6bd8e
Python 2 and 3 support. Convert Exception into BaseException in core code.
John Rouillard <rouilj@ieee.org>
parents:
5079
diff
changeset
|
47 class SendStaticFile(BaseException): |
|
2004
1782fe36e7b8
Move out parts of client.py to new modules:
Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
parents:
diff
changeset
|
48 """Send a static file from the instance html directory.""" |
|
2052
78e6a1e4984e
forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents:
2004
diff
changeset
|
49 |
|
5264
32f95ec6bd8e
Python 2 and 3 support. Convert Exception into BaseException in core code.
John Rouillard <rouilj@ieee.org>
parents:
5079
diff
changeset
|
50 class SeriousError(BaseException): |
|
2052
78e6a1e4984e
forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents:
2004
diff
changeset
|
51 """Raised when we can't reasonably display an error message on a |
|
78e6a1e4984e
forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents:
2004
diff
changeset
|
52 templated page. |
|
78e6a1e4984e
forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents:
2004
diff
changeset
|
53 |
|
78e6a1e4984e
forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents:
2004
diff
changeset
|
54 The exception value will be displayed in the error page, HTML |
|
78e6a1e4984e
forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents:
2004
diff
changeset
|
55 escaped. |
|
78e6a1e4984e
forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents:
2004
diff
changeset
|
56 """ |
|
78e6a1e4984e
forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents:
2004
diff
changeset
|
57 def __str__(self): |
| 4083 | 58 return """ |
|
2052
78e6a1e4984e
forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents:
2004
diff
changeset
|
59 <html><head><title>Roundup issue tracker: An error has occurred</title> |
|
2278
93bd8c4d43ef
in HTML produced by SeriousError.__str__():
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2129
diff
changeset
|
60 <link rel="stylesheet" type="text/css" href="@@file/style.css"> |
|
2052
78e6a1e4984e
forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents:
2004
diff
changeset
|
61 </head> |
|
78e6a1e4984e
forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents:
2004
diff
changeset
|
62 <body class="body" marginwidth="0" marginheight="0"> |
|
78e6a1e4984e
forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents:
2004
diff
changeset
|
63 <p class="error-message">%s</p> |
|
78e6a1e4984e
forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents:
2004
diff
changeset
|
64 </body></html> |
| 4083 | 65 """%cgi.escape(self.args[0]) |
|
2052
78e6a1e4984e
forward-port from maint branch
Richard Jones <richard@users.sourceforge.net>
parents:
2004
diff
changeset
|
66 |
|
2924
df4a3355ee8f
added LoginError; fix vim modeline
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
2278
diff
changeset
|
67 # vim: set filetype=python sts=4 sw=4 et si : |
