uploads: replace old upload limits with new upload limits.
This commit is contained in:
@@ -27,6 +27,7 @@ class Post < ApplicationRecord
|
||||
validate :has_enough_tags
|
||||
validate :post_is_not_its_own_parent
|
||||
validate :updater_can_change_rating
|
||||
validate :uploader_is_not_limited, on: :create
|
||||
before_save :update_tag_post_counts
|
||||
before_save :set_tag_counts
|
||||
before_create :autoban
|
||||
@@ -1280,7 +1281,7 @@ class Post < ApplicationRecord
|
||||
give_favorites_to_parent(options) if options[:move_favorites]
|
||||
|
||||
is_automatic = (reason == "Unapproved in three days")
|
||||
uploader.new_upload_limit.update_limit!(self, incremental: is_automatic)
|
||||
uploader.upload_limit.update_limit!(self, incremental: is_automatic)
|
||||
|
||||
unless options[:without_mod_action]
|
||||
ModAction.log("deleted post ##{id}, reason: #{reason}", :post_delete)
|
||||
@@ -1648,6 +1649,10 @@ class Post < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def uploader_is_not_limited
|
||||
errors[:uploader] << uploader.upload_limit.limit_reason if uploader.upload_limit.limited?
|
||||
end
|
||||
|
||||
def added_tags_are_valid
|
||||
new_tags = added_tags.select { |t| t.post_count <= 0 }
|
||||
new_general_tags = new_tags.select { |t| t.category == Tag.categories.general }
|
||||
|
||||
@@ -32,7 +32,7 @@ class PostApproval < ApplicationRecord
|
||||
post.update(approver: user, is_flagged: false, is_pending: false, is_deleted: false)
|
||||
ModAction.log("undeleted post ##{post_id}", :post_undelete) if is_undeletion
|
||||
|
||||
post.uploader.new_upload_limit.update_limit!(post, incremental: !is_undeletion)
|
||||
post.uploader.upload_limit.update_limit!(post, incremental: !is_undeletion)
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
|
||||
@@ -60,7 +60,6 @@ class Upload < ApplicationRecord
|
||||
|
||||
before_validation :initialize_attributes, on: :create
|
||||
before_validation :assign_rating_from_tags
|
||||
validate :uploader_is_not_limited, on: :create
|
||||
# validates :source, format: { with: /\Ahttps?/ }, if: ->(record) {record.file.blank?}, on: :create
|
||||
validates :rating, inclusion: { in: %w(q e s) }, allow_nil: true
|
||||
validates :md5, confirmation: true, if: ->(rec) { rec.md5_confirmation.present? }
|
||||
@@ -235,12 +234,6 @@ class Upload < ApplicationRecord
|
||||
extend SearchMethods
|
||||
include SourceMethods
|
||||
|
||||
def uploader_is_not_limited
|
||||
if !uploader.can_upload?
|
||||
errors.add(:uploader, uploader.upload_limited_reason)
|
||||
end
|
||||
end
|
||||
|
||||
def assign_rating_from_tags
|
||||
if rating = Tag.has_metatag?(tag_string, :rating)
|
||||
self.rating = rating.downcase.first
|
||||
|
||||
@@ -417,26 +417,6 @@ class User < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def can_upload?
|
||||
if can_upload_free?
|
||||
true
|
||||
elsif is_admin?
|
||||
true
|
||||
elsif created_at > 1.week.ago
|
||||
false
|
||||
else
|
||||
upload_limit > 0
|
||||
end
|
||||
end
|
||||
|
||||
def upload_limited_reason
|
||||
if created_at > 1.week.ago
|
||||
"cannot upload during your first week of registration"
|
||||
else
|
||||
"have reached your upload limit for the day"
|
||||
end
|
||||
end
|
||||
|
||||
def can_comment?
|
||||
if is_gold?
|
||||
true
|
||||
@@ -469,38 +449,8 @@ class User < ApplicationRecord
|
||||
(is_moderator? && flag.not_uploaded_by?(id)) || flag.creator_id == id
|
||||
end
|
||||
|
||||
def new_upload_limit
|
||||
@new_upload_limit ||= UploadLimit.new(self)
|
||||
end
|
||||
|
||||
def upload_limit
|
||||
[max_upload_limit - used_upload_slots, 0].max
|
||||
end
|
||||
|
||||
def used_upload_slots
|
||||
uploaded_count = posts.where("created_at >= ?", 23.hours.ago).count
|
||||
uploaded_comic_count = posts.tag_match("comic").where("created_at >= ?", 23.hours.ago).count / 3
|
||||
uploaded_count - uploaded_comic_count
|
||||
end
|
||||
memoize :used_upload_slots
|
||||
|
||||
def max_upload_limit
|
||||
[(base_upload_limit * upload_limit_multiplier).ceil, 10].max
|
||||
end
|
||||
|
||||
def upload_limit_multiplier
|
||||
(1 - (adjusted_deletion_confidence / 15.0))
|
||||
end
|
||||
|
||||
def adjusted_deletion_confidence
|
||||
[deletion_confidence(60.days.ago), 15].min
|
||||
end
|
||||
memoize :adjusted_deletion_confidence
|
||||
|
||||
def deletion_confidence(date)
|
||||
deletions = posts.deleted.where("created_at >= ?", date).count
|
||||
total = posts.where("created_at >= ?", date).count
|
||||
DanbooruMath.ci_lower_bound(deletions, total)
|
||||
@upload_limit ||= UploadLimit.new(self)
|
||||
end
|
||||
|
||||
def base_upload_limit
|
||||
@@ -624,7 +574,6 @@ class User < ApplicationRecord
|
||||
forum_post_count comment_count favorite_group_count
|
||||
appeal_count flag_count positive_feedback_count
|
||||
neutral_feedback_count negative_feedback_count upload_limit
|
||||
max_upload_limit
|
||||
]
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user