Disable front-end features for read-only mode
Review Request #8810 — Created March 11, 2017 and submitted
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. This commit disables most UI features which would
normally affect Review Board, but under read-only mode, does not.
Disabling some features such as login and redirection when attempting
to view a read-only restricted page is contained in the next commit.This commit contains changes to the datagrid so changes to it does not
change profile settings, navbar (hide My Account and New Review Request
buttons), ETag, ReviewRequestEditor(including actions, comments, and
the editor itself),Other changes include adding read-only mode setting to the context
processor and adding a utility file containing the logic to determine
whether a user is in read-only mode or not.
- Check that caching of read-only mode is done correctly by changing
modes and refreshing pages - Check that profile doesn't save in datagrid when in read-only mode by
ensuring code doesn't reach the save method - Check that the review request actions available are appropriately
changed when in read-only mode - Check that comments can't be added or replied to in read-only mode
- Check that review requests can not be modified in read-only mode
- Check that modifying review requests (such as bugs or branch) when in
read-only mode while the site in browser is still old displayed an
appropriate error message - Check that modifying anything to the webapi doesn't send a request at
all when in read-only mode - Check that trying to add a comment through clicking on a line in diff
displays appropriate warning about read-only mode - Check that clicking on the Star does nothing in read-only mode
- Check that the above does not occur for admins
Description | From | Last Updated |
---|---|---|
Mind wrapping your description & testing done at 72 characters? Also, can you change your testing done to be bullet … |
brennie | |
'reverse' imported but unused |
reviewbot | |
'django_reset' imported but unused |
reviewbot | |
'from settings_local import *' used; unable to detect undefined names |
reviewbot | |
Missing args/returns. |
brennie | |
Missing: from __future__ import unicode_literals There must be a blank line between that import and any other imports. |
chipx86 | |
If you use the following, it will link to the class "the :py:class:`~djblets.siteconfig.models.SiteConfiguration`" |
brennie | |
We need to use full paths, e.g. django.contrib.auth.models.User |
brennie | |
If user.is_superuser is True, there's no reason to bother with a cache. That's just as fast. |
chipx86 | |
Missing args. |
brennie | |
Where does disable_save come from? Is there a change for Djblets that isn't up for review? It's better to have … |
chipx86 | |
Missing args. |
brennie | |
Let's pull out context['request'].user into a variable, so we're not doing the (actually fairly expensive, since context is not your … |
chipx86 | |
Indent this by two more spaces? |
szhang | |
Indent this by one space as well. |
szhang | |
Indent this by one space here? |
szhang | |
Let's move the read-only check last, as it's going to be less frequently a factor (it's more likely someone will … |
chipx86 | |
Same here. |
chipx86 | |
Move this after the if statement? Putting it before the if statement subtly gives the impression that the if statement … |
szhang | |
'django_reset' imported but unused |
reviewbot | |
'from settings_local import *' used; unable to detect undefined names |
reviewbot | |
Can you say why this happens? It's not going to be clear to people in the future that this means … |
chipx86 | |
Format as: ```javascript / * Comment * text / |
brennie | |
It'd be nice to only do this at one place. So instead, how about something like: if (rsp.fields === undefined) … |
chipx86 | |
No trailing comma. Since this isn't an ES6 JavaScript file, it will end up breaking some browsers (such as IE). |
chipx86 | |
Isn't there always a value returned for readOnly? We probably don't need to specify a default. |
chipx86 | |
We probably don't need to specify a default, since readOnly should always have a value. It would also be nice … |
chipx86 | |
We specify variables with values before variables without values. Also, I don't think we need a default here for readOnly. |
chipx86 | |
I'm unsure if this declaration should live here -- I don't think we do this anywhere else, really. Perhaps ping … |
brennie | |
Instead of this, can you just set actions to empty if in this mode? So: this.template({ ... actions: (this.showActions ? … |
chipx86 | |
Maybe it'd make more sense to have the other change built on top of this one instead. |
chipx86 | |
'django_reset' imported but unused |
reviewbot | |
'from settings_local import *' used; unable to detect undefined names |
reviewbot | |
Does is_site_read_only_for correctly handle user=None ? |
brennie | |
'django_reset' imported but unused |
reviewbot | |
'from settings_local import *' used; unable to detect undefined names |
reviewbot | |
Do we want this to be user-visible? Or is this only for debugging? |
brennie | |
This needs Args. It should also start off by saying the main thing that it does: "Saves the profile to … |
chipx86 | |
Parameters should align. This should also use format strings: console.log('%s request not sent ...', options.type); I'd also maybe use console.error … |
chipx86 | |
"The profile will only be saved if the user is not affected by read-only mode." |
brennie | |
Mind adding Args/Returns while you're here? |
brennie | |
Mind adding Args/Returns while you're here? |
brennie | |
Could you put the summary on the first line of the docstring? |
brennie | |
Mind adding Args/Returns while you're here? |
brennie | |
Instead of this, why not just readOnly: {% is_read_only|yesno:'true,false' %}, That way the information is always available. |
brennie |
- Testing Done:
-
+ Check that caching of read-only mode is done correctly by changing modes and refreshing pages
+ Check that profile doesn't save in datagrid when in read-only mode by ensuring code doesn't reach the save method + Check that the review request actions available are appropriately changed when in read-only mode + Check that comments can't be added or replied to in read-only mode + Check that review requests can not be modified in read-only mode + Check that modifying review requests (such as bugs or branch) when in read-only mode while the site in browser is still old displayed an appropriate error message + Check that modifying anything to the webapi doesn't send a request at all when in read-only mode + Check that trying to add a comment through clicking on a line in diff displays appropriate warning about read-only mode + Check that clicking on the Star does nothing in read-only mode + Check that the above does not occur for admins
-
Tool: Pyflakes Processed Files: reviewboard/reviews/views.py reviewboard/admin/read_only.py reviewboard/reviews/models/base_comment.py reviewboard/webapi/base.py reviewboard/reviews/default_actions.py reviewboard/reviews/models/review_request.py reviewboard/datagrids/grids.py reviewboard/admin/context_processors.py reviewboard/settings.py reviewboard/reviews/templatetags/reviewtags.py Ignored Files: reviewboard/static/rb/js/pages/views/dashboardView.js reviewboard/static/rb/js/views/starManagerView.js reviewboard/templates/reviews/review_reply_section.html reviewboard/templates/base/navbar.html reviewboard/static/rb/js/utils/apiUtils.es6.js reviewboard/templates/base.html reviewboard/templates/base/_nav_support_menu.html reviewboard/static/rb/js/models/userSessionModel.js reviewboard/static/rb/js/views/reviewRequestEditorView.js reviewboard/static/rb/js/models/reviewRequestEditorModel.js reviewboard/static/rb/js/views/commentDialogView.js reviewboard/static/rb/js/models/commentEditorModel.js Tool: PEP8 Style Checker Processed Files: reviewboard/reviews/views.py reviewboard/admin/read_only.py reviewboard/reviews/models/base_comment.py reviewboard/webapi/base.py reviewboard/reviews/default_actions.py reviewboard/reviews/models/review_request.py reviewboard/datagrids/grids.py reviewboard/admin/context_processors.py reviewboard/settings.py reviewboard/reviews/templatetags/reviewtags.py Ignored Files: reviewboard/static/rb/js/pages/views/dashboardView.js reviewboard/static/rb/js/views/starManagerView.js reviewboard/templates/reviews/review_reply_section.html reviewboard/templates/base/navbar.html reviewboard/static/rb/js/utils/apiUtils.es6.js reviewboard/templates/base.html reviewboard/templates/base/_nav_support_menu.html reviewboard/static/rb/js/models/userSessionModel.js reviewboard/static/rb/js/views/reviewRequestEditorView.js reviewboard/static/rb/js/models/reviewRequestEditorModel.js reviewboard/static/rb/js/views/commentDialogView.js reviewboard/static/rb/js/models/commentEditorModel.js
-
-
-
-
-
If you use the following, it will link to the class
"the :py:class:`~djblets.siteconfig.models.SiteConfiguration`"
-
-
-
-
We only require vars declared at the top for ES5 javascript (due to hoisting). It doesn't matter if you put this before or after the
if
statement. -
-
I'm unsure if this declaration should live here -- I don't think we do this anywhere else, really. Perhaps ping some other mentors about this.
-
-
Missing:
from __future__ import unicode_literals
There must be a blank line between that import and any other imports.
-
-
Where does
disable_save
come from? Is there a change for Djblets that isn't up for review?It's better to have options be positive rather than negative. For instance, "enable_save" vs. "disable_save." I'm not sure I love either, though.
There are lots of places where a
Profile
gets modified, and I don't think we should special-case every single place in existence. Instead, I'd overrideProfile.save
and have it not save ifis_site_read_only_for
returnsTrue
. That way, the DataGrid can try saving all it wants, but it won't matter. -
Let's pull out
context['request'].user
into a variable, so we're not doing the (actually fairly expensive, sincecontext
is not your standard kind ofdict
) lookup more than once.Same with all others that use this more than once.
-
Let's move the read-only check last, as it's going to be less frequently a factor (it's more likely someone will fail the other checks before this one).
-
-
Can you say why this happens? It's not going to be clear to people in the future that this means it's in read-only mode.
-
It'd be nice to only do this at one place. So instead, how about something like:
if (rsp.fields === undefined) { message = xhr.errorText; } else { /* All the stuff here for computing an error message below. */ } options.error.call(...);
-
No trailing comma. Since this isn't an ES6 JavaScript file, it will end up breaking some browsers (such as IE).
-
-
We probably don't need to specify a default, since
readOnly
should always have a value.It would also be nice to log something here to let anyone diagnosing things know that the request was ignored because it's in read-only mode.
-
We specify variables with values before variables without values.
Also, I don't think we need a default here for
readOnly
. -
Instead of this, can you just set actions to empty if in this mode? So:
this.template({ ... actions: (this.showActions ? this.actions : []), ... });
-
- Change Summary:
-
Changes according to comments. Still need to re-arrange commits to remove redundant changes.
- Diff:
-
Revision 3 (+196 -71)
-
Tool: Pyflakes Processed Files: reviewboard/reviews/views.py reviewboard/admin/read_only.py reviewboard/reviews/models/base_comment.py reviewboard/webapi/base.py reviewboard/reviews/default_actions.py reviewboard/reviews/models/review_request.py reviewboard/accounts/models.py reviewboard/admin/context_processors.py reviewboard/settings.py reviewboard/reviews/templatetags/reviewtags.py Ignored Files: reviewboard/static/rb/js/pages/views/dashboardView.js reviewboard/static/rb/js/views/starManagerView.js reviewboard/templates/reviews/review_reply_section.html reviewboard/templates/base/navbar.html reviewboard/static/rb/js/utils/apiUtils.es6.js reviewboard/templates/base.html reviewboard/templates/base/_nav_support_menu.html reviewboard/static/rb/js/models/userSessionModel.js reviewboard/static/rb/js/views/reviewRequestEditorView.js reviewboard/static/rb/js/models/reviewRequestEditorModel.js reviewboard/static/rb/js/views/commentDialogView.js reviewboard/static/rb/js/models/commentEditorModel.js Tool: PEP8 Style Checker Processed Files: reviewboard/reviews/views.py reviewboard/admin/read_only.py reviewboard/reviews/models/base_comment.py reviewboard/webapi/base.py reviewboard/reviews/default_actions.py reviewboard/reviews/models/review_request.py reviewboard/accounts/models.py reviewboard/admin/context_processors.py reviewboard/settings.py reviewboard/reviews/templatetags/reviewtags.py Ignored Files: reviewboard/static/rb/js/pages/views/dashboardView.js reviewboard/static/rb/js/views/starManagerView.js reviewboard/templates/reviews/review_reply_section.html reviewboard/templates/base/navbar.html reviewboard/static/rb/js/utils/apiUtils.es6.js reviewboard/templates/base.html reviewboard/templates/base/_nav_support_menu.html reviewboard/static/rb/js/models/userSessionModel.js reviewboard/static/rb/js/views/reviewRequestEditorView.js reviewboard/static/rb/js/models/reviewRequestEditorModel.js reviewboard/static/rb/js/views/commentDialogView.js reviewboard/static/rb/js/models/commentEditorModel.js
-
-
- Change Summary:
-
Moved read_only.py and webapi/base.py changes to previous diff, review #8657. Since the review is based on the old 8657 still, it will not show read_only.py and the webapi.py changes on this diff, but once it is applied on 8657 it should show.
- Diff:
-
Revision 4 (+164 -66)
-
Tool: Pyflakes Processed Files: reviewboard/reviews/views.py reviewboard/reviews/models/base_comment.py reviewboard/reviews/default_actions.py reviewboard/reviews/templatetags/reviewtags.py reviewboard/reviews/models/review_request.py reviewboard/accounts/models.py reviewboard/admin/context_processors.py reviewboard/settings.py Ignored Files: reviewboard/static/rb/js/pages/views/dashboardView.js reviewboard/static/rb/js/views/starManagerView.js reviewboard/templates/reviews/review_reply_section.html reviewboard/templates/base/navbar.html reviewboard/static/rb/js/utils/apiUtils.es6.js reviewboard/templates/base.html reviewboard/templates/base/_nav_support_menu.html reviewboard/static/rb/js/models/userSessionModel.js reviewboard/static/rb/js/views/reviewRequestEditorView.js reviewboard/static/rb/js/models/reviewRequestEditorModel.js reviewboard/static/rb/js/views/commentDialogView.js reviewboard/static/rb/js/models/commentEditorModel.js Tool: PEP8 Style Checker Processed Files: reviewboard/reviews/views.py reviewboard/reviews/models/base_comment.py reviewboard/reviews/default_actions.py reviewboard/reviews/templatetags/reviewtags.py reviewboard/reviews/models/review_request.py reviewboard/accounts/models.py reviewboard/admin/context_processors.py reviewboard/settings.py Ignored Files: reviewboard/static/rb/js/pages/views/dashboardView.js reviewboard/static/rb/js/views/starManagerView.js reviewboard/templates/reviews/review_reply_section.html reviewboard/templates/base/navbar.html reviewboard/static/rb/js/utils/apiUtils.es6.js reviewboard/templates/base.html reviewboard/templates/base/_nav_support_menu.html reviewboard/static/rb/js/models/userSessionModel.js reviewboard/static/rb/js/views/reviewRequestEditorView.js reviewboard/static/rb/js/models/reviewRequestEditorModel.js reviewboard/static/rb/js/views/commentDialogView.js reviewboard/static/rb/js/models/commentEditorModel.js
-
-
- Description:
-
~ 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. This commit disables most UI features which would normally affect Review Board, but under read-only mode, does not. Disabling some features such as login and redirection when attempting to view a read-only restricted page is contained in the next commit.
~ 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. This commit disables most UI features which would + normally affect Review Board, but under read-only mode, does not. + Disabling some features such as login and redirection when attempting + to view a read-only restricted page is contained in the next commit. ~ This commit contains changes to the datagrid so changes to it does not change profile settings, navbar (hide My Account and New Review Request buttons), ETag, ReviewRequestEditor(including actions, comments, and the editor itself),
~ This commit contains changes to the datagrid so changes to it does not
+ change profile settings, navbar (hide My Account and New Review Request + buttons), ETag, ReviewRequestEditor(including actions, comments, and + the editor itself), ~ Other changes include adding read-only mode setting to the context processor and adding a utility file containing the logic to determine whether a user is in read-only mode or not.
~ Other changes include adding read-only mode setting to the context
+ processor and adding a utility file containing the logic to determine + whether a user is in read-only mode or not. - Testing Done:
-
~ Check that caching of read-only mode is done correctly by changing modes and refreshing pages
~ Check that profile doesn't save in datagrid when in read-only mode by ensuring code doesn't reach the save method ~ Check that the review request actions available are appropriately changed when in read-only mode ~ Check that comments can't be added or replied to in read-only mode ~ Check that review requests can not be modified in read-only mode ~ Check that modifying review requests (such as bugs or branch) when in read-only mode while the site in browser is still old displayed an appropriate error message ~ Check that modifying anything to the webapi doesn't send a request at all when in read-only mode ~ Check that trying to add a comment through clicking on a line in diff displays appropriate warning about read-only mode ~ Check that clicking on the Star does nothing in read-only mode ~ Check that the above does not occur for admins ~ - Check that caching of read-only mode is done correctly by changing
modes and refreshing pages
~ - Check that profile doesn't save in datagrid when in read-only mode by
ensuring code doesn't reach the save method
~ - Check that the review request actions available are appropriately
changed when in read-only mode
~ - Check that comments can't be added or replied to in read-only mode
~ - Check that review requests can not be modified in read-only mode
~ - Check that modifying review requests (such as bugs or branch) when in
read-only mode while the site in browser is still old displayed an
appropriate error message
~ - Check that modifying anything to the webapi doesn't send a request at
all when in read-only mode
~ - Check that trying to add a comment through clicking on a line in diff
displays appropriate warning about read-only mode
~ - Check that clicking on the Star does nothing in read-only mode
~ - Check that the above does not occur for admins
- Check that caching of read-only mode is done correctly by changing
- Diff:
-
Revision 5 (+168 -66)
Checks run (2 succeeded, 1 failed with error)
-
-
This needs
Args
.It should also start off by saying the main thing that it does: "Saves the profile to the database."
Then, in the description, it should say that if the site is in read-only mode, the profile will not be saved.
-
Parameters should align.
This should also use format strings:
console.log('%s request not sent ...', options.type);
I'd also maybe use
console.error
instead.
- Diff:
-
Revision 6 (+178 -66)
Checks run (2 succeeded, 1 failed with error)
- Diff:
-
Revision 7 (+226 -70)