Skip to content
Permalink
Browse files

Martin Edenhofer's avatar Fixed issue #2719 - Unable to set owner via…

… `X-Zammad-Ticket-owner` header.
  • Loading branch information
zammad-sync committed Aug 26, 2019
1 parent ffa2b61 commit bea44638d5846356b20bac504cb130507b3534c4
Showing with 110 additions and 4 deletions.
  1. +6 −4 app/models/channel/email_parser.rb
  2. +104 −0 test/unit/email_process_test.rb
@@ -417,7 +417,7 @@ def set_attributes_by_x_headers(item_object, header_name, mail, suffix = false)
end

# 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]}"
item_object.class.reflect_on_all_associations.map do |assoc|
@@ -426,14 +426,16 @@ def set_attributes_by_x_headers(item_object, header_name, mail, suffix = false)

Rails.logger.info "set_attributes_by_x_headers found #{assoc.class_name} lookup for '#{mail[header.to_sym]}'"
item = assoc.class_name.constantize

assoc_object = nil
if item.respond_to?(:name)
if item.new.respond_to?(:name)
assoc_object = item.lookup(name: mail[header.to_sym])
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])
end
if !assoc_object && item.new.respond_to?(:email)
assoc_object = item.lookup(email: mail[header.to_sym])
end

if assoc_object.blank?

@@ -3180,6 +3180,31 @@ class EmailProcessTest < ActiveSupport::TestCase
end

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 = [
{
data: 'From: me@example.com
@@ -3199,6 +3224,7 @@ class EmailProcessTest < ActiveSupport::TestCase
Subject: some subject
X-Zammad-Ticket-Followup-State: closed
X-Zammad-Ticket-priority: 3 high
X-Zammad-Ticket-owner: agent1@example.com
X-Zammad-Article-sender: System
x-Zammad-Article-type: phone
x-Zammad-Article-Internal: true
@@ -3213,6 +3239,7 @@ class EmailProcessTest < ActiveSupport::TestCase
state: 'new',
priority: '3 high',
title: 'some subject',
owner: agent1,
},
1 => {
sender: 'System',
@@ -3227,6 +3254,7 @@ class EmailProcessTest < ActiveSupport::TestCase
Subject: some subject
X-Zammad-Ticket-Followup-State: closed
X-Zammad-Ticket-priority_id: 777777
X-Zammad-Ticket-owner: not_existing@example.com
X-Zammad-Article-sender_id: 999999
x-Zammad-Article-type: phone
x-Zammad-Article-Internal: true
@@ -3241,6 +3269,7 @@ class EmailProcessTest < ActiveSupport::TestCase
state: 'new',
priority: '2 normal',
title: 'some subject',
owner: User.find(1),
},
1 => {
sender: 'Customer',
@@ -3249,6 +3278,81 @@ class EmailProcessTest < ActiveSupport::TestCase
},
},
},
{
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)
end

0 comments on commit bea4463

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