Martin Edenhofer's avatar Fixed issue #2719 - Unable to set owner via X-Zammad-Ticket-owner header.

This commit is contained in:
Martin Edenhofer 2019-08-26 22:14:33 +02:00
parent ffa2b61087
commit bea44638d5
2 changed files with 110 additions and 4 deletions

View file

@ -417,7 +417,7 @@ returns
end end
# only set value on _id if value/reference lookup exists # only set value on _id if value/reference lookup exists
if mail[ header.to_sym ] if mail[header.to_sym]
Rails.logger.info "set_attributes_by_x_headers header #{header} found #{mail[header.to_sym]}" Rails.logger.info "set_attributes_by_x_headers header #{header} found #{mail[header.to_sym]}"
item_object.class.reflect_on_all_associations.map do |assoc| item_object.class.reflect_on_all_associations.map do |assoc|
@ -426,14 +426,16 @@ returns
Rails.logger.info "set_attributes_by_x_headers found #{assoc.class_name} lookup for '#{mail[header.to_sym]}'" Rails.logger.info "set_attributes_by_x_headers found #{assoc.class_name} lookup for '#{mail[header.to_sym]}'"
item = assoc.class_name.constantize item = assoc.class_name.constantize
assoc_object = nil assoc_object = nil
if item.respond_to?(:name) if item.new.respond_to?(:name)
assoc_object = item.lookup(name: mail[header.to_sym]) assoc_object = item.lookup(name: mail[header.to_sym])
end end
if !assoc_object && item.respond_to?(:login) if !assoc_object && item.new.respond_to?(:login)
assoc_object = item.lookup(login: mail[header.to_sym]) assoc_object = item.lookup(login: mail[header.to_sym])
end end
if !assoc_object && item.new.respond_to?(:email)
assoc_object = item.lookup(email: mail[header.to_sym])
end
if assoc_object.blank? if assoc_object.blank?

View file

@ -3180,6 +3180,31 @@ Content-Type: text/html; charset=us-ascii; format=flowed
end end
test 'process trusted' do test 'process trusted' do
groups = Group.all
roles = Role.where(name: 'Agent')
agent1 = User.create!(
login: 'agent1',
firstname: 'Firstname',
lastname: 'agent1',
email: 'agent1@example.com',
active: true,
roles: roles,
groups: groups,
updated_by_id: 1,
created_by_id: 1,
)
roles = Role.where(name: 'Customer')
customer1 = User.create!(
login: 'customer1',
firstname: 'Firstname',
lastname: 'customer1',
email: 'customer1@example.com',
active: true,
roles: roles,
updated_by_id: 1,
created_by_id: 1,
)
files = [ files = [
{ {
data: 'From: me@example.com data: 'From: me@example.com
@ -3199,6 +3224,7 @@ To: customer@example.com
Subject: some subject Subject: some subject
X-Zammad-Ticket-Followup-State: closed X-Zammad-Ticket-Followup-State: closed
X-Zammad-Ticket-priority: 3 high X-Zammad-Ticket-priority: 3 high
X-Zammad-Ticket-owner: agent1@example.com
X-Zammad-Article-sender: System X-Zammad-Article-sender: System
x-Zammad-Article-type: phone x-Zammad-Article-type: phone
x-Zammad-Article-Internal: true x-Zammad-Article-Internal: true
@ -3213,6 +3239,7 @@ Some Text',
state: 'new', state: 'new',
priority: '3 high', priority: '3 high',
title: 'some subject', title: 'some subject',
owner: agent1,
}, },
1 => { 1 => {
sender: 'System', sender: 'System',
@ -3227,6 +3254,7 @@ To: customer@example.com
Subject: some subject Subject: some subject
X-Zammad-Ticket-Followup-State: closed X-Zammad-Ticket-Followup-State: closed
X-Zammad-Ticket-priority_id: 777777 X-Zammad-Ticket-priority_id: 777777
X-Zammad-Ticket-owner: not_existing@example.com
X-Zammad-Article-sender_id: 999999 X-Zammad-Article-sender_id: 999999
x-Zammad-Article-type: phone x-Zammad-Article-type: phone
x-Zammad-Article-Internal: true x-Zammad-Article-Internal: true
@ -3241,6 +3269,7 @@ Some Text',
state: 'new', state: 'new',
priority: '2 normal', priority: '2 normal',
title: 'some subject', title: 'some subject',
owner: User.find(1),
}, },
1 => { 1 => {
sender: 'Customer', sender: 'Customer',
@ -3249,6 +3278,81 @@ Some Text',
}, },
}, },
}, },
{
data: 'From: me@example.com
To: customer@example.com
Subject: some subject / with customer as agent - customer can not be owner
X-Zammad-Ticket-owner: customer1@example.com
Some Text',
channel: {
trusted: true,
},
success: true,
result: {
0 => {
state: 'new',
priority: '2 normal',
title: 'some subject / with customer as agent - customer can not be owner',
owner: User.find(1),
},
1 => {
sender: 'Customer',
type: 'email',
internal: false,
},
},
},
{
data: 'From: me@example.com
To: customer@example.com
Subject: some subject / with agent login
X-Zammad-Ticket-owner: agent1
Some Text',
channel: {
trusted: true,
},
success: true,
result: {
0 => {
state: 'new',
priority: '2 normal',
title: 'some subject / with agent login',
owner: agent1,
},
1 => {
sender: 'Customer',
type: 'email',
internal: false,
},
},
},
{
data: 'From: me@example.com
To: customer@example.com
Subject: some subject / with agent email
X-Zammad-Ticket-owner: agent1@example.com
Some Text',
channel: {
trusted: true,
},
success: true,
result: {
0 => {
state: 'new',
priority: '2 normal',
title: 'some subject / with agent email',
owner: agent1,
},
1 => {
sender: 'Customer',
type: 'email',
internal: false,
},
},
},
] ]
assert_process(files) assert_process(files)
end end