comments: rework deleted comments.

Let users see when a post has deleted comments. Show normal users a
'[deleted]' placeholder when a comment is deleted. Show the full comment
to moderators.

Also fix it so that the comment creator can't edit or undelete deleted
comments, and users can't vote on or report deleted comments.

Finally, hide the creator_id, updater_id, and body of deleted comments
in the API.
This commit is contained in:
evazion
2021-01-19 03:31:53 -06:00
parent 07bdc6eab0
commit e1e3604f46
7 changed files with 141 additions and 53 deletions

View File

@@ -26,6 +26,29 @@ class CommentComponentTest < ViewComponent::TestCase
end
end
context "for a deleted comment" do
setup do
@deleted_comment = as(create(:user)) { create(:comment, is_deleted: true) }
end
should "have the creator and body hidden for a Member" do
render_comment(@deleted_comment, current_user: @deleted_comment.creator)
assert_css("article[data-is-dimmed=true]")
assert_css("article .author-name", text: "[deleted]")
assert_css("article .body p", text: "[deleted]")
end
should "be visible for a Moderator" do
render_comment(@deleted_comment, current_user: create(:moderator_user))
assert_css("article[data-is-dimmed=true]")
assert_no_css("article .unhide-comment-link")
assert_css("article .author-name", text: @deleted_comment.creator.pretty_name)
assert_css("article .body p", text: @deleted_comment.body)
end
end
context "for a comment with moderation reports" do
should "show the report notice to moderators" do
create(:moderation_report, model: @comment)