Fixed issue #2728 - Put _type, _doc and _id to reserved words for object managaer becasue of elasticssearch internal use.

This commit is contained in:
Martin Edenhofer 2019-09-02 18:20:32 +02:00 committed by Thorsten Eckel
parent 180502d03b
commit f79555ecc6
2 changed files with 11 additions and 3 deletions

View file

@ -899,13 +899,13 @@ is certain attribute used by triggers, overviews or schedulers
def check_name
return if !name
raise 'Name can\'t get used, *_id and *_ids are not allowed' if name.match?(/_(id|ids)$/i) || name.match?(/^id$/i)
raise 'Name can\'t get used, *_id and *_ids are not allowed' if name.match?(/.+?_(id|ids)$/i)
raise 'Spaces in name are not allowed' if name.match?(/\s/)
raise 'Only letters from a-z, numbers from 0-9, and _ are allowed' if !name.match?(/^[a-z0-9_]+$/)
raise 'At least one letters is needed' if !name.match?(/[a-z]/)
# do not allow model method names as attributes
reserved_words = %w[destroy true false integer select drop create alter index table varchar blob date datetime timestamp url icon initials avatar permission validate subscribe unsubscribe translate search]
reserved_words = %w[destroy true false integer select drop create alter index table varchar blob date datetime timestamp url icon initials avatar permission validate subscribe unsubscribe translate search _type _doc _id id]
raise "#{name} is a reserved word, please choose a different one" if name.match?(/^(#{reserved_words.join('|')})$/)
# fixes issue #2236 - Naming an attribute "attribute" causes ActiveRecord failure

View file

@ -57,7 +57,7 @@ RSpec.describe ObjectManager::Attribute, type: :model do
end.to raise_error 'attribute is a reserved word, please choose a different one'
end
%w[destroy true false integer select drop create alter index table varchar blob date datetime timestamp url icon initials avatar permission validate subscribe unsubscribe translate search].each do |reserved_word|
%w[destroy true false integer select drop create alter index table varchar blob date datetime timestamp url icon initials avatar permission validate subscribe unsubscribe translate search _type _doc _id id].each do |reserved_word|
it "rejects Zammad reserved word '#{reserved_word}'" do
expect do
ObjectManager::Attribute.add attributes_for :object_manager_attribute_text, name: reserved_word
@ -65,6 +65,14 @@ RSpec.describe ObjectManager::Attribute, type: :model do
end
end
%w[someting_id something_ids].each do |reserved_word|
it "rejects word '#{reserved_word}' which is used for database references" do
expect do
ObjectManager::Attribute.add attributes_for :object_manager_attribute_text, name: reserved_word
end.to raise_error "Name can't get used, *_id and *_ids are not allowed"
end
end
it 'rejects duplicate attribute name of conflicting types' do
attribute = attributes_for :object_manager_attribute_text
ObjectManager::Attribute.add attribute