Fixes #3890 - 'Sender Format' set to 'Agent Name' causes empty display names in triggers
This commit is contained in:
parent
76fe4ce0e7
commit
3b513dc670
2 changed files with 20 additions and 3 deletions
|
@ -69,6 +69,10 @@ module Ticket::Article::AddsMetadataEmail
|
||||||
elsif Setting.get('ticket_define_email_from') == 'AgentName'
|
elsif Setting.get('ticket_define_email_from') == 'AgentName'
|
||||||
sender = User.find(created_by_id)
|
sender = User.find(created_by_id)
|
||||||
realname = "#{sender.firstname} #{sender.lastname}"
|
realname = "#{sender.firstname} #{sender.lastname}"
|
||||||
|
|
||||||
|
# avoid "-" as realname, see https://github.com/zammad/zammad/issues/3890
|
||||||
|
realname = email_address.realname if sender.id == 1
|
||||||
|
|
||||||
self.from = Channel::EmailBuild.recipient_line(realname, email_address.email)
|
self.from = Channel::EmailBuild.recipient_line(realname, email_address.email)
|
||||||
else
|
else
|
||||||
self.from = Channel::EmailBuild.recipient_line(email_address.realname, email_address.email)
|
self.from = Channel::EmailBuild.recipient_line(email_address.realname, email_address.email)
|
||||||
|
|
|
@ -34,7 +34,7 @@ RSpec.describe Ticket::Article, type: :model do
|
||||||
|
|
||||||
describe 'Setting of ticket_define_email_from' do
|
describe 'Setting of ticket_define_email_from' do
|
||||||
subject(:article) do
|
subject(:article) do
|
||||||
create(:ticket_article, sender_name: 'Agent', type_name: 'email')
|
create(:ticket_article, created_by: created_by, sender_name: 'Agent', type_name: 'email')
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when AgentName' do
|
context 'when AgentName' do
|
||||||
|
@ -42,9 +42,22 @@ RSpec.describe Ticket::Article, type: :model do
|
||||||
Setting.set('ticket_define_email_from', 'AgentName')
|
Setting.set('ticket_define_email_from', 'AgentName')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the from based on the setting' do
|
context 'with real sender' do
|
||||||
expect(article.reload.from).to eq("\"#{article.created_by.firstname} #{article.created_by.lastname}\" <#{article.ticket.group.email_address.email}>")
|
let(:created_by) { create(:user) }
|
||||||
|
|
||||||
|
it 'sets the from to the realname of the user' do
|
||||||
|
expect(article.reload.from).to eq("\"#{article.created_by.firstname} #{article.created_by.lastname}\" <#{article.ticket.group.email_address.email}>")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with no real sender (e.g. trigger or scheduler)' do
|
||||||
|
let(:created_by) { User.find(1) }
|
||||||
|
|
||||||
|
it 'sets the from to realname of the mail address)' do
|
||||||
|
expect(article.reload.from).to eq("\"#{article.ticket.group.email_address.realname}\" <#{article.ticket.group.email_address.email}>")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue