Respond to API requests with 503 when read-only mode
Review Request #8657 — Created Jan. 21, 2017 and submitted
Information | |
---|---|
khp | |
Review Board | |
master | |
|
|
8861, 8824, 8847, 8812, 8810, 8811, 8677 | |
e04ec08... | |
Reviewers | |
reviewboard, students | |
Read-only mode is a setting an admin can enable to prevent writes to
the database. This can be used when the site is under maintenence or
being upgraded. The previous commit added the siteconfig attribute and
a checkbox to toggle the mode. This commit adds a new 503 error to
Review Board's webapi. Furthermore, all requests that hit RB's API
usingPUT
,POST
,DELETE
methods while read-only mode is on, and
the user is not a superuser, will return the new 503 error. A utility
fileread_only.py
has been added which deals with the logic and
caching of determining when a user should be affected by read-only
mode.
Added new Python unit tests that send API requests as superuser and
non-superuser
Ran the Python unit test suite
Check that modifying/deleting review requests and comments works
properly
Description | From | Last Updated |
---|---|---|
Can you wrap your description at 72 characters? |
|
|
Col: 80 E501 line too long (80 > 79 characters) |
![]() |
|
request.user should always be an object. If the user is logged in, it will be a User. Otherwise it will … |
|
|
This needs a default value in reviewboard/admin/siteconfig.py |
|
|
The performance difference between set and tuple here is probably negligible, but we should probably just use tuple (i.e., ('POST', … |
|
|
'SiteConfiguration' imported but unused |
![]() |
|
Col: 1 E302 expected 2 blank lines, found 1 |
![]() |
|
Col: 39 E703 statement ends with a semicolon |
![]() |
|
Missing docstring. |
|
|
Docstrings for tests should begin with "Testing" |
|
|
Can you pass the boolean params as keywords? It makes the test cases clearer. |
|
|
Col: 45 E201 whitespace after '[' |
![]() |
|
How about "If read-only mode is enabled, all PUT, POST, and DELETE requests will be rejected with a 503 Service … |
|
|
"these" |
|
|
There are other mutable types of requests that may be supported down the road. I'd change this to request.method not … |
|
|
Can you verify that all unit tests for Review Board pass? My concern is that the siteconfig changes made in … |
|
|
Blank line between these. |
|
|
Blank line between these. |
|
|
Two blank lines. |
|
|
I don't know that we need to cache this, since SiteConfiguration.objects.get_current() will only hit the database the first time its … |
|
|
Docstring. |
|
-
-
reviewboard/webapi/base.py (Diff revision 1) request.user
should always be an object. If the user is logged in, it will be aUser
. Otherwise it will be anAnonymousUser
(for whichis_superuser
will beFalse
). -
reviewboard/webapi/base.py (Diff revision 1) This needs a default value in
reviewboard/admin/siteconfig.py
-
reviewboard/webapi/base.py (Diff revision 1) The performance difference between
set
andtuple
here is probably negligible, but we should probably just usetuple
(i.e.,('POST', 'PUT', 'DELETE')
).set
is (I believe) backed by a red-black tree and so will have to allocate memory for the nodes, as well as do bunch of other overhead work.
Change Summary:
Updated according to comments; formatting and update test by adding user to requests
Commit: |
|
||||
---|---|---|---|---|---|
Diff: |
Revision 2 (+117 -6) |

-
Tool: PEP8 Style Checker Processed Files: reviewboard/admin/siteconfig.py reviewboard/admin/forms.py reviewboard/webapi/tests/test_base.py reviewboard/webapi/errors.py reviewboard/webapi/base.py Tool: Pyflakes Processed Files: reviewboard/admin/siteconfig.py reviewboard/admin/forms.py reviewboard/webapi/tests/test_base.py reviewboard/webapi/errors.py reviewboard/webapi/base.py
-
reviewboard/webapi/tests/test_base.py (Diff revision 2) Col: 39 E703 statement ends with a semicolon

-
Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/base.py reviewboard/webapi/tests/test_base.py reviewboard/webapi/errors.py Tool: Pyflakes Processed Files: reviewboard/webapi/base.py reviewboard/webapi/tests/test_base.py reviewboard/webapi/errors.py
-
-
-
reviewboard/webapi/tests/test_base.py (Diff revision 3) Docstrings for tests should begin with "Testing"
-
reviewboard/webapi/tests/test_base.py (Diff revision 3) Can you pass the boolean params as keywords? It makes the test cases clearer.
Change Summary:
Updated with responses with Barret's comments. Also updated tests to include an argument for expected outcome instead of coding an expected behaviour into the test.
Diff: |
Revision 4 (+140 -5) |
---|

-
Tool: Pyflakes Processed Files: reviewboard/webapi/base.py reviewboard/webapi/tests/test_base.py reviewboard/webapi/errors.py Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/base.py reviewboard/webapi/tests/test_base.py reviewboard/webapi/errors.py
-

-
Tool: Pyflakes Processed Files: reviewboard/webapi/base.py reviewboard/webapi/tests/test_base.py reviewboard/webapi/errors.py Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/base.py reviewboard/webapi/tests/test_base.py reviewboard/webapi/errors.py
-
-
-
reviewboard/webapi/base.py (Diff revision 5) How about
"If read-only mode is enabled, all PUT, POST, and DELETE requests will be rejected with a 503 Service Unavailable unless the user is a superuser."
-
-
-
reviewboard/webapi/base.py (Diff revision 5) There are other mutable types of requests that may be supported down the road. I'd change this to
request.method not in ('GET', 'HEAD', 'OPTIONS')
, since those are all safe. -
reviewboard/webapi/tests/test_base.py (Diff revision 5) Can you verify that all unit tests for Review Board pass? My concern is that the
siteconfig
changes made in the unit tests could leak. Just in case, could you have thetearDown()
method resetsite_read_only
back to defaults? -
-
Change Summary:
Revised according to comments.
Description: |
|
||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Testing Done: |
|
||||||||||||||||||||||||
Diff: |
Revision 6 (+151 -5) |

-
Tool: Pyflakes Processed Files: reviewboard/webapi/base.py reviewboard/webapi/tests/test_base.py reviewboard/webapi/errors.py Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/base.py reviewboard/webapi/tests/test_base.py reviewboard/webapi/errors.py

-
Tool: Pyflakes Processed Files: reviewboard/webapi/base.py reviewboard/admin/read_only.py reviewboard/webapi/tests/test_base.py reviewboard/webapi/errors.py Tool: PEP8 Style Checker Processed Files: reviewboard/webapi/base.py reviewboard/admin/read_only.py reviewboard/webapi/tests/test_base.py reviewboard/webapi/errors.py
Description: |
|
---|
-
-
reviewboard/admin/read_only.py (Diff revision 7) I don't know that we need to cache this, since
SiteConfiguration.objects.get_current()
will only hit the database the first time its called. Every other call is cached. -