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')
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
clean_params = ActiveSupport::HashWithIndifferentAccess.new
new.attributes.each_key do |attribute|
next if !data.key?(attribute)
invalid = false
# check reference records, referenced by _id attributes
reflect_on_all_associations.map do |assoc|
class_name = assoc.options[:class_name]
next if !class_name
if attribute_associations[attribute].present? && data[attribute].present? && !attribute_associations[attribute].klass.lookup(id: data[attribute])
raise Exceptions::UnprocessableEntity, "Invalid value for param '#{attribute}': #{data[attribute].inspect}" if exceptions
name = "#{assoc.name}_id"
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
next
end
next if invalid
clean_params[attribute] = data[attribute]
end

View file

@ -980,6 +980,12 @@ RSpec.describe Ticket, type: :model do
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
describe 'Attributes:' do