mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 05:04:35 +08:00
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:
commit
7fd3eec195
14 changed files with 25 additions and 24 deletions
|
@ -470,7 +470,7 @@ function initImport() {
|
||||||
} else {
|
} else {
|
||||||
if (data.status === 'size_too_large') {
|
if (data.status === 'size_too_large') {
|
||||||
alert('<%= I18n.t('my_modules.protocols.load_from_file_size_error',
|
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 {
|
} else {
|
||||||
alert(I18n.t("my_modules.protocols.load_from_file_error"));
|
alert(I18n.t("my_modules.protocols.load_from_file_error"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -557,7 +557,7 @@ function importProtocolFromFile(
|
||||||
$.extend(data_json, params);
|
$.extend(data_json, params);
|
||||||
|
|
||||||
var rough_size = roughSizeOfObject(data_json);
|
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
|
// Call the callback function
|
||||||
resultCallback({ name: protocolJson["name"], new_name: null, status: "size_too_large" });
|
resultCallback({ name: protocolJson["name"], new_name: null, status: "size_too_large" });
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -235,23 +235,23 @@
|
||||||
function _validateFilesSize(file) {
|
function _validateFilesSize(file) {
|
||||||
var fileSize = file.size;
|
var fileSize = file.size;
|
||||||
totalSize += parseInt(fileSize);
|
totalSize += parseInt(fileSize);
|
||||||
if(fileSize > <%= Constants::FILE_MAX_SIZE_MB.megabyte %>) {
|
if(fileSize > <%= Rails.configuration.x.file_max_size_mb.megabyte %>) {
|
||||||
file.isValid = false;
|
file.isValid = false;
|
||||||
_disableSubmitButton();
|
_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 '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function _validateTotalSize() {
|
function _validateTotalSize() {
|
||||||
if(totalSize > <%= Constants::FILE_MAX_SIZE_MB.megabyte %>) {
|
if(totalSize > <%= Rails.configuration.x.file_max_size_mb.megabyte %>) {
|
||||||
filesValid = false;
|
filesValid = false;
|
||||||
_disableSubmitButton();
|
_disableSubmitButton();
|
||||||
$.each($('.panel-step-attachment-new'), function() {
|
$.each($('.panel-step-attachment-new'), function() {
|
||||||
if(!$(this).find('p').hasClass('dnd-total-error')) {
|
if(!$(this).find('p').hasClass('dnd-total-error')) {
|
||||||
$(this)
|
$(this)
|
||||||
.find('.panel-body')
|
.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 {
|
} else {
|
||||||
|
@ -392,23 +392,23 @@
|
||||||
function _validateFilesSize(file) {
|
function _validateFilesSize(file) {
|
||||||
var fileSize = file.size;
|
var fileSize = file.size;
|
||||||
totalSize += parseInt(fileSize);
|
totalSize += parseInt(fileSize);
|
||||||
if(fileSize > <%= Constants::FILE_MAX_SIZE_MB.megabyte %>) {
|
if(fileSize > <%= Rails.configuration.x.file_max_size_mb.megabyte %>) {
|
||||||
file.isValid = false;
|
file.isValid = false;
|
||||||
_disableSubmitButton();
|
_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 '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function _validateTotalSize() {
|
function _validateTotalSize() {
|
||||||
if(totalSize > <%= Constants::FILE_MAX_SIZE_MB.megabyte %>) {
|
if(totalSize > <%= Rails.configuration.x.file_max_size_mb.megabyte %>) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
_disableSubmitButton();
|
_disableSubmitButton();
|
||||||
$.each($('.panel-result-attachment-new'), function() {
|
$.each($('.panel-result-attachment-new'), function() {
|
||||||
if(!$(this).find('p').hasClass('dnd-total-error')) {
|
if(!$(this).find('p').hasClass('dnd-total-error')) {
|
||||||
$(this)
|
$(this)
|
||||||
.find('.panel-body')
|
.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 {
|
} else {
|
||||||
|
|
|
@ -102,7 +102,7 @@ function checklistsValidator(ev, checklists, editMode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var FileTypeEnum = Object.freeze({
|
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 %>
|
AVATAR: <%= Constants::AVATAR_MAX_SIZE_MB.megabytes %>
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ function filesSizeValidator(ev, fileInputs, fileTypeEnum) {
|
||||||
if (file.size > fileTypeEnum) {
|
if (file.size > fileTypeEnum) {
|
||||||
switch (fileTypeEnum) {
|
switch (fileTypeEnum) {
|
||||||
case FileTypeEnum.FILE:
|
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:
|
case FileTypeEnum.AVATAR:
|
||||||
return "<%= I18n.t 'general.file.size_exceeded', file_size: Constants::AVATAR_MAX_SIZE_MB %>".strToErrorFormat();
|
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) {
|
if (size > fileTypeEnum) {
|
||||||
switch (fileTypeEnum) {
|
switch (fileTypeEnum) {
|
||||||
case FileTypeEnum.FILE:
|
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:
|
case FileTypeEnum.AVATAR:
|
||||||
return "<%= I18n.t('users.registrations.edit.avatar_total_size', size: Constants::AVATAR_MAX_SIZE_MB) %>".strToErrorFormat();
|
return "<%= I18n.t('users.registrations.edit.avatar_total_size', size: Constants::AVATAR_MAX_SIZE_MB) %>".strToErrorFormat();
|
||||||
}
|
}
|
||||||
|
|
|
@ -618,7 +618,7 @@ class ProtocolsController < ApplicationController
|
||||||
end
|
end
|
||||||
return 0 # return 0 stops the rest of the controller code from executing
|
return 0 # return 0 stops the rest of the controller code from executing
|
||||||
end
|
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
|
@protocolsio_too_big = true
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js {}
|
format.js {}
|
||||||
|
|
|
@ -191,7 +191,7 @@ class RepositoriesController < ApplicationController
|
||||||
)
|
)
|
||||||
if parsed_file.too_large?
|
if parsed_file.too_large?
|
||||||
repository_response(t('general.file.size_exceeded',
|
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?
|
elsif parsed_file.has_too_many_rows?
|
||||||
repository_response(
|
repository_response(
|
||||||
t('repositories.import_records.error_message.items_limit',
|
t('repositories.import_records.error_message.items_limit',
|
||||||
|
|
|
@ -11,9 +11,9 @@ class TeamsController < ApplicationController
|
||||||
unless import_params[:file]
|
unless import_params[:file]
|
||||||
return parse_sheet_error(t('teams.parse_sheet.errors.no_file_selected'))
|
return parse_sheet_error(t('teams.parse_sheet.errors.no_file_selected'))
|
||||||
end
|
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',
|
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)
|
return parse_sheet_error(error)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -276,7 +276,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
|
||||||
success_action_status: '201',
|
success_action_status: '201',
|
||||||
acl: 'public-read',
|
acl: 'public-read',
|
||||||
storage_class: "REDUCED_REDUNDANCY",
|
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
|
content_type: content_type
|
||||||
)
|
)
|
||||||
posts.push({
|
posts.push({
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Asset < ApplicationRecord
|
||||||
validates_attachment :file,
|
validates_attachment :file,
|
||||||
presence: true,
|
presence: true,
|
||||||
size: {
|
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 :estimated_size, presence: true
|
||||||
validates :file_present, inclusion: { in: [true, false] }
|
validates :file_present, inclusion: { in: [true, false] }
|
||||||
|
|
|
@ -18,7 +18,7 @@ class TinyMceAsset < ApplicationRecord
|
||||||
validates_attachment :image,
|
validates_attachment :image,
|
||||||
presence: true,
|
presence: true,
|
||||||
size: {
|
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 :estimated_size, presence: true
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ module ImportRepository
|
||||||
end
|
end
|
||||||
|
|
||||||
def too_large?
|
def too_large?
|
||||||
@file.size > Constants::FILE_MAX_SIZE_MB.megabytes
|
@file.size > Rails.configuration.x.file_max_size_mb.megabytes
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_too_many_rows?
|
def has_too_many_rows?
|
||||||
|
|
|
@ -4,7 +4,7 @@ $('#modal-import-json-protocol').on('hidden.bs.modal', function () {
|
||||||
<% if @protocolsio_too_big %>
|
<% if @protocolsio_too_big %>
|
||||||
$('#modal-import-json-protocol').modal('hide');
|
$('#modal-import-json-protocol').modal('hide');
|
||||||
HelperModule.flashAlertMsg(' <%= t('my_modules.protocols.load_from_file_size_error',
|
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 %>
|
<% elsif @protocolsio_invalid_file %>
|
||||||
$('#modal-import-json-protocol').modal('hide');
|
$('#modal-import-json-protocol').modal('hide');
|
||||||
HelperModule.flashAlertMsg(' <%= t('my_modules.protocols.load_from_file_invalid_error') %>','danger');
|
HelperModule.flashAlertMsg(' <%= t('my_modules.protocols.load_from_file_invalid_error') %>','danger');
|
||||||
|
|
|
@ -26,6 +26,9 @@ module Scinote
|
||||||
|
|
||||||
config.active_job.queue_adapter = :delayed_job
|
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
|
# Logging
|
||||||
config.log_formatter = proc do |severity, datetime, progname, msg|
|
config.log_formatter = proc do |severity, datetime, progname, msg|
|
||||||
"[#{datetime}] #{severity}: #{msg}\n"
|
"[#{datetime}] #{severity}: #{msg}\n"
|
||||||
|
|
|
@ -64,8 +64,6 @@ class Constants
|
||||||
|
|
||||||
# Max table JSON size in MB
|
# Max table JSON size in MB
|
||||||
TABLE_JSON_MAX_SIZE_MB = 20
|
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
|
# Max uploaded user picture avatar size in MB
|
||||||
AVATAR_MAX_SIZE_MB = 0.2
|
AVATAR_MAX_SIZE_MB = 0.2
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue