Feature: Replace v1 comment routes with v2 routes#4804
Merged
sloria merged 45 commits intoDec 22, 2015
Conversation
Add can_edit, has_children and is_abuse fields to the API v2 comment serializer.
Since the v2 comment serializer does not include serializied information about the commenter (and embedded requests have not yet been implemented), iterate through the serialized comments, make a request to get commenter info and then create a CommentModel based on the updated response.
Because the v1 route is being removed, move the logic for calling notify when a comment is added to a separate function that receives the 'comment-added' signal sent from Comment.create.
Handle case where auth is None or the user is an anonymous user.
Also, add a test to ensure that html tags are removed from the content.
Remove query string since it is already passed in as a query parameter.
Ensure that when a comment is edited, it cannot exceed the max length or be empty.
Ensure self.abuseText() defaults to an empty string. Also fix checking whether a user is anoymous in the is_abuse serializer method field.
Check if auth or if user is anonymous before comparing the commenter and user by id
Remove v1 routes for create, edit, delete and undelete for comments and tests.
When finding unread comments for a user on a node, look for comments created since comments_viewed_timestamp OR edited since then (instead of AND). Also exclude any deleted comments and add tests for the model method now that the view method tests have been removed. Fixes [#OSF-5193]
Every time comment replies are fetched instead of pushing the comment model to the array (that already contains the comment) re-assign the value of self.comments to the result of the fetch.
Change updateCommentsUserData to handle a single comment (from when a comment is added) or a list of comments (from fetching comment data).
Instead of making a separate request to get the data for every comment's user, embed that information in the request for the list of nodes.
Specify the comment target and type in the POST request
When a POST request is made to create a new comment or reply, the commenter's info is not embedded in the response. Get the current user's author info in CommentListModel (where the comments list gets fetched) so that whenever the user makes a comment, their info can be added to the CommentModel.
- Make methods that do async requests return promises. - Log unexpected errors to Sentry - Make setUnreadCommentCount a method of BaseComment
Instead of making a request to get the current user's information, get the info off of contextVars and pass it in to the model.
Instead of checking that the value is not empty in the create and update methods, use a field validator. Note: the trim_whitespace parameter gets applied after validation, allowing whitespace comments so a custom field validator is needed.
Since empty comments are not allowed, add validation to the comment model as well. Add tests to check that a validation error is raised when trying to create an empty or whitespace comment. Also test that comments with content=None throw a validation error.
Also make the string_required validator trim whitespace and then check that the string is empty.
Handle PermissionsErrors in comment serializer methods.
If a user is viewing a project through a VOL, pass the private_key to the API request to get comments.
samanehsan
force-pushed
the
feature/v2-comments
branch
from
December 22, 2015 15:36
822c038 to
3009537
Compare
Contributor
|
Reviewed in #4702 -- Looks good to merge. |
sloria
added a commit
that referenced
this pull request
Dec 22, 2015
Feature: Replace v1 comment routes with v2 routes
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Purpose
Replace existing API v1 routes with API v2 routes for comments.
Changes
In addition to changing the routes...
CommentSerialzer:
can_edit,has_childrenandis_abusefields to the comment serializerComment model:
createmethod sends a signal to send the notification event, since that logic was happening in the v1 create view function which is no longer being used.Side Effects
Instead of escaping html in comments and making it a string, it gets removed entirely by DRF. E.g. the comment
"<em>hi</em>"would be"hi"instead.