-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
APIv3 CRUD for Redirect objects #5879
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6f9302c
Follow same pattern of .api method for RedirectQuerySet as well
humitos 04e675f
APIv3 CRUD for Redirect objects
humitos 89d2cb0
Split Redirect serializer to allow sanitize fields
humitos 37663c5
Small queryset optimization (select_related)
humitos e1e92d3
Small optimization on base has_admin_permission check
humitos f9346d3
Include 'redirects' in '_links' responses
humitos 1dacb63
Add some tests for Redirect endpoints
humitos ba2dfe2
Test for PUTi and DELETE methods
humitos 213db7f
Rename `redirect_type` to `type` in the APIv3 response
humitos ba61d0c
Small lint fix
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
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
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
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
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
13 changes: 13 additions & 0 deletions
13
readthedocs/api/v3/tests/responses/projects-redirects-detail.json
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"_links": { | ||
"_self": "https://readthedocs.org/api/v3/projects/project/redirects/1/", | ||
"project": "https://readthedocs.org/api/v3/projects/project/" | ||
}, | ||
"created": "2019-04-29T10:00:00Z", | ||
"modified": "2019-04-29T12:00:00Z", | ||
"from_url": "/docs/", | ||
"pk": 1, | ||
"project": "project", | ||
"type": "page", | ||
"to_url": "/documentation/" | ||
} |
13 changes: 13 additions & 0 deletions
13
readthedocs/api/v3/tests/responses/projects-redirects-detail_PUT.json
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"_links": { | ||
"_self": "https://readthedocs.org/api/v3/projects/project/redirects/1/", | ||
"project": "https://readthedocs.org/api/v3/projects/project/" | ||
}, | ||
"created": "2019-04-29T10:00:00Z", | ||
"modified": "2019-04-29T12:00:00Z", | ||
"from_url": "/changed/", | ||
"pk": 1, | ||
"project": "project", | ||
"type": "page", | ||
"to_url": "/toanother/" | ||
} |
20 changes: 20 additions & 0 deletions
20
readthedocs/api/v3/tests/responses/projects-redirects-list.json
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"count": 1, | ||
"next": null, | ||
"previous": null, | ||
"results": [ | ||
{ | ||
"_links": { | ||
"_self": "https://readthedocs.org/api/v3/projects/project/redirects/1/", | ||
"project": "https://readthedocs.org/api/v3/projects/project/" | ||
}, | ||
"created": "2019-04-29T10:00:00Z", | ||
"modified": "2019-04-29T12:00:00Z", | ||
"from_url": "/docs/", | ||
"pk": 1, | ||
"project": "project", | ||
"type": "page", | ||
"to_url": "/documentation/" | ||
} | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
readthedocs/api/v3/tests/responses/projects-redirects-list_POST.json
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"_links": { | ||
"_self": "https://readthedocs.org/api/v3/projects/project/redirects/2/", | ||
"project": "https://readthedocs.org/api/v3/projects/project/" | ||
}, | ||
"created": "2019-04-29T10:00:00Z", | ||
"modified": "2019-04-29T12:00:00Z", | ||
"from_url": "/page/", | ||
"pk": 2, | ||
"project": "project", | ||
"type": "page", | ||
"to_url": "/another/" | ||
} |
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
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
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
Oops, something went wrong.
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.
This permission seems to be generating something like 6 extra queries which was surprising. However, it is not generating N queries where N is the number of redirects.
Uh oh!
There was an error while loading. Please reload this page.
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.
Well, this is the basic permission check that we need in all the endpoints for user admin of a project. I split it here to make it simpler and have it isolated.
So, if this check is slow, we should take care of it since it's used a on most of the endpoints.
Basically, it does:
Project.objects.filter(users__in=[user])
I think we can use
.only('id')
inProjectQuerySetMixin.has_admin_permission
in the if, to avoid bringing the full objects since we only want to make a simple check.In my very simple local tests, there is a timing difference. I'll add a commit for this.
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.
Also, some of these method are called more than once (at least for the BrowsableAPIRenderer) and returned value won't change in the same request, so we could do something there if we care enough.
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.
Overall it probably isn't a big deal either way. Some number of queries is necessary for the permission check but 6 just seemed high. I do wonder if we shouldn't just cache the project object onto the view object since most of our views relate to projects.
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 think we can optimize it later if needed --I think it's a good option. Although, I don't want to introduce a "buggy cached object" at this point before knowing that everything is working as we expect :)
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'm ok with that for now. Let's keep it in mind though.