Skip to content
Permalink
Browse files

Fixed issue #2728 - Put _type, _doc and _id to reserved words for obj…

…ect managaer becasue of elasticssearch internal use.
  • Loading branch information
zammad-sync authored and thorsteneckel committed Sep 2, 2019
1 parent 180502d commit f79555ecc63ad672b233b214469b0a9a10046660
Showing with 11 additions and 3 deletions.
  1. +2 −2 app/models/object_manager/attribute.rb
  2. +9 −1 spec/models/object_manager/attribute_spec.rb
@@ -899,13 +899,13 @@ def self.reset_database_info(model)
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
@@ -57,14 +57,22 @@
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
end.to raise_error "#{reserved_word} is a reserved word, please choose a different one"
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

0 comments on commit f79555e

Please sign in to comment.
You can’t perform that action at this time.