Merge pull request #1219 from ZmagoD/zd_SCI_2415

move maximum file size limit to an ENV variable [fixes SCI-2415]
This commit is contained in:
Zmago Devetak 2018-06-26 18:43:16 +02:00 committed by GitHub
commit 7fd3eec195
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 25 additions and 24 deletions

View file

@ -470,7 +470,7 @@ function initImport() {
} else {
if (data.status === 'size_too_large') {
alert('<%= I18n.t('my_modules.protocols.load_from_file_size_error',
size: Constants::FILE_MAX_SIZE_MB ) %>');
size: Rails.configuration.x.file_max_size_mb ) %>');
} else {
alert(I18n.t("my_modules.protocols.load_from_file_error"));
}

View file

@ -557,7 +557,7 @@ function importProtocolFromFile(
$.extend(data_json, params);
var rough_size = roughSizeOfObject(data_json);
if (rough_size > <%= Constants::FILE_MAX_SIZE_MB.megabytes %>) {
if (rough_size > <%= Rails.configuration.x.file_max_size_mb.megabytes %>) {
// Call the callback function
resultCallback({ name: protocolJson["name"], new_name: null, status: "size_too_large" });
return;

View file

@ -235,23 +235,23 @@
function _validateFilesSize(file) {
var fileSize = file.size;
totalSize += parseInt(fileSize);
if(fileSize > <%= Constants::FILE_MAX_SIZE_MB.megabyte %>) {
if(fileSize > <%= Rails.configuration.x.file_max_size_mb.megabyte %>) {
file.isValid = false;
_disableSubmitButton();
return "<p class='dnd-error'><%= I18n.t 'general.file.size_exceeded', file_size: Constants::FILE_MAX_SIZE_MB %></p>";
return "<p class='dnd-error'><%= I18n.t 'general.file.size_exceeded', file_size: Rails.configuration.x.file_max_size_mb %></p>";
}
return '';
}
function _validateTotalSize() {
if(totalSize > <%= Constants::FILE_MAX_SIZE_MB.megabyte %>) {
if(totalSize > <%= Rails.configuration.x.file_max_size_mb.megabyte %>) {
filesValid = false;
_disableSubmitButton();
$.each($('.panel-step-attachment-new'), function() {
if(!$(this).find('p').hasClass('dnd-total-error')) {
$(this)
.find('.panel-body')
.append("<p class='dnd-total-error'><%= I18n.t('general.file.total_size', size: Constants::FILE_MAX_SIZE_MB) %></p>");
.append("<p class='dnd-total-error'><%= I18n.t('general.file.total_size', size: Rails.configuration.x.file_max_size_mb) %></p>");
}
});
} else {
@ -392,23 +392,23 @@
function _validateFilesSize(file) {
var fileSize = file.size;
totalSize += parseInt(fileSize);
if(fileSize > <%= Constants::FILE_MAX_SIZE_MB.megabyte %>) {
if(fileSize > <%= Rails.configuration.x.file_max_size_mb.megabyte %>) {
file.isValid = false;
_disableSubmitButton();
return "<p class='dnd-error'><%= I18n.t 'general.file.size_exceeded', file_size: Constants::FILE_MAX_SIZE_MB %></p>";
return "<p class='dnd-error'><%= I18n.t 'general.file.size_exceeded', file_size: Rails.configuration.x.file_max_size_mb %></p>";
}
return '';
}
function _validateTotalSize() {
if(totalSize > <%= Constants::FILE_MAX_SIZE_MB.megabyte %>) {
if(totalSize > <%= Rails.configuration.x.file_max_size_mb.megabyte %>) {
isValid = false;
_disableSubmitButton();
$.each($('.panel-result-attachment-new'), function() {
if(!$(this).find('p').hasClass('dnd-total-error')) {
$(this)
.find('.panel-body')
.append("<p class='dnd-total-error'><%= I18n.t('general.file.total_size', size: Constants::FILE_MAX_SIZE_MB) %></p>");
.append("<p class='dnd-total-error'><%= I18n.t('general.file.total_size', size: Rails.configuration.x.file_max_size_mb) %></p>");
}
});
} else {

View file

@ -102,7 +102,7 @@ function checklistsValidator(ev, checklists, editMode) {
}
var FileTypeEnum = Object.freeze({
FILE: <%= Constants::FILE_MAX_SIZE_MB.megabytes %>,
FILE: <%= Rails.configuration.x.file_max_size_mb.megabytes %>,
AVATAR: <%= Constants::AVATAR_MAX_SIZE_MB.megabytes %>
});
@ -140,7 +140,7 @@ function filesSizeValidator(ev, fileInputs, fileTypeEnum) {
if (file.size > fileTypeEnum) {
switch (fileTypeEnum) {
case FileTypeEnum.FILE:
return "<%= I18n.t 'general.file.size_exceeded', file_size: Constants::FILE_MAX_SIZE_MB %>".strToErrorFormat();
return "<%= I18n.t 'general.file.size_exceeded', file_size: Rails.configuration.x.file_max_size_mb %>".strToErrorFormat();
case FileTypeEnum.AVATAR:
return "<%= I18n.t 'general.file.size_exceeded', file_size: Constants::AVATAR_MAX_SIZE_MB %>".strToErrorFormat();
}
@ -161,7 +161,7 @@ function filesSizeValidator(ev, fileInputs, fileTypeEnum) {
if (size > fileTypeEnum) {
switch (fileTypeEnum) {
case FileTypeEnum.FILE:
return "<%= I18n.t('general.file.total_size', size: Constants::FILE_MAX_SIZE_MB) %>".strToErrorFormat();
return "<%= I18n.t('general.file.total_size', size: Rails.configuration.x.file_max_size_mb) %>".strToErrorFormat();
case FileTypeEnum.AVATAR:
return "<%= I18n.t('users.registrations.edit.avatar_total_size', size: Constants::AVATAR_MAX_SIZE_MB) %>".strToErrorFormat();
}

View file

@ -618,7 +618,7 @@ class ProtocolsController < ApplicationController
end
return 0 # return 0 stops the rest of the controller code from executing
end
if file_size > Constants::FILE_MAX_SIZE_MB.megabytes
if file_size > Rails.configuration.x.file_max_size_mb.megabytes
@protocolsio_too_big = true
respond_to do |format|
format.js {}

View file

@ -191,7 +191,7 @@ class RepositoriesController < ApplicationController
)
if parsed_file.too_large?
repository_response(t('general.file.size_exceeded',
file_size: Constants::FILE_MAX_SIZE_MB))
file_size: Rails.configuration.x.file_max_size_mb))
elsif parsed_file.has_too_many_rows?
repository_response(
t('repositories.import_records.error_message.items_limit',

View file

@ -11,9 +11,9 @@ class TeamsController < ApplicationController
unless import_params[:file]
return parse_sheet_error(t('teams.parse_sheet.errors.no_file_selected'))
end
if import_params[:file].size > Constants::FILE_MAX_SIZE_MB.megabytes
if import_params[:file].size > Rails.configuration.x.file_max_size_mb.megabytes
error = t('general.file.size_exceeded',
file_size: Constants::FILE_MAX_SIZE_MB)
file_size: Rails.configuration.x.file_max_size_mb)
return parse_sheet_error(error)
end

View file

@ -276,7 +276,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
success_action_status: '201',
acl: 'public-read',
storage_class: "REDUCED_REDUNDANCY",
content_length_range: 1..Constants::FILE_MAX_SIZE_MB.megabytes,
content_length_range: 1..Rails.configuration.x.file_max_size_mb.megabytes,
content_type: content_type
)
posts.push({

View file

@ -19,7 +19,7 @@ class Asset < ApplicationRecord
validates_attachment :file,
presence: true,
size: {
less_than: Constants::FILE_MAX_SIZE_MB.megabytes
less_than: Rails.configuration.x.file_max_size_mb.megabytes
}
validates :estimated_size, presence: true
validates :file_present, inclusion: { in: [true, false] }

View file

@ -18,7 +18,7 @@ class TinyMceAsset < ApplicationRecord
validates_attachment :image,
presence: true,
size: {
less_than: Constants::FILE_MAX_SIZE_MB.megabytes
less_than: Rails.configuration.x.file_max_size_mb.megabytes
}
validates :estimated_size, presence: true

View file

@ -21,7 +21,7 @@ module ImportRepository
end
def too_large?
@file.size > Constants::FILE_MAX_SIZE_MB.megabytes
@file.size > Rails.configuration.x.file_max_size_mb.megabytes
end
def has_too_many_rows?

View file

@ -4,7 +4,7 @@ $('#modal-import-json-protocol').on('hidden.bs.modal', function () {
<% if @protocolsio_too_big %>
$('#modal-import-json-protocol').modal('hide');
HelperModule.flashAlertMsg(' <%= t('my_modules.protocols.load_from_file_size_error',
size: Constants::FILE_MAX_SIZE_MB ) %>','danger');
size: Rails.configuration.x.file_max_size_mb ) %>','danger');
<% elsif @protocolsio_invalid_file %>
$('#modal-import-json-protocol').modal('hide');
HelperModule.flashAlertMsg(' <%= t('my_modules.protocols.load_from_file_invalid_error') %>','danger');

View file

@ -26,6 +26,9 @@ module Scinote
config.active_job.queue_adapter = :delayed_job
# Max uploaded file size in MB
config.x.file_max_size_mb = (ENV['FILE_MAX_SIZE_MB'] || 50).to_i
# Logging
config.log_formatter = proc do |severity, datetime, progname, msg|
"[#{datetime}] #{severity}: #{msg}\n"

View file

@ -64,8 +64,6 @@ class Constants
# Max table JSON size in MB
TABLE_JSON_MAX_SIZE_MB = 20
# Max uploaded file size in MB
FILE_MAX_SIZE_MB = 50
# Max uploaded user picture avatar size in MB
AVATAR_MAX_SIZE_MB = 0.2