Fixes #3811 - Able to create custom fields for existing relation (e. g. ticket.state) - will lead to non bootable Zammad.

This commit is contained in:
Martin Edenhofer 2021-10-19 10:38:20 +02:00 committed by Rolf Schmidt
parent 4264327d9b
commit 8561d97ddc
2 changed files with 17 additions and 1 deletions

View file

@ -834,7 +834,7 @@ is certain attribute used by triggers, overviews or schedulers
end
record = object_lookup.name.constantize.new
if record.respond_to?(name.to_sym) && record.attributes.key?(name) && new_record?
if new_record? && (record.respond_to?(name.to_sym) || record.attributes.key?(name))
errors.add(:name, "#{name} already exists!")
end

View file

@ -76,6 +76,22 @@ RSpec.describe ObjectManager::Attribute, type: :model do
end
end
%w[title tags].each do |not_editable_attribute|
it "rejects '#{not_editable_attribute}' which is used" do
expect do
described_class.add attributes_for :object_manager_attribute_text, name: not_editable_attribute
end.to raise_error(ActiveRecord::RecordInvalid, 'Validation failed: Name Attribute not editable!')
end
end
%w[priority state note number].each do |existing_attribute|
it "rejects '#{existing_attribute}' which is used" do
expect do
described_class.add attributes_for :object_manager_attribute_text, name: existing_attribute
end.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Name #{existing_attribute} already exists!")
end
end
it 'rejects duplicate attribute name of conflicting types' do
attribute = attributes_for :object_manager_attribute_text
described_class.add attribute