Fix #4669: Track moderation report status.

* Add ability to mark moderation reports as 'handled' or 'rejected'.
* Automatically mark reports as handled when the comment or forum post
  is deleted.
* Send a dmail to the reporter when their report is handled.
* Don't show the report notice on comments or forum posts when all
  reports against it have been handled or rejected.
* Add a fix script to mark all existing reports for deleted comments,
  forum posts, or dmails as handled.
This commit is contained in:
evazion
2022-01-20 17:41:05 -06:00
parent 98aee048f2
commit c8d27c2719
20 changed files with 160 additions and 16 deletions

View File

@@ -243,6 +243,18 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest
assert_equal(true, @comment.reload.is_deleted)
assert_redirected_to @comment
end
should "mark all pending moderation reports against the comment as handled" do
@comment = create(:comment, post: @post)
report1 = create(:moderation_report, model: @comment, status: :pending)
report2 = create(:moderation_report, model: @comment, status: :rejected)
delete_auth comment_path(@comment.id), @mod
assert_redirected_to @comment
assert_equal(true, @comment.reload.is_deleted)
assert_equal(true, report1.reload.handled?)
assert_equal(true, report2.reload.rejected?)
end
end
context "undelete action" do

View File

@@ -229,6 +229,17 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest
assert_response 403
assert_equal(false, @forum_post.reload.is_deleted?)
end
should "mark all pending moderation reports against the post as handled" do
report1 = create(:moderation_report, model: @forum_post, status: :pending)
report2 = create(:moderation_report, model: @forum_post, status: :rejected)
delete_auth forum_post_path(@forum_post), @mod
assert_redirected_to(forum_post_path(@forum_post))
assert_equal(true, @forum_post.reload.is_deleted?)
assert_equal(true, report1.reload.handled?)
assert_equal(true, report2.reload.rejected?)
end
end
context "undelete action" do

View File

@@ -104,5 +104,32 @@ class ModerationReportsControllerTest < ActionDispatch::IntegrationTest
end
end
end
context "update action" do
should "not allow non-mods to update moderation reports" do
report = create(:moderation_report, model: @comment, creator: @user)
put_auth moderation_report_path(report), @user, params: { moderation_report: { status: "handled" }}, xhr: true
assert_response 403
end
should "allow a moderator to mark a moderation report as handled" do
report = create(:moderation_report, model: @comment, creator: @user)
put_auth moderation_report_path(report), @mod, params: { moderation_report: { status: "handled" }}, xhr: true
assert_response :success
assert_equal("handled", report.reload.status)
assert_equal(true, @user.dmails.received.exists?(from: User.system, title: "Thank you for reporting comment ##{@comment.id}"))
end
should "allow a moderator to mark a moderation report as rejected" do
report = create(:moderation_report, model: @comment, creator: @user)
put_auth moderation_report_path(report), @mod, params: { moderation_report: { status: "rejected" }}, xhr: true
assert_response :success
assert_equal("rejected", report.reload.status)
assert_equal(false, @user.dmails.received.exists?(from: User.system))
end
end
end
end