Redirect some views in read-only mode, hide links to these views

Review Request #8811 — Created March 11, 2017 and submitted

khp
Review Board
master
8648, 8657, 8810
8861, 8824, 8847, 8812
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. This commit adds a decorator that wraps
login_required. If no arguments are passed into the new
login_required it will behave the same as django's login_required.
If a boolean value for redirect_read_only is set to true, a decorator
that checks whether the user is in read-only mode and should redirect
will be returned.

"New Review Request" and "My Accounts" now redirect to a Read-Only page
and "Register" redirects to "Log-in". Buttons to these pages are
removed for users affected in read-only mode.

  • Check that accessing New Review Request and My Accounts redirects to
    503 page logged in as non-admin in read-only mode
  • Check that accessing Register when logged in or not redirects to the
    log-in page
  • Check that links to New Review/My Accounts/Register are removed for
    non-admins/unauthenticated users
  • Check that submitting Register form when in read-only mode does not
    do any writes
Description From Last Updated

Mind wrapping your description & testing done at 72 characters?

brenniebrennie

Col: 80 E501 line too long (82 > 79 characters)

reviewbotreviewbot

'django_login_required' imported but unused

reviewbotreviewbot

Col: 80 E501 line too long (82 > 79 characters)

reviewbotreviewbot

Col: 5 E128 continuation line under-indented for visual indent

reviewbotreviewbot

Col: 5 E128 continuation line under-indented for visual indent

reviewbotreviewbot

Needs Args and Returns. The return type here is callable.

brenniebrennie

No blank line here.

brenniebrennie

No blank line here.

brenniebrennie

No blank line here.

brenniebrennie

We prefer to use a hanging indent here. Reformat as: if (auth_backends[0].supports_registration and siteconfig.get('auth_enable_registration') and not siteconfig.get('site_read_only')): Also, mind changing ...

brenniebrennie

The request arg is not used, so I don't think we need to have it here. It can live in ...

brenniebrennie

Comments should end with a period.

brenniebrennie

redefinition of unused 'login_required' from line 3

reviewbotreviewbot
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/reviews/views.py
        reviewboard/accounts/decorators.py
        reviewboard/accounts/views.py
        reviewboard/urls.py
    
    Ignored Files:
        reviewboard/templates/503.html
        reviewboard/templates/accounts/login.html
        reviewboard/templates/base/_nav_support_menu.html
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/reviews/views.py
        reviewboard/accounts/decorators.py
        reviewboard/accounts/views.py
        reviewboard/urls.py
    
    Ignored Files:
        reviewboard/templates/503.html
        reviewboard/templates/accounts/login.html
        reviewboard/templates/base/_nav_support_menu.html
    
    
  2. reviewboard/accounts/decorators.py (Diff revision 1)
     
     
    Col: 80
     E501 line too long (82 > 79 characters)
    
  3. reviewboard/accounts/views.py (Diff revision 1)
     
     
     'django_login_required' imported but unused
    
  4. reviewboard/accounts/views.py (Diff revision 1)
     
     
    Col: 80
     E501 line too long (82 > 79 characters)
    
  5. reviewboard/urls.py (Diff revision 1)
     
     
    Col: 5
     E128 continuation line under-indented for visual indent
    
  6. reviewboard/urls.py (Diff revision 1)
     
     
    Col: 5
     E128 continuation line under-indented for visual indent
    
  7. 
      
KH
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/reviews/views.py
        reviewboard/accounts/decorators.py
        reviewboard/accounts/views.py
        reviewboard/urls.py
    
    Ignored Files:
        reviewboard/templates/503.html
        reviewboard/templates/accounts/login.html
        reviewboard/templates/base/_nav_support_menu.html
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/reviews/views.py
        reviewboard/accounts/decorators.py
        reviewboard/accounts/views.py
        reviewboard/urls.py
    
    Ignored Files:
        reviewboard/templates/503.html
        reviewboard/templates/accounts/login.html
        reviewboard/templates/base/_nav_support_menu.html
    
    
  2. 
      
brennie
  1. 
      
  2. reviewboard/accounts/decorators.py (Diff revision 2)
     
     

    Needs Args and Returns. The return type here is callable.

  3. reviewboard/accounts/decorators.py (Diff revision 2)
     
     

    No blank line here.

  4. 
      
KH
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/reviews/views.py
        reviewboard/accounts/decorators.py
        reviewboard/accounts/views.py
        reviewboard/urls.py
    
    Ignored Files:
        reviewboard/templates/503.html
        reviewboard/templates/accounts/login.html
        reviewboard/templates/base/_nav_support_menu.html
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/reviews/views.py
        reviewboard/accounts/decorators.py
        reviewboard/accounts/views.py
        reviewboard/urls.py
    
    Ignored Files:
        reviewboard/templates/503.html
        reviewboard/templates/accounts/login.html
        reviewboard/templates/base/_nav_support_menu.html
    
    
  2. 
      
brennie
  1. Just a few nits.

  2. Mind wrapping your description & testing done at 72 characters?

  3. reviewboard/accounts/decorators.py (Diff revision 3)
     
     

    No blank line here.

  4. reviewboard/accounts/decorators.py (Diff revision 3)
     
     

    No blank line here.

  5. reviewboard/accounts/views.py (Diff revision 3)
     
     
     
     

    We prefer to use a hanging indent here. Reformat as:

    if (auth_backends[0].supports_registration and
        siteconfig.get('auth_enable_registration') and
        not siteconfig.get('site_read_only')):
    

    Also, mind changing that other string to single quotes?

  6. reviewboard/accounts/views.py (Diff revision 3)
     
     

    The request arg is not used, so I don't think we need to have it here. It can live in *args.

  7. reviewboard/urls.py (Diff revision 3)
     
     

    Comments should end with a period.

  8. 
      
KH
Review request changed

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 adds a decorator that wraps login_required. If no arguments are passed into the new login_required it will behave the same as django's login_required. If a boolean value for redirect_read_only is set to true, a decorator that checks whether the user is in read-only mode and redirect apprpriately will be returned.

  ~

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 adds a decorator that wraps
  + login_required. If no arguments are passed into the new
  + login_required it will behave the same as django's login_required.
  + If a boolean value for redirect_read_only is set to true, a decorator
  + that checks whether the user is in read-only mode and should redirect
  + will be returned.

   
~  

"New Review Request" and "My Accounts" now redirect to a Read-Only page and "Register" redirects to "Log-in". Buttons to these pages are removed for users affected in read-only mode.

  ~

"New Review Request" and "My Accounts" now redirect to a Read-Only page

  + and "Register" redirects to "Log-in". Buttons to these pages are
  + removed for users affected in read-only mode.

Testing Done:

~  

Check that accessing New Review Request and My Accounts redirects to 503 page logged in as non-admin in read-only mode

~   Check that accessing Register when logged in or not redirects to the log-in page
~   Check that links to New Review/My Accounts/Register are removed for non-admins/unauthenticated users
~   Check that submitting Register form when in read-only mode does not do any writes

  ~
  • Check that accessing New Review Request and My Accounts redirects to
    503 page logged in as non-admin in read-only mode
  ~
  • Check that accessing Register when logged in or not redirects to the
    log-in page
  ~
  • Check that links to New Review/My Accounts/Register are removed for
    non-admins/unauthenticated users
  ~
  • Check that submitting Register form when in read-only mode does not
    do any writes

Diff:

Revision 4 (+92 -8)

Show changes

Checks run (1 failed, 1 succeeded, 1 failed with error)

JSHint passed.
PEP8 Style Checker internal error.
Pyflakes failed.

Pyflakes

KH
KH
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-4.0.x (e0e7431)
Loading...