Fix #4603: Total Upload Limit Being Reduced After A Failed Appeal
This commit is contained in:
@@ -82,19 +82,26 @@ class UploadLimit
|
||||
end
|
||||
|
||||
# Update the uploader's upload points when a post is approved or deleted.
|
||||
# @param post [Post] The post that was approved or deleted.
|
||||
# @param incremental [Boolean] True if the post was status:pending and we can
|
||||
# simply increment/decrement the upload points. False if the post was an
|
||||
# approval or undeletion of an old post, and we have to replay the user's
|
||||
# entire upload history to recalculate their points.
|
||||
def update_limit!(post, incremental: true)
|
||||
# This must be called *after* the post is approved or deleted.
|
||||
#
|
||||
# @param is_pending [Boolean] true if the post is pending, false if the post is
|
||||
# active, flagged, appealed, or deleted.
|
||||
# @param is_approval [Boolean] true if the post is being approved or
|
||||
# undeleted, false if the post is being deleted.
|
||||
def update_limit!(is_pending, is_approval)
|
||||
return if user.can_upload_free?
|
||||
|
||||
user.with_lock do
|
||||
if incremental
|
||||
user.upload_points += UploadLimit.upload_value(user.upload_points, post.is_deleted)
|
||||
# If we're approving or deleting a pending post, we can simply increment
|
||||
# or decrement the upload points.
|
||||
if is_pending
|
||||
user.upload_points += UploadLimit.upload_value(user.upload_points, !is_approval)
|
||||
user.upload_points = user.upload_points.clamp(0, MAXIMUM_POINTS)
|
||||
user.save!
|
||||
|
||||
# If we're undeleting a deleted or appealed post, or deleting a flagged
|
||||
# or active post, then we have to replay the user's entire upload
|
||||
# history to recalculate their upload points.
|
||||
else
|
||||
user.update!(upload_points: UploadLimit.points_for_user(user))
|
||||
end
|
||||
|
||||
@@ -1003,7 +1003,7 @@ class Post < ApplicationRecord
|
||||
# XXX This must happen *after* the `is_deleted` flag is set to true (issue #3419).
|
||||
give_favorites_to_parent if move_favorites
|
||||
|
||||
uploader.upload_limit.update_limit!(self, incremental: automated)
|
||||
uploader.upload_limit.update_limit!(is_pending?, false)
|
||||
|
||||
unless automated
|
||||
ModAction.log("deleted post ##{id}, reason: #{reason}", :post_delete)
|
||||
|
||||
@@ -26,6 +26,7 @@ class PostApproval < ApplicationRecord
|
||||
end
|
||||
|
||||
def approve_post
|
||||
is_pending = post.is_pending
|
||||
is_undeletion = post.is_deleted
|
||||
|
||||
post.flags.pending.update!(status: :rejected)
|
||||
@@ -34,7 +35,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.upload_limit.update_limit!(post, incremental: !is_undeletion)
|
||||
post.uploader.upload_limit.update_limit!(is_pending, true)
|
||||
end
|
||||
|
||||
def self.search(params)
|
||||
|
||||
Reference in New Issue
Block a user