forked from e621ng/e621ng
Post flagging and ticket limits
This commit is contained in:
parent
e94bb0f30e
commit
b658b2c682
@ -7,7 +7,7 @@ class PostFlag < ApplicationRecord
|
||||
BANNED = "Artist requested removal"
|
||||
end
|
||||
|
||||
COOLDOWN_PERIOD = 3.days
|
||||
COOLDOWN_PERIOD = 1.days
|
||||
CREATION_THRESHOLD = 10 # in 30 days
|
||||
MAPPED_REASONS = Danbooru.config.flag_reasons.map {|i| [i[:name], i[:reason]] }.to_h
|
||||
|
||||
@ -158,23 +158,19 @@ class PostFlag < ApplicationRecord
|
||||
|
||||
return if creator.is_janitor?
|
||||
|
||||
if creator_id != User.system.id && PostFlag.for_creator(creator_id).where("created_at > ?", 30.days.ago).count >= CREATION_THRESHOLD
|
||||
report = Reports::PostFlags.new(user_id: post.uploader_id, date_range: 90.days.ago)
|
||||
# TODO: Should we keep this?
|
||||
# if creator_id != User.system.id && PostFlag.for_creator(creator_id).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 report.attackers.include?(creator_id)
|
||||
errors[:creator] << "cannot flag posts uploaded by this user"
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: Convert to a user limit and move to user class.
|
||||
if CurrentUser.can_approve_posts?
|
||||
# do nothing
|
||||
elsif creator.created_at > 1.week.ago
|
||||
errors[:creator] << "cannot flag within the first week of sign up"
|
||||
elsif creator.is_privileged? && flag_count_for_creator >= 10
|
||||
errors[:creator] << "can flag 10 posts a day"
|
||||
elsif !creator.is_privileged? && flag_count_for_creator >= 1
|
||||
errors[:creator] << "can flag 1 post a day"
|
||||
allowed = creator.can_post_flag_with_reason
|
||||
if allowed != true
|
||||
errors.add(:creator, User.throttle_reason(allowed))
|
||||
return false
|
||||
end
|
||||
|
||||
flag = post.flags.in_cooldown.last
|
||||
@ -184,7 +180,7 @@ class PostFlag < ApplicationRecord
|
||||
end
|
||||
|
||||
def validate_post
|
||||
errors[:post] << "is locked and cannot be flagged" if post.is_status_locked?
|
||||
errors[:post] << "is locked and cannot be flagged" if post.is_status_locked? && !creator.is_admin?
|
||||
errors[:post] << "is deleted" if post.is_deleted?
|
||||
end
|
||||
|
||||
|
@ -12,6 +12,8 @@ class Ticket < ApplicationRecord
|
||||
after_update :send_update_dmail, if: :should_send_notification
|
||||
validate :validate_can_see_target, on: :create
|
||||
|
||||
scope :for_creator, ->(uid) {where('creator_id = ?', uid)}
|
||||
|
||||
=begin
|
||||
Permission truth table.
|
||||
Type | Field | Access
|
||||
|
@ -447,6 +447,10 @@ class User < ApplicationRecord
|
||||
:general_bypass_throttle?, 3.days.ago)
|
||||
create_user_throttle(:post_vote, ->{ Danbooru.config.post_vote_limit - PostVote.for_user(id).where("created_at > ?", 1.hour.ago)},
|
||||
:general_bypass_throttle?, nil)
|
||||
create_user_throttle(:post_flag, ->{ Danboooru.config.post_flag_limit - PostFlag.for_creator(id).where("created_at > ?", 1.hour.ago)},
|
||||
:can_approve_posts?, 3.days.ago)
|
||||
create_user_throttle(:ticket, ->{ Danbooru.config.ticket_limit - Ticket.for_creator(id).where("created_at > ?", 1.hour.ago)},
|
||||
:general_bypass_throttle?, 3.days.ago)
|
||||
|
||||
def max_saved_searches
|
||||
if is_contributor?
|
||||
|
@ -249,11 +249,19 @@ fart'
|
||||
150
|
||||
end
|
||||
|
||||
def post_flag_limit
|
||||
10
|
||||
end
|
||||
|
||||
# Flat limit that applies to all users, regardless of level
|
||||
def hourly_upload_limit
|
||||
30
|
||||
end
|
||||
|
||||
def ticket_limit
|
||||
30
|
||||
end
|
||||
|
||||
# Members cannot change the category of pools with more than this many posts.
|
||||
def pool_category_change_limit
|
||||
30
|
||||
|
Loading…
Reference in New Issue
Block a user