mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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_export
|
||||||
attr_accessor :for_site_setting
|
attr_accessor :for_site_setting
|
||||||
attr_accessor :for_gravatar
|
attr_accessor :for_gravatar
|
||||||
|
attr_accessor :validate_file_size
|
||||||
|
|
||||||
validates_presence_of :filesize
|
validates_presence_of :filesize
|
||||||
validates_presence_of :original_filename
|
validates_presence_of :original_filename
|
||||||
@ -92,6 +93,11 @@ class Upload < ActiveRecord::Base
|
|||||||
.where("ur.upload_id IS NULL")
|
.where("ur.upload_id IS NULL")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def initialize(*args)
|
||||||
|
super
|
||||||
|
self.validate_file_size = true
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
self.url
|
self.url
|
||||||
end
|
end
|
||||||
|
@ -1189,6 +1189,10 @@ task "uploads:downsize" => :environment do
|
|||||||
log "After: #{w}x#{h} #{ww}x#{hh} (#{upload.filesize})"
|
log "After: #{w}x#{h} #{ww}x#{hh} (#{upload.filesize})"
|
||||||
|
|
||||||
dimensions_count += 1
|
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!
|
upload.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,10 +2,7 @@
|
|||||||
|
|
||||||
require "file_helper"
|
require "file_helper"
|
||||||
|
|
||||||
module Validators; end
|
|
||||||
|
|
||||||
class UploadValidator < ActiveModel::Validator
|
class UploadValidator < ActiveModel::Validator
|
||||||
|
|
||||||
def validate(upload)
|
def validate(upload)
|
||||||
# staff can upload any file in PM
|
# staff can upload any file in PM
|
||||||
if (upload.for_private_message && SiteSetting.allow_staff_to_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
|
end
|
||||||
|
|
||||||
def maximum_file_size(upload, type)
|
def maximum_file_size(upload, type)
|
||||||
|
return if !upload.validate_file_size
|
||||||
|
|
||||||
max_size_kb = if upload.for_export
|
max_size_kb = if upload.for_export
|
||||||
SiteSetting.max_export_file_size_kb
|
SiteSetting.max_export_file_size_kb
|
||||||
else
|
else
|
||||||
@ -157,5 +156,4 @@ class UploadValidator < ActiveModel::Validator
|
|||||||
upload.errors.add(:filesize, message)
|
upload.errors.add(:filesize, message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -235,5 +235,12 @@ RSpec.describe "tasks/uploads" do
|
|||||||
|
|
||||||
expect { invoke_task }.to change { upload.reload.thumbnail_height }.to(200)
|
expect { invoke_task }.to change { upload.reload.thumbnail_height }.to(200)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user