diff --git a/app/models/observer/ticket/article/fillup_from_email.rb b/app/models/observer/ticket/article/fillup_from_email.rb index 4ba9cf032..86c2fba6d 100644 --- a/app/models/observer/ticket/article/fillup_from_email.rb +++ b/app/models/observer/ticket/article/fillup_from_email.rb @@ -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 diff --git a/db/migrate/20201201000001_setting_add_sender_format_agent_name.rb b/db/migrate/20201201000001_setting_add_sender_format_agent_name.rb new file mode 100644 index 000000000..9d8f4e3ce --- /dev/null +++ b/db/migrate/20201201000001_setting_add_sender_format_agent_name.rb @@ -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 diff --git a/db/seeds/settings.rb b/db/seeds/settings.rb index 81264c158..2fa159eee 100644 --- a/db/seeds/settings.rb +++ b/db/seeds/settings.rb @@ -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', }, }, ], diff --git a/spec/models/ticket/article_spec.rb b/spec/models/ticket/article_spec.rb index e0ba48892..ef3981f53 100644 --- a/spec/models/ticket/article_spec.rb +++ b/spec/models/ticket/article_spec.rb @@ -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) }