Check OAuth token in @webapi_check_local_site

Review Request #9079 — Created July 17, 2017 and submitted

Information

Review Board
release-3.0.x
b60473b...

Reviewers

This patch updates @webapi_check_local_site to ensure that if the user
is using an OAuth2 access token that it is valid for the current Local
Site.

Web API test mixins classes have been added so that this logic can be
tested for all resources.

Ran unit tests.

Description From Last Updated

It looks like you posted the wrong change here?

daviddavid

F401 'djblets.webapi.errors.NOT_LOGGED_IN' imported but unused

reviewbotreviewbot

Why is this commented out? Same below.

daviddavid

E303 too many blank lines (2)

reviewbotreviewbot

Here we compare directly against None, whereas below (in the next conditional), we just check truthiness. Is this correct? Or …

chipx86chipx86

The other logging statements are out of date. These should now have a request=request argument, and the three initial request.* …

chipx86chipx86

Swap these.

chipx86chipx86

This method should really be purely about setting things up to work with a Local Site. I don't think we …

chipx86chipx86

I don't really understand this. "Meant for a local site on the root"?

chipx86chipx86

The two Local Site-related assignments are redundant.

chipx86chipx86

These would be better as creates + IntegrityError checks. It'll keep query counts down (otherwise, we're doing 2 in most …

chipx86chipx86

E999 SyntaxError: invalid syntax

reviewbotreviewbot

E999 SyntaxError: invalid syntax

reviewbotreviewbot
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

david
  1. 
      
  2. reviewboard/webapi/tests/mixins.py (Diff revision 1)
     
     
    Show all issues

    Why is this commented out? Same below.

  3. 
      
brennie
Review request changed
brennie
david
  1. 
      
  2. Show all issues

    It looks like you posted the wrong change here?

  3. 
      
brennie
chipx86
  1. 
      
  2. reviewboard/webapi/decorators.py (Diff revision 4)
     
     
    Show all issues

    Here we compare directly against None, whereas below (in the next conditional), we just check truthiness. Is this correct? Or can we just check truthiness in both?

  3. reviewboard/webapi/decorators.py (Diff revision 4)
     
     
    Show all issues

    The other logging statements are out of date. These should now have a request=request argument, and the three initial request.* args should be removed. The logging handler will take care to log these details.

  4. reviewboard/webapi/tests/mixins.py (Diff revision 4)
     
     
     
    Show all issues

    Swap these.

  5. reviewboard/webapi/tests/mixins.py (Diff revision 4)
     
     
    Show all issues

    This method should really be purely about setting things up to work with a Local Site. I don't think we want to complicate it by then amking the usage of a Local Site optional. It seems that we only have the one basic test using this (and then the GET equivalent used the GET version of this test). Can we just change up the logic in those to use the non-site versions of this, and to perform the tests needed?

    This applies to the equivalent versions of this.

  6. reviewboard/webapi/tests/mixins.py (Diff revision 4)
     
     
     
    Show all issues

    I don't really understand this. "Meant for a local site on the root"?

    1. A local-site restricted token was used on the root, ie. /api/ instead of s/foo/api/

    2. Hmm, okay. It's the "with access to a local site ... meant for a local site on the root" that's confusing. It's still not completely clear to me what this is testing for, from the docstring alone. Is it the token meant for a local site that the user has access to, being used on /api/? Might be better to explicitly say /api/ instead of "root", and to maybe just get rid of the "with access to a local site" bit?

  7. reviewboard/webapi/tests/mixins.py (Diff revision 4)
     
     
     
     
     
    Show all issues

    The two Local Site-related assignments are redundant.

  8. Show all issues

    These would be better as creates + IntegrityError checks. It'll keep query counts down (otherwise, we're doing 2 in most cases now).

  9. 
      
brennie
Review request changed
Commit:
a93b44d74e75d235e09843a868e847fca5ecd97e
b60473b5ef7713aead80668421d9e6058b651ce9

Checks run (1 failed, 1 succeeded)

flake8 failed.
JSHint passed.

flake8

brennie
Review request changed
brennie
david
  1. Ship It!
  2. 
      
brennie
Review request changed
Status:
Completed
Change Summary:
Pushed to release-3.0.x (f738b53)