Fixes #3319, Closes #2496 - Make it possible to only send with agent name.

This commit is contained in:
Mike Raunsbæk 2020-12-01 11:34:04 +01:00 committed by Thorsten Eckel
parent d684ffa7ba
commit a4b82a6634
4 changed files with 33 additions and 0 deletions

View file

@ -59,6 +59,10 @@ class Observer::Ticket::Article::FillupFromEmail < ActiveRecord::Observer
sender = User.find(record.created_by_id)
realname = "#{sender.firstname} #{sender.lastname} #{separator} #{email_address.realname}"
record.from = Channel::EmailBuild.recipient_line(realname, email_address.email)
elsif Setting.get('ticket_define_email_from') == 'AgentName'
sender = User.find(record.created_by_id)
realname = "#{sender.firstname} #{sender.lastname}"
record.from = Channel::EmailBuild.recipient_line(realname, email_address.email)
else
record.from = Channel::EmailBuild.recipient_line(email_address.realname, email_address.email)
end

View file

@ -0,0 +1,12 @@
class SettingAddSenderFormatAgentName < ActiveRecord::Migration[5.1]
def up
# return if it's a new setup
return if !Setting.exists?(name: 'system_init_done')
setting = Setting.find_by(name: 'ticket_define_email_from')
return if !setting
setting.options[:form][0][:options][:AgentName] = 'Agent Name'
setting.save!
end
end

View file

@ -2524,6 +2524,7 @@ Setting.create_if_not_exists(
options: {
SystemAddressName: 'System Address Display Name',
AgentNameSystemAddressName: 'Agent Name + FromSeparator + System Address Display Name',
AgentName: 'Agent Name',
},
},
],

View file

@ -27,6 +27,22 @@ RSpec.describe Ticket::Article, type: :model do
end
end
describe 'Setting of ticket_define_email_from' do
subject(:article) do
create(:ticket_article, sender_name: 'Agent', type_name: 'email')
end
context 'when AgentName' do
before do
Setting.set('ticket_define_email_from', 'AgentName')
end
it 'sets the from based on the setting' do
expect(article.reload.from).to eq("\"#{article.created_by.firstname} #{article.created_by.lastname}\" <#{article.ticket.group.email_address.email}>")
end
end
end
describe 'Setting of ticket.create_article_{sender,type}' do
let!(:ticket) { create(:ticket) }