moderation: extract 3 day modqueue length to config.
This commit is contained in:
@@ -38,7 +38,7 @@ class UploadLimit
|
|||||||
def used_upload_slots
|
def used_upload_slots
|
||||||
pending_count = user.posts.pending.count
|
pending_count = user.posts.pending.count
|
||||||
appealed_count = user.post_appeals.pending.count
|
appealed_count = user.post_appeals.pending.count
|
||||||
early_deleted_count = user.posts.deleted.where("created_at >= ?", 3.days.ago).count
|
early_deleted_count = user.posts.deleted.where("created_at >= ?", Danbooru.config.moderation_period.ago).count
|
||||||
|
|
||||||
pending_count + early_deleted_count + (appealed_count * APPEAL_COST)
|
pending_count + early_deleted_count + (appealed_count * APPEAL_COST)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class Post < ApplicationRecord
|
|||||||
scope :active, -> { where(is_pending: false, is_deleted: false, is_flagged: false).where.not(id: PostAppeal.pending) }
|
scope :active, -> { where(is_pending: false, is_deleted: false, is_flagged: false).where.not(id: PostAppeal.pending) }
|
||||||
scope :appealed, -> { where(id: PostAppeal.pending.select(:post_id)) }
|
scope :appealed, -> { where(id: PostAppeal.pending.select(:post_id)) }
|
||||||
scope :in_modqueue, -> { pending.or(flagged).or(appealed) }
|
scope :in_modqueue, -> { pending.or(flagged).or(appealed) }
|
||||||
scope :expired, -> { where("posts.created_at < ?", 3.days.ago) }
|
scope :expired, -> { pending.where("posts.created_at < ?", Danbooru.config.moderation_period.ago) }
|
||||||
|
|
||||||
scope :unflagged, -> { where(is_flagged: false) }
|
scope :unflagged, -> { where(is_flagged: false) }
|
||||||
scope :has_notes, -> { where.not(last_noted_at: nil) }
|
scope :has_notes, -> { where.not(last_noted_at: nil) }
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ class PostAppeal < ApplicationRecord
|
|||||||
rejected: 2
|
rejected: 2
|
||||||
}
|
}
|
||||||
|
|
||||||
scope :recent, -> { where("post_appeals.created_at >= ?", 1.day.ago) }
|
scope :expired, -> { pending.where("post_appeals.created_at < ?", Danbooru.config.moderation_period.ago) }
|
||||||
scope :expired, -> { pending.where("post_appeals.created_at <= ?", 3.days.ago) }
|
|
||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
def search(params)
|
def search(params)
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ class PostFlag < ApplicationRecord
|
|||||||
REJECTED = "Unapproved in three days after returning to moderation queue%"
|
REJECTED = "Unapproved in three days after returning to moderation queue%"
|
||||||
end
|
end
|
||||||
|
|
||||||
COOLDOWN_PERIOD = 3.days
|
|
||||||
|
|
||||||
belongs_to :creator, class_name: "User"
|
belongs_to :creator, class_name: "User"
|
||||||
belongs_to :post
|
belongs_to :post
|
||||||
validates :reason, presence: true, length: { in: 1..140 }
|
validates :reason, presence: true, length: { in: 1..140 }
|
||||||
@@ -25,8 +23,8 @@ class PostFlag < ApplicationRecord
|
|||||||
|
|
||||||
scope :by_users, -> { where.not(creator: User.system) }
|
scope :by_users, -> { where.not(creator: User.system) }
|
||||||
scope :by_system, -> { where(creator: User.system) }
|
scope :by_system, -> { where(creator: User.system) }
|
||||||
scope :in_cooldown, -> { by_users.where("created_at >= ?", COOLDOWN_PERIOD.ago) }
|
scope :in_cooldown, -> { by_users.where("created_at >= ?", Danbooru.config.moderation_period.ago) }
|
||||||
scope :expired, -> { pending.where("post_flags.created_at <= ?", 3.days.ago) }
|
scope :expired, -> { pending.where("post_flags.created_at < ?", Danbooru.config.moderation_period.ago) }
|
||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
def creator_matches(creator, searcher)
|
def creator_matches(creator, searcher)
|
||||||
@@ -106,7 +104,7 @@ class PostFlag < ApplicationRecord
|
|||||||
|
|
||||||
flag = post.flags.in_cooldown.last
|
flag = post.flags.in_cooldown.last
|
||||||
if !is_deletion && flag.present?
|
if !is_deletion && flag.present?
|
||||||
errors[:post] << "cannot be flagged more than once every #{COOLDOWN_PERIOD.inspect} (last flagged: #{flag.created_at.to_s(:long)})"
|
errors[:post] << "cannot be flagged more than once every #{Danbooru.config.moderation_period.inspect} (last flagged: #{flag.created_at.to_s(:long)})"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<% if (CurrentUser.can_approve_posts? || post.created_at < 3.days.ago) && disapprovals.length > 0 %>
|
<% if (CurrentUser.can_approve_posts? || post.created_at < Danbooru.config.moderation_period.ago) && disapprovals.length > 0 %>
|
||||||
<% if disapprovals.map(&:reason).grep("breaks_rules").count > 0 %>
|
<% if disapprovals.map(&:reason).grep("breaks_rules").count > 0 %>
|
||||||
(breaks rules: <%= disapprovals.map(&:reason).grep("breaks_rules").count %>)
|
(breaks rules: <%= disapprovals.map(&:reason).grep("breaks_rules").count %>)
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<% if (CurrentUser.can_approve_posts? || post.created_at < 3.days.ago) && disapprovals.length > 0 %>
|
<% if (CurrentUser.can_approve_posts? || post.created_at < Danbooru.config.moderation_period.ago) && disapprovals.length > 0 %>
|
||||||
<p>
|
<p>
|
||||||
It has been reviewed by <%= pluralize disapprovals.length, "approver" %>.
|
It has been reviewed by <%= pluralize disapprovals.length, "approver" %>.
|
||||||
|
|
||||||
|
|||||||
@@ -110,6 +110,11 @@ module Danbooru
|
|||||||
40000
|
40000
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# How long pending posts stay in the modqueue before being deleted.
|
||||||
|
def moderation_period
|
||||||
|
3.days
|
||||||
|
end
|
||||||
|
|
||||||
# https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration
|
# https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration
|
||||||
# https://guides.rubyonrails.org/configuring.html#configuring-action-mailer
|
# https://guides.rubyonrails.org/configuring.html#configuring-action-mailer
|
||||||
def mail_delivery_method
|
def mail_delivery_method
|
||||||
|
|||||||
@@ -71,13 +71,13 @@ class PostFlagTest < ActiveSupport::TestCase
|
|||||||
@flag1 = create(:post_flag, post: @post, creator: @users.first)
|
@flag1 = create(:post_flag, post: @post, creator: @users.first)
|
||||||
as(@mod) { @post.approve! }
|
as(@mod) { @post.approve! }
|
||||||
|
|
||||||
travel_to(PostFlag::COOLDOWN_PERIOD.from_now - 1.minute) do
|
travel_to(Danbooru.config.moderation_period.from_now - 1.minute) do
|
||||||
@flag2 = build(:post_flag, post: @post, reason: "something", creator: @users.second)
|
@flag2 = build(:post_flag, post: @post, reason: "something", creator: @users.second)
|
||||||
assert_equal(false, @flag2.valid?)
|
assert_equal(false, @flag2.valid?)
|
||||||
assert_match(/cannot be flagged more than once/, @flag2.errors[:post].join)
|
assert_match(/cannot be flagged more than once/, @flag2.errors[:post].join)
|
||||||
end
|
end
|
||||||
|
|
||||||
travel_to(PostFlag::COOLDOWN_PERIOD.from_now + 1.minute) do
|
travel_to(Danbooru.config.moderation_period.from_now + 1.minute) do
|
||||||
@flag3 = create(:post_flag, post: @post, reason: "something", creator: @users.second)
|
@flag3 = create(:post_flag, post: @post, reason: "something", creator: @users.second)
|
||||||
assert(@flag3.errors.empty?)
|
assert(@flag3.errors.empty?)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user