Skip to content

Feature: Replace v1 comment routes with v2 routes#4804

Merged
sloria merged 45 commits into
CenterForOpenScience:release/0.61.0from
samanehsan:feature/v2-comments
Dec 22, 2015
Merged

Feature: Replace v1 comment routes with v2 routes#4804
sloria merged 45 commits into
CenterForOpenScience:release/0.61.0from
samanehsan:feature/v2-comments

Conversation

@samanehsan

Copy link
Copy Markdown
Contributor

Purpose

Replace existing API v1 routes with API v2 routes for comments.

Changes

In addition to changing the routes...

CommentSerialzer:

  • Add can_edit, has_children and is_abuse fields to the comment serializer
  • Add max_length to comment content field
  • Do not allow whitespace comments

Comment model:

  • create method 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.

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.
 into feature/v2-comments

Conflicts:
	api/comments/serializers.py
- 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 samanehsan changed the title Feature/v2 comments Feature: Replace v1 comment routes with v2 routes Dec 22, 2015
@sloria sloria added this to the 0.61.0 milestone Dec 22, 2015
@sloria

sloria commented Dec 22, 2015

Copy link
Copy Markdown
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
@sloria
sloria merged commit 3f246a6 into CenterForOpenScience:release/0.61.0 Dec 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants