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:
@@ -2,8 +2,8 @@
|
||||
<article id="comment_<%= comment.id %>" class="comment message"
|
||||
data-id="<%= comment.id %>"
|
||||
data-post-id="<%= comment.post_id %>"
|
||||
data-creator-id="<%= comment.creator_id %>"
|
||||
data-updater-id="<%= comment.updater_id %>"
|
||||
data-creator-id="<%= comment.creator_id unless redact_deleted? %>"
|
||||
data-updater-id="<%= comment.updater_id unless redact_deleted? %>"
|
||||
data-score="<%= comment.score %>"
|
||||
data-do-not-bump-post="<%= comment.do_not_bump_post? %>"
|
||||
data-is-deleted="<%= comment.is_deleted? %>"
|
||||
@@ -14,9 +14,13 @@
|
||||
data-is-voted="<%= comment.voted_by?(current_user) %>">
|
||||
<div class="author">
|
||||
<div class="author-name">
|
||||
<%= link_to_user comment.creator %>
|
||||
<% if comment.is_deleted? %>
|
||||
(deleted)
|
||||
<% if redact_deleted? %>
|
||||
[deleted]
|
||||
<% else %>
|
||||
<%= link_to_user comment.creator %>
|
||||
<% if comment.is_deleted? %>
|
||||
(deleted)
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
<%= link_to time_ago_in_words_tagged(comment.created_at), post_path(comment.post, anchor: "comment_#{comment.id}"), class: "message-timestamp" %>
|
||||
@@ -27,26 +31,34 @@
|
||||
<% end %>
|
||||
|
||||
<%= tag.div class: "body prose", style: ("display: none;" if thresholded?) do %>
|
||||
<%= format_text(comment.body, data: dtext_data) %>
|
||||
<% if redact_deleted? %>
|
||||
<p>[deleted]</p>
|
||||
<% else %>
|
||||
<%= format_text(comment.body, data: dtext_data) %>
|
||||
<% end %>
|
||||
|
||||
<%= render "application/update_notice", record: comment %>
|
||||
<% end %>
|
||||
|
||||
<% if policy(comment).create? %>
|
||||
<menu>
|
||||
<menu>
|
||||
<% if policy(comment).reply? %>
|
||||
<% if context == :index_by_comment %>
|
||||
<li><%= link_to "Reply", new_comment_path(id: comment, comment: { post_id: comment.post_id }), class: "reply-link" %></li>
|
||||
<% else %>
|
||||
<li><%= link_to "Reply", new_comment_path(id: comment, comment: { post_id: comment.post_id }), class: "reply-link", remote: true %></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if policy(comment).update? %>
|
||||
<% if comment.is_deleted? %>
|
||||
<li><%= link_to "Undelete", undelete_comment_path(comment.id), method: :post, remote: true %></li>
|
||||
<% else %>
|
||||
<li><%= link_to "Delete", comment_path(comment.id), "data-confirm": "Are you sure you want to delete this comment?", method: :delete, remote: true %></li>
|
||||
<% end %>
|
||||
<li><%= link_to "Edit", edit_comment_path(comment.id), id: "edit_comment_link_#{comment.id}", class: "edit_comment_link" %></li>
|
||||
<% if policy(comment).update? %>
|
||||
<% if comment.is_deleted? %>
|
||||
<li><%= link_to "Undelete", undelete_comment_path(comment.id), method: :post, remote: true %></li>
|
||||
<% else %>
|
||||
<li><%= link_to "Delete", comment_path(comment.id), "data-confirm": "Are you sure you want to delete this comment?", method: :delete, remote: true %></li>
|
||||
<% end %>
|
||||
<li><%= link_to "Edit", edit_comment_path(comment.id), id: "edit_comment_link_#{comment.id}", class: "edit_comment_link" %></li>
|
||||
<% end %>
|
||||
|
||||
<% if policy(comment).vote? %>
|
||||
<li class="comment-vote-up-link">
|
||||
<%= link_to "Vote up", comment_comment_votes_path(comment_id: comment.id, score: "up"), method: :post, remote: true %>
|
||||
</li>
|
||||
@@ -56,16 +68,19 @@
|
||||
<li class="comment-unvote-link">
|
||||
<%= link_to "Unvote", comment_comment_votes_path(comment_id: comment.id), method: :delete, remote: true %>
|
||||
</li>
|
||||
<% if policy(comment).reportable? %>
|
||||
<li><%= link_to "Report", new_moderation_report_path(moderation_report: { model_type: "Comment", model_id: comment.id }), remote: true %></li>
|
||||
<% end %>
|
||||
<% if has_moderation_reports? %>
|
||||
<li class="moderation-report-notice">This comment has been reported! (<%= link_to pluralize(comment.moderation_reports.length, "report"), moderation_reports_path(search: { model_type: "Comment", model_id: comment.id }) %>)</li>
|
||||
<% end %>
|
||||
</menu>
|
||||
<% if policy(comment).update? %>
|
||||
<%= render "comments/form", comment: comment, hidden: true %>
|
||||
<% end %>
|
||||
|
||||
<% if policy(comment).reportable? %>
|
||||
<li><%= link_to "Report", new_moderation_report_path(moderation_report: { model_type: "Comment", model_id: comment.id }), remote: true %></li>
|
||||
<% end %>
|
||||
|
||||
<% if has_moderation_reports? %>
|
||||
<li class="moderation-report-notice">This comment has been reported! (<%= link_to pluralize(comment.moderation_reports.length, "report"), moderation_reports_path(search: { model_type: "Comment", model_id: comment.id }) %>)</li>
|
||||
<% end %>
|
||||
</menu>
|
||||
|
||||
<% if policy(comment).update? %>
|
||||
<%= render "comments/form", comment: comment, hidden: true %>
|
||||
<% end %>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
Reference in New Issue
Block a user