FIX: Allow attr updates of over-size-limit uploads (#18986)
This commit is contained in:
parent
99e5fbe303
commit
dc8a7e74f4
|
@ -34,6 +34,7 @@ class Upload < ActiveRecord::Base
|
|||
attr_accessor :for_export
|
||||
attr_accessor :for_site_setting
|
||||
attr_accessor :for_gravatar
|
||||
attr_accessor :validate_file_size
|
||||
|
||||
validates_presence_of :filesize
|
||||
validates_presence_of :original_filename
|
||||
|
@ -92,6 +93,11 @@ class Upload < ActiveRecord::Base
|
|||
.where("ur.upload_id IS NULL")
|
||||
end
|
||||
|
||||
def initialize(*args)
|
||||
super
|
||||
self.validate_file_size = true
|
||||
end
|
||||
|
||||
def to_s
|
||||
self.url
|
||||
end
|
||||
|
|
|
@ -1189,6 +1189,10 @@ task "uploads:downsize" => :environment do
|
|||
log "After: #{w}x#{h} #{ww}x#{hh} (#{upload.filesize})"
|
||||
|
||||
dimensions_count += 1
|
||||
|
||||
# Don't validate the size - max image size setting might have
|
||||
# changed since the file was uploaded, so this could fail
|
||||
upload.validate_file_size = false
|
||||
upload.save!
|
||||
end
|
||||
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
|
||||
require "file_helper"
|
||||
|
||||
module Validators; end
|
||||
|
||||
class UploadValidator < ActiveModel::Validator
|
||||
|
||||
def validate(upload)
|
||||
# staff can upload any file in PM
|
||||
if (upload.for_private_message && SiteSetting.allow_staff_to_upload_any_file_in_pm)
|
||||
|
@ -141,6 +138,8 @@ class UploadValidator < ActiveModel::Validator
|
|||
end
|
||||
|
||||
def maximum_file_size(upload, type)
|
||||
return if !upload.validate_file_size
|
||||
|
||||
max_size_kb = if upload.for_export
|
||||
SiteSetting.max_export_file_size_kb
|
||||
else
|
||||
|
@ -157,5 +156,4 @@ class UploadValidator < ActiveModel::Validator
|
|||
upload.errors.add(:filesize, message)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -235,5 +235,12 @@ RSpec.describe "tasks/uploads" do
|
|||
|
||||
expect { invoke_task }.to change { upload.reload.thumbnail_height }.to(200)
|
||||
end
|
||||
|
||||
it "updates attributes of uploads that are over the size limit" do
|
||||
upload.update!(thumbnail_height: 0)
|
||||
SiteSetting.max_image_size_kb = 0.001 # 1 byte
|
||||
|
||||
expect { invoke_task }.to change { upload.reload.thumbnail_height }.to(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue