Fixes #3743 - Owner selection empty or pending reminder data picker not shown if customer field has content but no customer is selected (in ticket create screen).

This commit is contained in:
Rolf Schmidt 2021-09-20 17:57:51 +02:00 committed by Thorsten Eckel
parent a389b8f07c
commit 3b18f7feaf
2 changed files with 18 additions and 16 deletions

View file

@ -47,31 +47,27 @@ returns
data.delete('id') data.delete('id')
end end
# get associations by id
attribute_associations = {}
reflect_on_all_associations.map do |assoc|
class_name = assoc.options[:class_name]
next if !class_name
attribute_associations["#{assoc.name}_id"] = assoc
end
# only use object attributes # only use object attributes
clean_params = ActiveSupport::HashWithIndifferentAccess.new clean_params = ActiveSupport::HashWithIndifferentAccess.new
new.attributes.each_key do |attribute| new.attributes.each_key do |attribute|
next if !data.key?(attribute) next if !data.key?(attribute)
invalid = false
# check reference records, referenced by _id attributes # check reference records, referenced by _id attributes
reflect_on_all_associations.map do |assoc| if attribute_associations[attribute].present? && data[attribute].present? && !attribute_associations[attribute].klass.lookup(id: data[attribute])
class_name = assoc.options[:class_name] raise Exceptions::UnprocessableEntity, "Invalid value for param '#{attribute}': #{data[attribute].inspect}" if exceptions
next if !class_name
name = "#{assoc.name}_id" next
next if !data.key?(name)
next if data[name].blank?
next if assoc.klass.lookup(id: data[name])
raise Exceptions::UnprocessableEntity, "Invalid value for param '#{name}': #{data[name].inspect}" if exceptions
invalid = true
break
end end
next if invalid
clean_params[attribute] = data[attribute] clean_params[attribute] = data[attribute]
end end

View file

@ -980,6 +980,12 @@ RSpec.describe Ticket, type: :model do
end end
end end
end end
describe '#param_cleanup' do
it 'does only remove parameters which are invalid and not the complete params hash if one element is invalid (#3743)' do
expect(described_class.param_cleanup({ state_id: 3, customer_id: 'guess:1234' }, true, false, false)).to eq({ 'state_id' => 3 })
end
end
end end
describe 'Attributes:' do describe 'Attributes:' do