[Replacements] Fix approving when hitting the upload limit

Also improves the error message that was being returned because
just saying 'pending' isn't really helpful
This commit is contained in:
Earlopain 2023-08-11 17:39:33 +02:00
parent 3f03182dfb
commit d6bfa02694
No known key found for this signature in database
GPG Key ID: 48860312319ADF61
3 changed files with 17 additions and 7 deletions

View File

@ -40,14 +40,14 @@ class UploadService
file: replacement.replacement_file,
replaced_post: post,
original_post_id: post.id,
replacement_id: replacement.id
replacement_id: replacement.id,
)
begin
if upload.invalid? || upload.is_errored?
raise ProcessingError, upload.status
end
if upload.invalid? || upload.is_errored?
raise ProcessingError, upload.errors.full_messages.to_sentence
end
begin
upload.update(status: "processing")
upload.file = Utils.get_file_for_upload(upload, file: upload.file)
@ -56,7 +56,7 @@ class UploadService
upload.save!
rescue Exception => e
upload.update(status: "error: #{e.class} - #{e.message}", backtrace: e.backtrace.join("\n"))
raise ProcessingError, upload.status
raise ProcessingError, "#{e.class} - #{e.message}"
end
md5_changed = upload.md5 != post.md5

View File

@ -150,6 +150,9 @@ class Upload < ApplicationRecord
include DirectURLMethods
def uploader_is_not_limited
# Uploads created when approving a replacemnet should always go through
return if replacement_id.present?
uploadable = uploader.can_upload_with_reason
if uploadable != true
self.errors.add(:uploader, User.upload_reason_string(uploadable))

View File

@ -128,7 +128,6 @@ class PostReplacementTest < ActiveSupport::TestCase
setup do
@note = create(:note, post: @post, x: 100, y: 200, width: 100, height: 50)
@replacement = create(:png_replacement, creator: @user, post: @post)
assert @replacement
end
should "fail if post cannot be backed up" do
@ -151,6 +150,14 @@ class PostReplacementTest < ActiveSupport::TestCase
assert_equal @replacement.file_size, @post.file_size
end
should "work if the approver is above their upload limit" do
User.any_instance.stubs(:upload_limit).returns(0)
Danbooru.config.stubs(:disable_throttles?).returns(false)
assert_nothing_raised { @replacement.approve!(penalize_current_uploader: true) }
assert_equal @replacement.md5, @post.md5
end
should "generate videos samples if replacement is video" do
@replacement = create(:webm_replacement, creator: @user, post: @post)
@post.expects(:generate_video_samples).times(1)