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