Fix #4525: Show mod report notices next to reported content.

This commit is contained in:
evazion
2021-01-15 19:54:21 -06:00
parent 37792bd5dd
commit b4530183f4
20 changed files with 153 additions and 57 deletions

View File

@@ -1,14 +1,22 @@
# frozen_string_literal: true
class CommentComponent < ApplicationComponent
attr_reader :comment, :context, :dtext_data, :moderation_reports, :show_deleted, :current_user
attr_reader :comment, :context, :dtext_data, :show_deleted, :current_user
delegate :link_to_user, :time_ago_in_words_tagged, :format_text, :policy, to: :helpers
def initialize(comment:, context: nil, dtext_data: nil, moderation_reports: [], show_deleted: false, current_user: User.anonymous)
def self.with_collection(comments, current_user:, **options)
dtext_data = DText.preprocess(comments.map(&:body))
# XXX
#comments = comments.includes(:moderation_reports) if Pundit.policy!([current_user, nil], ModerationReport).show?
super(comments, current_user: current_user, dtext_data: dtext_data, **options)
end
# XXX calls to pundit policy don't respect current_user.
def initialize(comment:, current_user:, context: nil, dtext_data: nil, show_deleted: false)
@comment = comment
@context = context
@dtext_data = dtext_data
@moderation_reports = moderation_reports
@show_deleted = show_deleted
@current_user = current_user
end
@@ -16,4 +24,8 @@ class CommentComponent < ApplicationComponent
def render?
!comment.is_deleted? || show_deleted || current_user.is_moderator?
end
def has_moderation_reports?
policy(ModerationReport).show? && comment.moderation_reports.present?
end
end

View File

@@ -8,11 +8,9 @@
data-do-not-bump-post="<%= comment.do_not_bump_post? %>"
data-is-deleted="<%= comment.is_deleted? %>"
data-is-sticky="<%= comment.is_sticky? %>"
data-below-threshold="<%= comment.score < CurrentUser.user.comment_threshold %>"
<% if moderation_reports.present? && policy(moderation_reports).show? %>
data-is-reported="<%= moderation_reports.pluck(:model_id).include?(comment.id) %>"
<% end %>
data-is-voted="<%= comment.voted_by?(CurrentUser.user) %>">
data-below-threshold="<%= comment.score < current_user.comment_threshold %>"
data-is-reported="<%= has_moderation_reports? %>"
data-is-voted="<%= comment.voted_by?(current_user) %>">
<div class="author">
<div class="author-name">
<%= link_to_user comment.creator %>
@@ -56,6 +54,9 @@
<% 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 %>

View File

@@ -6,7 +6,7 @@ article.comment {
}
&[data-is-reported="true"] {
border: var(--moderation-report-border);
background-color: var(--moderation-report-background-color);
}
&[data-is-voted="true"] {
@@ -28,4 +28,9 @@ article.comment {
opacity: 1;
}
}
.moderation-report-notice {
font-weight: bold;
color: var(--moderation-report-text-color);
}
}

View File

@@ -6,15 +6,28 @@ class ForumPostComponent < ApplicationComponent
with_collection_parameter :forum_post
def initialize(forum_post:, original_forum_post_id: nil, dtext_data: nil, moderation_reports: [], current_user: User.anonymous)
def self.with_collection(forum_posts, forum_topic:, current_user:)
dtext_data = DText.preprocess(forum_posts.map(&:body))
original_forum_post_id = forum_topic.original_post&.id
forum_posts = forum_posts.includes(:creator, :bulk_update_request)
forum_posts = forum_posts.includes(:moderation_reports) if Pundit.policy!([current_user, nil], ModerationReport).show?
super(forum_posts, dtext_data: dtext_data, original_forum_post_id: original_forum_post_id, current_user: current_user)
end
def initialize(forum_post:, original_forum_post_id: nil, dtext_data: nil, current_user: User.anonymous)
@forum_post = forum_post
@original_forum_post_id = original_forum_post_id
@dtext_data = dtext_data
@moderation_reports = moderation_reports
@current_user = current_user
end
def render?
policy(forum_post).show_deleted?
end
def has_moderation_reports?
policy(ModerationReport).show? && forum_post.moderation_reports.present?
end
end

View File

@@ -1,8 +1,6 @@
<article class="forum-post message" id="forum_post_<%= forum_post.id %>"
data-forum-post-id="<%= forum_post.id %>"
<% if policy(moderation_reports).show? %>
data-is-reported="<%= moderation_reports.pluck(:model_id).include?(forum_post.id) %>"
<% end %>
data-is-reported="<%= has_moderation_reports? %>"
data-creator="<%= forum_post.creator.name %>">
<div class="author">
@@ -42,6 +40,9 @@
<% if policy(forum_post).reportable? %>
<li><%= link_to "Report", new_moderation_report_path(moderation_report: { model_type: "ForumPost", model_id: forum_post.id }), remote: true, title: "Report this forum post to the moderators" %></li>
<% end %>
<% if has_moderation_reports? %>
<li class="moderation-report-notice">This post has been reported! (<%= link_to pluralize(forum_post.moderation_reports.length, "report"), moderation_reports_path(search: { model_type: "ForumPost", model_id: forum_post.id }) %>)</li>
<% end %>
<% if forum_post.bulk_update_request.present? %>
<ul class="votes" id="forum-post-votes-for-<%= forum_post.id %>">
<%= render "forum_post_votes/list", votes: forum_post.votes, forum_post: forum_post %>

View File

@@ -1,6 +1,6 @@
article.forum-post {
&[data-is-reported="true"] {
border: var(--moderation-report-border);
background-color: var(--moderation-report-background-color);
}
a.voted {
@@ -30,4 +30,9 @@ article.forum-post {
}
}
}
.moderation-report-notice {
font-weight: bold;
color: var(--moderation-report-text-color);
}
}