Fixed issue#190 - differ between ticket customer and the user who sends the email.

This commit is contained in:
Martin Edenhofer 2016-08-23 11:49:12 +02:00
parent 4319023ad1
commit 9797dbb1d4
4 changed files with 45 additions and 19 deletions

View file

@ -385,7 +385,7 @@ retrns
File.open(filename, 'wb') { |file|
file.write msg
}
raise e.inspect
raise e.inspect + e.backtrace.inspect
end
@ -428,18 +428,18 @@ retrns
# use transaction
ActiveRecord::Base.transaction do
# create sender if needed
sender_user_id = mail[ 'x-zammad-customer-id'.to_sym ]
if !sender_user_id
raise 'No x-zammad-customer-id, no sender set!'
# get sender user
session_user_id = mail[ 'x-zammad-session-user-id'.to_sym ]
if !session_user_id
raise 'No x-zammad-session-user-id, no sender set!'
end
user = User.lookup(id: sender_user_id)
if !user
raise "No user found for x-zammad-customer-id: #{sender_user_id}!"
session_user = User.lookup(id: session_user_id)
if !session_user
raise "No user found for x-zammad-session-user-id: #{session_user_id}!"
end
# set current user
UserInfo.current_user_id = user.id
UserInfo.current_user_id = session_user.id
# get ticket# based on email headers
if mail[ 'x-zammad-ticket-id'.to_sym ]
@ -468,7 +468,7 @@ retrns
if !mail[ 'x-zammad-ticket-followup-state'.to_sym ]
if state_type.name != 'new' && !mail[ 'x-zammad-out-of-office'.to_sym ]
ticket.state = Ticket::State.find_by(name: 'open')
ticket.save
ticket.save!
end
end
end
@ -496,7 +496,6 @@ retrns
end
ticket = Ticket.new(
group_id: group.id,
customer_id: user.id,
title: mail[:subject] || '',
state_id: Ticket::State.find_by(name: 'new').id,
priority_id: Ticket::Priority.find_by(name: '2 normal').id,

View file

@ -4,14 +4,14 @@ module Channel::Filter::IdentifySender
def self.run(_channel, mail)
customer_user_id = mail[ 'x-zammad-customer-id'.to_sym ]
customer_user_id = mail[ 'x-zammad-ticket-customer_id'.to_sym ]
customer_user = nil
if !customer_user_id.empty?
customer_user = User.lookup(id: customer_user_id)
if customer_user
Rails.logger.debug "Took customer form x-zammad-customer-id header '#{customer_user_id}'."
Rails.logger.debug "Took customer form x-zammad-ticket-customer_id header '#{customer_user_id}'."
else
Rails.logger.debug "Invalid x-zammad-customer-id header '#{customer_user_id}', no such user."
Rails.logger.debug "Invalid x-zammad-ticket-customer_id header '#{customer_user_id}', no such user - take user from 'from'-header."
end
end
@ -58,10 +58,31 @@ module Channel::Filter::IdentifySender
)
end
end
create_recipients(mail)
mail[ 'x-zammad-ticket-customer_id'.to_sym ] = customer_user.id
mail[ 'x-zammad-customer-id'.to_sym ] = customer_user.id
# find session user
session_user_id = mail[ 'x-zammad-session-user-id'.to_sym ]
session_user = nil
if !session_user_id.empty?
session_user = User.lookup(id: session_user_id)
if session_user
Rails.logger.debug "Took session form x-zammad-session-user-id header '#{session_user_id}'."
else
Rails.logger.debug "Invalid x-zammad-session-user-id header '#{session_user_id}', no such user - take user from 'from'-header."
end
end
if !session_user
session_user = user_create(
login: mail[:from_email],
firstname: mail[:from_display_name],
lastname: '',
email: mail[:from_email],
)
end
if session_user
mail[ 'x-zammad-session-user-id'.to_sym ] = session_user.id
end
end
# create to and cc user

View file

@ -22,8 +22,8 @@ class Channel::Filter::MonitoringBase
return if !mail[:from]
return if !mail[:body]
sender_user_id = mail[ 'x-zammad-customer-id'.to_sym ]
return if !sender_user_id
session_user_id = mail[ 'x-zammad-session-user-id'.to_sym ]
return if !session_user_id
# check if sender is monitoring
return if !mail[:from].match(/#{sender}/i)
@ -43,7 +43,7 @@ class Channel::Filter::MonitoringBase
}
# check if ticket with host is open
customer = User.lookup(id: sender_user_id)
customer = User.lookup(id: session_user_id)
# follow up detection by meta data
open_states = Ticket::State.by_category('open')

View file

@ -138,6 +138,8 @@ Some Text"
assert_equal('Customer', ticket.create_article_sender.name)
assert_equal('Customer', article.sender.name)
assert_equal('ticket-system-sender-customer1@example.com', ticket.customer.email)
assert_equal(customer1.id, ticket.created_by_id)
assert_equal(customer1.id, article.created_by_id)
# process agent email
email_raw_string = "From: ticket-system-sender-agent1@example.com
@ -154,6 +156,8 @@ Some Text"
assert_equal('Agent', ticket.create_article_sender.name)
assert_equal('Agent', article.sender.name)
assert_equal('ticket-system-sender-customer1@example.com', ticket.customer.email)
assert_equal(agent1.id, ticket.created_by_id)
assert_equal(agent1.id, article.created_by_id)
email_raw_string = "From: ticket-system-sender-agent1@example.com
To: myzammad@system.test, ticket-system-sender-customer1@example.com
@ -169,6 +173,8 @@ Some Text"
assert_equal('Agent', ticket.create_article_sender.name)
assert_equal('Agent', article.sender.name)
assert_equal('ticket-system-sender-customer1@example.com', ticket.customer.email)
assert_equal(agent1.id, ticket.created_by_id)
assert_equal(agent1.id, article.created_by_id)
end
end