-
Notifications
You must be signed in to change notification settings - Fork 350
[Ready for Review] Feature: Replace v1 comment routes with v2 routes #4702
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
[Ready for Review] Feature: Replace v1 comment routes with v2 routes #4702
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
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.
|
Done making those changes @sloria! 😎 |
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.
It would also be useful to test content that only has whitespace characters in it.
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.
Ah, but I see you've done that in TestNodeCommentsList#test_create_comment_trims_whitespace.
|
Pass finished. |
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.
I added an ODM validator for checking that a field is not empty: cos-archives/modular-odm#126 But then I found a Should I use the |
|
Do you mean that these methods should check that the user is able to edit, delete, etc.?
|
Yes.
Yes, although I now see that my original suggestion may be incorrect; a PermissionsError--not a ValidationError--should be raised. |
Also make the string_required validator trim whitespace and then check that the string is empty.
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.
Minor: It's safer to check self.id() ? 'comments' : 'nodes'; that will ensure you get the correct value if self.id() is either undefined or null.
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.
These lines get changed when I add in file comments: https://github.com/samanehsan/osf.io/blob/feature/file-comments-v2-merge/website/static/js/comment.js#L231-L232
9a1ea99 to
8063686
Compare
Handle PermissionsErrors in comment serializer methods.
8063686 to
37d6cdf
Compare
|
Done making those changes @sloria! ⭐ |
If a user is viewing a project through a VOL, pass the private_key to the API request to get comments.
822c038 to
3009537
Compare
|
Closing in favor of #4804 |
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.Note: This pull request cannot be merged until the v2 API supports anonymous view only links