Limits the max. amount of rows when importing into inventories [fixes SCI-2468]

This commit is contained in:
zmagod 2018-05-31 10:45:31 +02:00
parent 58e6701b0a
commit 9abf50e7c5
4 changed files with 12 additions and 0 deletions

View file

@ -192,6 +192,11 @@ class RepositoriesController < ApplicationController
if parsed_file.too_large?
repository_response(t('general.file.size_exceeded',
file_size: Constants::FILE_MAX_SIZE_MB))
elsif parsed_file.has_too_many_rows?
repository_response(
t('repositories.import_records.error_message.items_limit',
items_size: Constants::IMPORT_REPOSITORY_ITEMS_LIMIT)
)
else
@import_data = parsed_file.data

View file

@ -24,6 +24,10 @@ module ImportRepository
@file.size > Constants::FILE_MAX_SIZE_MB.megabytes
end
def has_too_many_rows?
@sheet.last_row > Constants::IMPORT_REPOSITORY_ITEMS_LIMIT
end
def generate_temp_file
# Save file for next step (importing)
temp_file = TempFile.new(

View file

@ -873,6 +873,8 @@ class Constants
REPOSITORY_LIST_ITEMS_PER_COLUMN = 500
IMPORT_REPOSITORY_ITEMS_LIMIT = 2000
# Very basic regex to check for validity of emails
BASIC_EMAIL_REGEX = URI::MailTo::EMAIL_REGEXP

View file

@ -959,6 +959,7 @@ en:
success_flash: "%{number_of_rows} new item(s) successfully imported."
partial_success_flash: "%{nr} of %{total_nr} successfully imported. Other rows contained errors."
error_message:
items_limit: "The imported file contains too many rows. Max %{items_size} items allowed to upload at once."
temp_file_not_found: "This file could not be found. Your session might expire."
session_expired: "Your session expired. Please try again."
no_data_to_parse: "There's nothing to be parsed."