Fixed issue #1671 - Add config option for intelligent customer selection of incoming emails of agents.
This commit is contained in:
parent
b952880d5d
commit
9b0f51461b
4 changed files with 153 additions and 11 deletions
|
@ -22,9 +22,9 @@ module Channel::Filter::IdentifySender
|
|||
if !customer_user && mail[ 'x-zammad-customer-email'.to_sym ].present?
|
||||
customer_user = User.find_by(email: mail[ 'x-zammad-customer-email'.to_sym ])
|
||||
end
|
||||
if !customer_user
|
||||
|
||||
# get correct customer
|
||||
if !customer_user && Setting.get('postmaster_sender_is_agent_search_for_customer') == true
|
||||
if mail[ 'x-zammad-ticket-create-article-sender'.to_sym ] == 'Agent'
|
||||
|
||||
# get first recipient and set customer
|
||||
|
@ -46,9 +46,12 @@ module Channel::Filter::IdentifySender
|
|||
end
|
||||
end
|
||||
rescue => e
|
||||
Rails.logger.error 'ERROR: SenderIsSystemAddress: ' + e.inspect
|
||||
Rails.logger.error "SenderIsSystemAddress: ##{e.inspect}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# take regular from as customer
|
||||
if !customer_user
|
||||
customer_user = user_create(
|
||||
login: mail[ 'x-zammad-customer-login'.to_sym ] || mail[ 'x-zammad-customer-email'.to_sym ] || mail[:from_email],
|
||||
|
@ -57,7 +60,7 @@ module Channel::Filter::IdentifySender
|
|||
email: mail[ 'x-zammad-customer-email'.to_sym ] || mail[:from_email],
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
create_recipients(mail)
|
||||
mail[ 'x-zammad-ticket-customer_id'.to_sym ] = customer_user.id
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
class EmailProcessCustomerSelectionBasedOnSenderRecipient < ActiveRecord::Migration[4.2]
|
||||
def up
|
||||
|
||||
# return if it's a new setup
|
||||
return if !Setting.find_by(name: 'system_init_done')
|
||||
|
||||
Setting.create_if_not_exists(
|
||||
title: 'Customer selection based on sender and receiver list',
|
||||
name: 'postmaster_sender_is_agent_search_for_customer',
|
||||
area: 'Email::Base',
|
||||
description: 'If the sender is an agent, set the first user in the recipient list as a customer.',
|
||||
options: {
|
||||
form: [
|
||||
{
|
||||
display: '',
|
||||
null: true,
|
||||
name: 'postmaster_sender_is_agent_search_for_customer',
|
||||
tag: 'boolean',
|
||||
options: {
|
||||
true => 'yes',
|
||||
false => 'no',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
state: true,
|
||||
preferences: {
|
||||
permission: ['admin.channel_email'],
|
||||
},
|
||||
frontend: false
|
||||
)
|
||||
end
|
||||
|
||||
end
|
|
@ -2041,6 +2041,32 @@ Setting.create_if_not_exists(
|
|||
frontend: false
|
||||
)
|
||||
|
||||
Setting.create_if_not_exists(
|
||||
title: 'Customer selection based on sender and receiver list',
|
||||
name: 'postmaster_sender_is_agent_search_for_customer',
|
||||
area: 'Email::Base',
|
||||
description: 'If the sender is an agent, set the first user in the recipient list as a customer.',
|
||||
options: {
|
||||
form: [
|
||||
{
|
||||
display: '',
|
||||
null: true,
|
||||
name: 'postmaster_sender_is_agent_search_for_customer',
|
||||
tag: 'boolean',
|
||||
options: {
|
||||
true => 'yes',
|
||||
false => 'no',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
state: true,
|
||||
preferences: {
|
||||
permission: ['admin.channel_email'],
|
||||
},
|
||||
frontend: false
|
||||
)
|
||||
|
||||
Setting.create_if_not_exists(
|
||||
title: 'Notification Sender',
|
||||
name: 'notification_sender',
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
|
||||
require 'test_helper'
|
||||
|
||||
class EmailProcessCustomerSelectionBasedOnSenderRecipient < ActiveSupport::TestCase
|
||||
|
||||
setup do
|
||||
groups = Group.all
|
||||
roles = Role.where(name: 'Agent')
|
||||
@agent1 = User.create_or_update(
|
||||
login: 'user-customer-selection-agent1@example.com',
|
||||
firstname: 'UserOutOfOffice',
|
||||
lastname: 'Agent1',
|
||||
email: 'user-customer-selection-agent1@example.com',
|
||||
password: 'agentpw',
|
||||
active: true,
|
||||
roles: roles,
|
||||
groups: groups,
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
roles = Role.where(name: 'Customer')
|
||||
@customer1 = User.create_or_update(
|
||||
login: 'user-customer-selection-customer1@example.com',
|
||||
firstname: 'UserOutOfOffice',
|
||||
lastname: 'customer1',
|
||||
email: 'user-customer-selection-customer1@example.com',
|
||||
password: 'customerpw',
|
||||
active: true,
|
||||
roles: roles,
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
end
|
||||
|
||||
test 'customer need to be customer' do
|
||||
|
||||
email_raw_string = "From: #{@agent1.email}
|
||||
To: #{@customer1.email}
|
||||
Subject: test
|
||||
|
||||
Some Text"
|
||||
|
||||
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||
ticket = Ticket.find(ticket_p.id)
|
||||
article = Ticket::Article.find(article_p.id)
|
||||
assert_equal('test', ticket.title)
|
||||
assert_equal('new', ticket.state.name)
|
||||
assert_equal('Agent', ticket.create_article_sender.name)
|
||||
assert_equal('Agent', article.sender.name)
|
||||
assert_equal(@customer1.email, ticket.customer.email)
|
||||
assert_equal(@customer1.firstname, ticket.customer.firstname)
|
||||
assert_equal(@customer1.lastname, ticket.customer.lastname)
|
||||
|
||||
end
|
||||
|
||||
test 'agent need to be customer' do
|
||||
|
||||
Setting.set('postmaster_sender_is_agent_search_for_customer', false)
|
||||
|
||||
email_raw_string = "From: #{@agent1.email}
|
||||
To: #{@customer1.email}
|
||||
Subject: test
|
||||
|
||||
Some Text"
|
||||
|
||||
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||
ticket = Ticket.find(ticket_p.id)
|
||||
article = Ticket::Article.find(article_p.id)
|
||||
assert_equal('test', ticket.title)
|
||||
assert_equal('new', ticket.state.name)
|
||||
assert_equal('Agent', ticket.create_article_sender.name)
|
||||
assert_equal('Agent', article.sender.name)
|
||||
assert_equal(@agent1.email, ticket.customer.email)
|
||||
assert_equal(@agent1.firstname, ticket.customer.firstname)
|
||||
assert_equal(@agent1.lastname, ticket.customer.lastname)
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue