Skip to content

Conversation

@samanehsan
Copy link
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.

Note: This pull request cannot be merged until the v2 API supports anonymous view only links

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
@samanehsan samanehsan changed the title Feature/v2 comments [WIP] Feature/v2 comments Dec 8, 2015
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.
@samanehsan
Copy link
Contributor Author

Done making those changes @sloria! 😎

Copy link
Contributor

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.

Copy link
Contributor

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.

@sloria
Copy link
Contributor

sloria commented Dec 18, 2015

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.
@samanehsan
Copy link
Contributor Author

We should also have validation at the model layer. If content is not allowed to be blank, then a validator should be added to the content field.

I added an ODM validator for checking that a field is not empty: cos-archives/modular-odm#126

But then I found a string_required validator in validators.py: https://github.com/CenterForOpenScience/osf.io/blob/develop/framework/mongo/validators.py#L8

Should I use the string_required validator since it's already there?

@samanehsan
Copy link
Contributor Author

Do you mean that these methods should check that the user is able to edit, delete, etc.?

For consistency with the reset of the codebase, comment.edit, comment.delete etc. should do permissions checks, and ValidationError should be handled here.

@sloria
Copy link
Contributor

sloria commented Dec 21, 2015

Should I use the string_required validator since it's already there?

Yes.

Do you mean that these methods should check that the user is able to edit, delete, etc.?

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.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samanehsan samanehsan force-pushed the feature/v2-comments branch 3 times, most recently from 9a1ea99 to 8063686 Compare December 21, 2015 16:04
Handle PermissionsErrors in comment serializer
methods.
@samanehsan
Copy link
Contributor Author

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.
@sloria
Copy link
Contributor

sloria commented Dec 22, 2015

Closing in favor of #4804

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.

3 participants