From afe3b00c0facdddb88e938ace7b1ee6825fb0121 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Tue, 31 Jul 2018 11:15:31 +0530 Subject: [PATCH] FIX: use hidden setting for max export file size --- config/site_settings.yml | 4 ++++ lib/validators/upload_validator.rb | 6 +++++- spec/components/validators/upload_validator_spec.rb | 9 +++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/config/site_settings.yml b/config/site_settings.yml index ee0b96c9cc9..aa34a64a8bb 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -869,6 +869,10 @@ files: default: 40 min: 5 max: 150 + max_export_file_size_kb: + hidden: true + default: 50000 + max: 1024000 theme_authorized_extensions: default: 'jpg|jpeg|png|woff|woff2|svg|eot|ttf|otf|gif' type: list diff --git a/lib/validators/upload_validator.rb b/lib/validators/upload_validator.rb index 5b9da9793df..60074a197f9 100644 --- a/lib/validators/upload_validator.rb +++ b/lib/validators/upload_validator.rb @@ -113,7 +113,11 @@ class Validators::UploadValidator < ActiveModel::Validator end def maximum_file_size(upload, type) - max_size_kb = SiteSetting.send("max_#{type}_size_kb") + max_size_kb = if upload.for_export + SiteSetting.max_export_file_size_kb + else + SiteSetting.send("max_#{type}_size_kb") + end max_size_bytes = max_size_kb.kilobytes if upload.filesize > max_size_bytes diff --git a/spec/components/validators/upload_validator_spec.rb b/spec/components/validators/upload_validator_spec.rb index 164d0b0a8e8..f256e2f176e 100644 --- a/spec/components/validators/upload_validator_spec.rb +++ b/spec/components/validators/upload_validator_spec.rb @@ -20,9 +20,14 @@ describe Validators::UploadValidator do it "allows 'gz' as extension when uploading export file" do SiteSetting.authorized_extensions = "" - created_upload = UploadCreator.new(csv_file, "#{filename}.gz", for_export: true).create_for(user.id) - expect(created_upload).to be_valid + expect(UploadCreator.new(csv_file, "#{filename}.gz", for_export: true).create_for(user.id)).to be_valid end + it "allows uses max_export_file_size_kb when uploading export file" do + SiteSetting.max_attachment_size_kb = "0" + SiteSetting.authorized_extensions = "gz" + + expect(UploadCreator.new(csv_file, "#{filename}.gz", for_export: true).create_for(user.id)).to be_valid + end end end