-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Use ServeDocsPermissionsMixin to isolate this methods and be more clear #6408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
60b121f
Use ServeDocsPermissionsMixin to isolate this methods and be more clear
humitos 730437f
Merge branch 'master' of github.com:readthedocs/readthedocs.org into …
humitos 3ed963c
Merge branch 'master' of github.com:readthedocs/readthedocs.org into …
humitos 9c0d28f
Default allowed_user to False and re-define when needed
humitos d0b8cd6
Merge branch 'master' into humitos/use-doc-permission-mixin
humitos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,3 +154,38 @@ def get_redirect_response(self, request, redirect_path, http_status): | |
return HttpResponsePermanentRedirect(new_path) | ||
|
||
return HttpResponseRedirect(new_path) | ||
|
||
|
||
class ServeDocsPermissionsMixin: | ||
|
||
""" | ||
Mixin to handle documentation permissions. | ||
|
||
To use this mixin, the method that serve the docs should call | ||
``allowed_user`` first to check if the user requesting to read the page is | ||
allowed. If allowed, the flow should continue. | ||
|
||
On the other hand, if the user is not allowed, the serve docs method MUST | ||
break the flow and return a call to ``get_unauthed_response``. | ||
""" | ||
|
||
def allowed_user(self, request, project, version_slug): | ||
""" | ||
Return whether the user is allowed to read this documentation's version. | ||
|
||
:returns: ``True`` if allowed. ``False`` otherwise. | ||
:rtype: bool | ||
""" | ||
return False | ||
|
||
def get_unauthed_response(self, request, project): | ||
""" | ||
Return response for an unauthed hit at a documentation's version. | ||
|
||
When a user does not have access to read documentation, we need to | ||
return a response showing the proper message. This method produces that | ||
reponse. | ||
|
||
:rtype: django.http.HttpResponse | ||
""" | ||
return self._serve_401(request, project) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand what this is meant to be doing. Are we using these additional methods, or are they just meant to be overwritten?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are overriding these methods from corporate. They are meant to be overwritten.
This PR just move them outside the main class and put them into a mixin with better docstrings. Which is easier to understand where they come from. That's all.
I could move the docstrings to the Base class, otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@humitos I think I ended up doing most of this PR in #6572 -- we should get this merged and combined with that one 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ericholscher see https://github.com/readthedocs/readthedocs.org/pull/6572/files#r371770894
I'm fine with either. I think defaulting to
False
and force re-define it, it's safer, though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, it should default False 👍