flags: remove uploader targeting restrictions.
Remove restrictions against flagging too many posts by the same uploader. This had problems with preventing legitimate flags in some cases, particularly with old legacy content. This will be policed manually instead.
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
module Reports
|
||||
class PostFlags
|
||||
attr_reader :user_id, :date_range
|
||||
|
||||
def initialize(user_id:, date_range:)
|
||||
@user_id = user_id
|
||||
@date_range = date_range
|
||||
end
|
||||
|
||||
def candidates
|
||||
PostFlag.where("posts.uploader_id = ? and posts.created_at >= ? and post_flags.creator_id <> ?", user_id, date_range, User.system.id).joins(:post).pluck("post_flags.creator_id").uniq
|
||||
end
|
||||
|
||||
def attackers
|
||||
matches = []
|
||||
|
||||
build.each do |flagger, uploaders|
|
||||
if uploaders[user_id].to_i > 50
|
||||
matches << flagger
|
||||
end
|
||||
end
|
||||
|
||||
return matches
|
||||
end
|
||||
|
||||
def build
|
||||
flaggers = Hash.new {|h, k| h[k] = {}}
|
||||
|
||||
candidates.each do |candidate|
|
||||
PostFlag.joins(:post).where("post_flags.creator_id = ? and posts.created_at >= ?", candidate, date_range).select("posts.uploader_id").group("posts.uploader_id").having("count(*) > 1").count.each do |uploader_id, count|
|
||||
flaggers[candidate][uploader_id] = count
|
||||
end
|
||||
|
||||
sum = flaggers[candidate].values.sum
|
||||
|
||||
flaggers[candidate].each_key do |user_id|
|
||||
flaggers[candidate][user_id] = DanbooruMath.ci_lower_bound(flaggers[candidate][user_id], sum)
|
||||
end
|
||||
end
|
||||
|
||||
return flaggers
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -8,7 +8,6 @@ class PostFlag < ApplicationRecord
|
||||
end
|
||||
|
||||
COOLDOWN_PERIOD = 3.days
|
||||
CREATION_THRESHOLD = 10 # in 30 days
|
||||
|
||||
belongs_to_creator :class_name => "User"
|
||||
belongs_to :post
|
||||
@@ -125,14 +124,6 @@ class PostFlag < ApplicationRecord
|
||||
def validate_creator_is_not_limited
|
||||
return if is_deletion
|
||||
|
||||
if creator_id != User.system.id && creator.post_flags.where("created_at > ?", 30.days.ago).count >= CREATION_THRESHOLD
|
||||
report = Reports::PostFlags.new(user_id: post.uploader_id, date_range: 90.days.ago)
|
||||
|
||||
if report.attackers.include?(creator_id)
|
||||
errors[:creator] << "cannot flag posts uploaded by this user"
|
||||
end
|
||||
end
|
||||
|
||||
if CurrentUser.can_approve_posts?
|
||||
# do nothing
|
||||
elsif creator.created_at > 1.week.ago
|
||||
|
||||
@@ -51,24 +51,6 @@ class PostFlagTest < ActiveSupport::TestCase
|
||||
assert_equal(["have already flagged this post"], @post_flag.errors[:creator_id])
|
||||
end
|
||||
|
||||
should "not be able to target a single uploader" do
|
||||
travel_to(2.weeks.ago) do
|
||||
as(@alice) do
|
||||
@posts = FactoryBot.create_list(:post, 10, uploader: @alice)
|
||||
end
|
||||
end
|
||||
|
||||
as(@bob) do
|
||||
travel_to(1.week.ago) do
|
||||
@flags = @posts.map {|x| PostFlag.create(reason: "bad #{x.id}", post: x)}
|
||||
end
|
||||
|
||||
@bad_flag = PostFlag.create(post: @post, reason: "bad #{@post.id}")
|
||||
end
|
||||
|
||||
assert_equal(["You cannot flag posts uploaded by this user"], @bad_flag.errors.full_messages)
|
||||
end
|
||||
|
||||
should "not be able to flag more than 10 posts in 24 hours" do
|
||||
as(@bob) do
|
||||
@post_flag = PostFlag.new(post: @post, reason: "aaa", is_resolved: false)
|
||||
|
||||
Reference in New Issue
Block a user