Skip to content
Snippets Groups Projects
Commit a1881c25 authored by Andrew Fontaine's avatar Andrew Fontaine Committed by Sean McGivern
Browse files

Add Username to Email From Header in Notifications

When replying to a notification from GitLab, it can be non-obvious as
to how to ping the person I am responding to without looking for their
username in Gitlab.

By adding the username to the From header in the form of From: User
Name (@user), it is much more clear as to how to ping a person in the
response.
parent 6810b0a9
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -70,7 +70,7 @@ def sender(sender_id, send_from_user_email: false, sender_name: nil)
return unless sender = User.find(sender_id)
 
address = default_sender_address
address.display_name = sender_name.presence || sender.name
address.display_name = sender_name.presence || "#{sender.name} (#{sender.to_reference})"
 
if send_from_user_email && can_send_from_user_email?(sender)
address.address = sender.email
Loading
Loading
---
title: Add Username to Email From Header in Notifications
merge_request: 56588
author:
type: changed
Loading
Loading
@@ -106,9 +106,7 @@
it_behaves_like 'an unsubscribeable thread'
 
it 'is sent as the last approver' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(last_approver.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(last_approver)
end
 
it 'has the correct subject' do
Loading
Loading
@@ -170,9 +168,7 @@
it_behaves_like 'an unsubscribeable thread'
 
it 'is sent as the last unapprover' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(last_unapprover.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(last_unapprover)
end
 
it 'has the correct subject' do
Loading
Loading
@@ -397,4 +393,10 @@
is_expected.to have_body_text recipient.confirmation_token
end
end
def expect_sender(user)
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq("#{user.name} (@#{user.username})")
expect(sender.address).to eq(gitlab_sender)
end
end
Loading
Loading
@@ -55,9 +55,7 @@
it_behaves_like 'appearance header and footer not enabled'
 
it 'is sent as the merge request author' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(merge_request.author.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(merge_request.author)
end
 
it 'has the correct subject and body' do
Loading
Loading
@@ -85,9 +83,7 @@
it_behaves_like 'appearance header and footer not enabled'
 
it 'is sent as the author' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(current_user.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(current_user)
end
 
it 'has the correct subject and body' do
Loading
Loading
@@ -120,9 +116,7 @@
it_behaves_like 'appearance header and footer not enabled'
 
it 'is sent as the merge author' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(merge_author.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(merge_author)
end
 
it 'has the correct subject and body' do
Loading
Loading
@@ -153,9 +147,7 @@
it_behaves_like 'appearance header and footer not enabled'
 
it 'is sent as the author' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(current_user.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(current_user)
end
 
it 'has the correct subject and body' do
Loading
Loading
@@ -229,4 +221,10 @@
it { expect(subject).to have_content('attachment has been truncated to avoid exceeding the maximum allowed attachment size of 15 MB.') }
end
end
def expect_sender(user)
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq("#{user.name} (@#{user.username})")
expect(sender.address).to eq(gitlab_sender)
end
end
Loading
Loading
@@ -69,11 +69,8 @@
it_behaves_like 'an email sent to a user'
 
it 'is sent to the assignee as the author' do
sender = subject.header[:from].addrs.first
aggregate_failures do
expect(sender.display_name).to eq(current_user.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(current_user)
expect(subject).to deliver_to(recipient.notification_email)
end
end
Loading
Loading
@@ -146,9 +143,7 @@
it_behaves_like 'appearance header and footer not enabled'
 
it 'is sent as the author' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(current_user.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(current_user)
end
 
it 'has the correct subject and body' do
Loading
Loading
@@ -187,9 +182,7 @@
it_behaves_like 'appearance header and footer not enabled'
 
it 'is sent as the author' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(current_user.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(current_user)
end
 
it 'has the correct subject and body' do
Loading
Loading
@@ -251,9 +244,7 @@
it_behaves_like 'appearance header and footer not enabled'
 
it 'is sent as the author' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(current_user.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(current_user)
end
 
it 'has the correct subject and body' do
Loading
Loading
@@ -389,9 +380,7 @@
it_behaves_like 'appearance header and footer not enabled'
 
it 'is sent as the author' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(current_user.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(current_user)
end
 
it 'has the correct subject and body' do
Loading
Loading
@@ -456,9 +445,7 @@
it_behaves_like 'appearance header and footer not enabled'
 
it 'is sent as the author' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(current_user.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(current_user)
end
 
it 'has the correct subject and body' do
Loading
Loading
@@ -486,10 +473,7 @@
it_behaves_like 'appearance header and footer not enabled'
 
it 'is sent as the push user' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(push_user.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(push_user)
end
 
it 'has the correct subject and body' do
Loading
Loading
@@ -1002,11 +986,8 @@ def invite_to_project(project, inviter:, user: nil)
it_behaves_like 'it should have Gmail Actions links'
 
it 'is sent to the given recipient as the author' do
sender = subject.header[:from].addrs[0]
aggregate_failures do
expect(sender.display_name).to eq(note_author.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(note_author)
expect(subject).to deliver_to(recipient.notification_email)
end
end
Loading
Loading
@@ -1162,11 +1143,8 @@ def create_note
it_behaves_like 'it should have Gmail Actions links'
 
it 'is sent to the given recipient as the author' do
sender = subject.header[:from].addrs[0]
aggregate_failures do
expect(sender.display_name).to eq(note_author.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(note_author)
expect(subject).to deliver_to(recipient.notification_email)
end
end
Loading
Loading
@@ -1221,12 +1199,6 @@ def create_note
issue.issue_email_participants.create!(email: 'service.desk@example.com')
end
 
def expect_sender(username)
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(username)
expect(sender.address).to eq(gitlab_sender)
end
describe 'thank you email' do
subject { described_class.service_desk_thank_you_email(issue.id) }
 
Loading
Loading
@@ -1244,14 +1216,16 @@ def expect_sender(username)
end
 
it 'uses service bot name by default' do
expect_sender(User.support_bot.name)
expect_sender(User.support_bot)
end
 
context 'when custom outgoing name is set' do
let_it_be(:settings) { create(:service_desk_setting, project: project, outgoing_name: 'some custom name') }
 
it 'uses custom name in "from" header' do
expect_sender('some custom name')
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq('some custom name')
expect(sender.address).to eq(gitlab_sender)
end
end
 
Loading
Loading
@@ -1259,7 +1233,7 @@ def expect_sender(username)
let_it_be(:settings) { create(:service_desk_setting, project: project, outgoing_name: '') }
 
it 'uses service bot name' do
expect_sender(User.support_bot.name)
expect_sender(User.support_bot)
end
end
end
Loading
Loading
@@ -1276,7 +1250,7 @@ def expect_sender(username)
end
 
it 'uses author\'s name in "from" header' do
expect_sender(first_note.author.name)
expect_sender(first_note.author)
end
 
it 'has the correct subject and body' do
Loading
Loading
@@ -1672,9 +1646,7 @@ def invite_to_group(group, inviter:, user: nil)
it_behaves_like 'appearance header and footer not enabled'
 
it 'is sent as the author' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(user.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(user)
end
 
it 'has the correct subject and body' do
Loading
Loading
@@ -1699,9 +1671,7 @@ def invite_to_group(group, inviter:, user: nil)
it_behaves_like 'appearance header and footer not enabled'
 
it 'is sent as the author' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(user.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(user)
end
 
it 'has the correct subject and body' do
Loading
Loading
@@ -1725,9 +1695,7 @@ def invite_to_group(group, inviter:, user: nil)
it_behaves_like 'appearance header and footer not enabled'
 
it 'is sent as the author' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(user.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(user)
end
 
it 'has the correct subject' do
Loading
Loading
@@ -1748,9 +1716,7 @@ def invite_to_group(group, inviter:, user: nil)
it_behaves_like 'appearance header and footer not enabled'
 
it 'is sent as the author' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(user.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(user)
end
 
it 'has the correct subject' do
Loading
Loading
@@ -1777,9 +1743,7 @@ def invite_to_group(group, inviter:, user: nil)
it_behaves_like 'appearance header and footer not enabled'
 
it 'is sent as the author' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(user.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(user)
end
 
it 'has the correct subject and body' do
Loading
Loading
@@ -1870,9 +1834,7 @@ def invite_to_group(group, inviter:, user: nil)
it_behaves_like 'appearance header and footer not enabled'
 
it 'is sent as the author' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(user.name)
expect(sender.address).to eq(gitlab_sender)
expect_sender(user)
end
 
it 'has the correct subject and body' do
Loading
Loading
@@ -1962,12 +1924,8 @@ def invite_to_group(group, inviter:, user: nil)
it_behaves_like 'an unsubscribeable thread'
 
it 'is sent to the given recipient as the author' do
sender = subject.header[:from].addrs[0]
aggregate_failures do
expect(sender.display_name).to eq(review.author_name)
expect(sender.address).to eq(gitlab_sender)
expect(subject).to deliver_to(recipient.notification_email)
expect_sender(review.author)
end
end
 
Loading
Loading
@@ -2002,4 +1960,10 @@ def invite_to_group(group, inviter:, user: nil)
end
end
end
def expect_sender(user)
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq("#{user.name} (@#{user.username})")
expect(sender.address).to eq(gitlab_sender)
end
end
Loading
Loading
@@ -1662,7 +1662,7 @@ def self.it_should_not_email!
notification.issue_due(issue)
email = find_email_for(@subscriber)
 
expect(email.header[:from].display_names).to eq([issue.author.name])
expect(email.header[:from].display_names).to eq(["#{issue.author.name} (@#{issue.author.username})"])
end
 
it_behaves_like 'participating notifications' do
Loading
Loading
Loading
Loading
@@ -225,7 +225,7 @@
sender = subject.header[:from].addrs[0]
 
aggregate_failures do
expect(sender.display_name).to eq(note_author.name)
expect(sender.display_name).to eq("#{note_author.name} (@#{note_author.username})")
expect(sender.address).to eq(gitlab_sender)
expect(subject).to deliver_to(recipient.notification_email)
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment