Add new upload limit system (fix #4234).

This commit is contained in:
evazion
2020-01-23 18:14:30 -06:00
parent 3d6084338c
commit 18affeb4e9
9 changed files with 196 additions and 3 deletions

View File

@@ -1279,6 +1279,9 @@ class Post < ApplicationRecord
# XXX This must happen *after* the `is_deleted` flag is set to true (issue #3419).
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)
unless options[:without_mod_action]
ModAction.log("deleted post ##{id}, reason: #{reason}", :post_delete)
end

View File

@@ -26,10 +26,13 @@ class PostApproval < ApplicationRecord
end
def approve_post
ModAction.log("undeleted post ##{post_id}", :post_undelete) if post.is_deleted
is_undeletion = post.is_deleted
post.flags.each(&:resolve!)
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)
end
def self.search(params)

View File

@@ -468,6 +468,10 @@ 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