mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-04 12:14:37 +08:00
set limit on maximum number of dropdown list items [fixes SCI-2259]
This commit is contained in:
parent
bdb6554870
commit
b12f6f1b92
6 changed files with 18 additions and 5 deletions
|
@ -1,4 +1,5 @@
|
|||
class RepositoryListItem < ApplicationRecord
|
||||
include ActiveModel::Validations
|
||||
has_many :repository_list_values, inverse_of: :repository_list_item
|
||||
belongs_to :repository, inverse_of: :repository_list_items
|
||||
belongs_to :repository_column, inverse_of: :repository_list_items
|
||||
|
@ -12,4 +13,5 @@ class RepositoryListItem < ApplicationRecord
|
|||
presence: true,
|
||||
uniqueness: { scope: :repository_column, case_sensitive: false },
|
||||
length: { maximum: Constants::TEXT_MAX_LENGTH }
|
||||
validates_with RepositoryListItemValidator
|
||||
end
|
||||
|
|
9
app/validators/repository_list_item_validator.rb
Normal file
9
app/validators/repository_list_item_validator.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
class RepositoryListItemValidator < ActiveModel::Validator
|
||||
def validate(record)
|
||||
return unless record.repository_column
|
||||
items_length = record.repository_column.repository_list_items.size
|
||||
if items_length >= Constants::REPOSITORY_LIST_ITEMS_PER_COLUMN
|
||||
record.errors[:items_limit] << 'Maximum number of list items reached!'
|
||||
end
|
||||
end
|
||||
end
|
|
@ -64,8 +64,8 @@
|
|||
</div>
|
||||
<div class="alert alert-info" role="alert">
|
||||
<ul>
|
||||
<li><%= t('repositories.modal_parse.warning_1') %></li>
|
||||
<li><%= t('repositories.modal_parse.warning_2') %></li>
|
||||
<li><%=t 'repositories.modal_parse.warning_1', limit: Constants::REPOSITORY_LIST_ITEMS_PER_COLUMN %></li>
|
||||
<li><%=t 'repositories.modal_parse.warning_2' %></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -868,6 +868,8 @@ class Constants
|
|||
|
||||
EXPORTABLE_ZIP_EXPIRATION_DAYS = 7
|
||||
|
||||
REPOSITORY_LIST_ITEMS_PER_COLUMN = 500
|
||||
|
||||
# Very basic regex to check for validity of emails
|
||||
BASIC_EMAIL_REGEX = URI::MailTo::EMAIL_REGEXP
|
||||
|
||||
|
|
|
@ -966,7 +966,7 @@ en:
|
|||
delete: "Delete column"
|
||||
modal_parse:
|
||||
title: 'Import items'
|
||||
warning_1: 'Be careful when importing into Dropdown column/s! Each new unique cell value from the file will create a new Dropdown option. This could result in large amounts of Dropdown options.'
|
||||
warning_1: 'Be careful when importing into Dropdown column/s! Each new unique cell value from the file will create a new Dropdown option. Maximum nr. of Dropdown options is %{limit}.'
|
||||
warning_2: 'Importing into file columns is not supported.'
|
||||
modal_import:
|
||||
title: 'Import items'
|
||||
|
|
|
@ -22,14 +22,14 @@ RSpec.describe RepositoryListItem, type: :model do
|
|||
end
|
||||
|
||||
describe 'Validations' do
|
||||
let!(:user) { create :user }
|
||||
let!(:repository_one) { create :repository }
|
||||
it { should validate_presence_of(:data) }
|
||||
it do
|
||||
should validate_length_of(:data).is_at_most(Constants::TEXT_MAX_LENGTH)
|
||||
end
|
||||
|
||||
context 'has a uniq data scoped on repository column' do
|
||||
let!(:user) { create :user }
|
||||
let!(:repository_one) { create :repository }
|
||||
let!(:repository_column) do
|
||||
create :repository_column, name: 'My column', repository: repository_one
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue