From 027359a2c1ea97c69b91ce9b7b8d68ab354ee40d Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 19 Jan 2021 06:05:51 -0600 Subject: [PATCH] comments: fix modreport notices being visible to Members. Fix the "This comment has been reported" notice being visible for Members. --- app/components/comment_component.rb | 2 +- app/policies/moderation_report_policy.rb | 4 ++++ test/components/comment_component_test.rb | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/components/comment_component.rb b/app/components/comment_component.rb index 1fbc085c4..fbae1fadf 100644 --- a/app/components/comment_component.rb +++ b/app/components/comment_component.rb @@ -24,6 +24,6 @@ class CommentComponent < ApplicationComponent end def has_moderation_reports? - policy(ModerationReport).show? && comment.moderation_reports.present? + policy(ModerationReport).can_see_moderation_reports? && comment.moderation_reports.present? end end diff --git a/app/policies/moderation_report_policy.rb b/app/policies/moderation_report_policy.rb index cbda4cbd6..2b1430a6b 100644 --- a/app/policies/moderation_report_policy.rb +++ b/app/policies/moderation_report_policy.rb @@ -11,6 +11,10 @@ class ModerationReportPolicy < ApplicationPolicy unbanned? && policy(record.model).reportable? end + def can_see_moderation_reports? + user.is_moderator? + end + def permitted_attributes [:model_type, :model_id, :reason] end diff --git a/test/components/comment_component_test.rb b/test/components/comment_component_test.rb index d5f329d58..601c1a490 100644 --- a/test/components/comment_component_test.rb +++ b/test/components/comment_component_test.rb @@ -58,7 +58,8 @@ class CommentComponentTest < ViewComponent::TestCase end should "not show the report notice to regular users" do - render_comment(@comment, current_user: User.anonymous) + create(:moderation_report, model: @comment) + render_comment(@comment, current_user: create(:user)) assert_no_css(".moderation-report-notice") end