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.
This commit is contained in:
evazion
2022-09-18 15:43:05 -05:00
parent 0c919a6bc8
commit 72e95b6ca3
2 changed files with 16 additions and 1 deletions

View File

@@ -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

View File

@@ -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