From 72e95b6ca3cfce16f08d7e7cdcb74ee262d6b40f Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 18 Sep 2022 15:43:05 -0500 Subject: [PATCH] flags: allow approvers to bypass the "can't flag more than once in 3 days" rule. Allow approvers to bypass the rule that you can't flag a post again if it was flagged less than 3 days ago. This rule was intended to prevent flag warring among regular users, which hopefully shouldn't be a problem among approvers. It was also useless because approvers could always just directly delete the post even if they couldn't flag it. Allowing approvers to reflag posts allows them to reinstate flags that were accidentally approved. --- app/models/post_flag.rb | 2 +- test/unit/post_flag_test.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/models/post_flag.rb b/app/models/post_flag.rb index b207958fd..96a7a406f 100644 --- a/app/models/post_flag.rb +++ b/app/models/post_flag.rb @@ -109,7 +109,7 @@ class PostFlag < ApplicationRecord errors.add(:post, "is deleted and cannot be flagged") if post.is_deleted? && !is_deletion flag = post.flags.in_cooldown.last - if !is_deletion && flag.present? + if !is_deletion && !creator.is_approver? && flag.present? errors.add(:post, "cannot be flagged more than once every #{Danbooru.config.moderation_period.inspect} (last flagged: #{flag.created_at.to_formatted_s(:long)})") end end diff --git a/test/unit/post_flag_test.rb b/test/unit/post_flag_test.rb index 0e8958adf..89a5c40a6 100644 --- a/test/unit/post_flag_test.rb +++ b/test/unit/post_flag_test.rb @@ -98,6 +98,21 @@ class PostFlagTest < ActiveSupport::TestCase assert(@flag3.errors.empty?) end end + + should "be able to flag a post in the cooldown period if they're a mod" do + @post = create(:post) + @flag1 = create(:post_flag, post: @post) + + create(:post_approval, post: @post) + assert_equal(false, @post.reload.is_pending?) + + travel_to(Danbooru.config.moderation_period.from_now - 1.minute) do + @flag2 = create(:post_flag, post: @post, reason: "something", creator: create(:approver)) + + assert_equal(true, @flag2.valid?) + assert_equal(true, @post.reload.is_flagged?) + end + end end end end