diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c191d183..538b07159 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ * Removed the option to disable tag autocomplete. +* You can now see the list of comments and forum posts you've reported to + the moderators at . + ## 2021-01-12 ### Changes diff --git a/app/models/moderation_report.rb b/app/models/moderation_report.rb index f7a3312dc..bafe41b83 100644 --- a/app/models/moderation_report.rb +++ b/app/models/moderation_report.rb @@ -20,6 +20,14 @@ class ModerationReport < ApplicationRecord MODEL_TYPES end + def self.visible(user) + if user.is_moderator? + all + else + where(creator: user) + end + end + def forum_topic_title "Reports requiring moderation" end @@ -74,10 +82,6 @@ class ModerationReport < ApplicationRecord end end - def self.visible(user) - user.is_moderator? ? all : none - end - def self.search(params) q = search_attributes(params, :id, :created_at, :updated_at, :reason, :creator, :model) q = q.text_attribute_matches(:reason, params[:reason_matches]) diff --git a/app/policies/moderation_report_policy.rb b/app/policies/moderation_report_policy.rb index 146335ba1..cbda4cbd6 100644 --- a/app/policies/moderation_report_policy.rb +++ b/app/policies/moderation_report_policy.rb @@ -1,10 +1,10 @@ class ModerationReportPolicy < ApplicationPolicy def index? - user.is_moderator? + !user.is_anonymous? end def show? - user.is_moderator? + !user.is_anonymous? end def create? diff --git a/test/functional/moderation_reports_controller_test.rb b/test/functional/moderation_reports_controller_test.rb index ff9af203c..ece56f024 100644 --- a/test/functional/moderation_reports_controller_test.rb +++ b/test/functional/moderation_reports_controller_test.rb @@ -34,9 +34,21 @@ class ModerationReportsControllerTest < ActionDispatch::IntegrationTest end context "as a user" do - should "render the access denied page" do + should "show reports submitted by the current user" do get_auth moderation_reports_path, @user - assert_response 403 + + assert_response :success + assert_select "tbody tr", count: 2 + assert_select "tr#moderation-report-#{@comment_report.id}", count: 1 + assert_select "tr#moderation-report-#{@forum_report.id}", count: 1 + assert_select "tr#moderation-report-#{@dmail_report.id}", count: 0 + end + + should "not show reports submitted by other users" do + get_auth moderation_reports_path, create(:user) + + assert_response :success + assert_select "tbody tr", count: 0 end end