Commit 0daf3dc9 authored by Doug Stull's avatar Doug Stull Committed by Mikołaj Wawrzyniak

Add custom headers to invite emails

parent 1a5f2e17
...@@ -53,18 +53,10 @@ module Emails ...@@ -53,18 +53,10 @@ module Emails
return unless member_exists? return unless member_exists?
subject_line = mail(to: member.invite_email, subject: invite_email_subject, **invite_email_headers) do |format|
if member.created_by format.html { render layout: 'unknown_user_mailer' }
subject(s_("MemberInviteEmail|%{member_name} invited you to join GitLab") % { member_name: member.created_by.name }) format.text { render layout: 'unknown_user_mailer' }
else
subject(s_("MemberInviteEmail|Invitation to join the %{project_or_group} %{project_or_group_name}") % { project_or_group: member_source.human_name, project_or_group_name: member_source.model_name.singular })
end end
member_email_with_layout(
to: member.invite_email,
subject: subject_line,
layout: 'unknown_user_mailer'
)
end end
def member_invited_reminder_email(member_source_type, member_id, token, reminder_index) def member_invited_reminder_email(member_source_type, member_id, token, reminder_index)
...@@ -149,6 +141,25 @@ module Emails ...@@ -149,6 +141,25 @@ module Emails
private private
def invite_email_subject
if member.created_by
subject(s_("MemberInviteEmail|%{member_name} invited you to join GitLab") % { member_name: member.created_by.name })
else
subject(s_("MemberInviteEmail|Invitation to join the %{project_or_group} %{project_or_group_name}") % { project_or_group: member_source.human_name, project_or_group_name: member_source.model_name.singular })
end
end
def invite_email_headers
if Gitlab.dev_env_or_com?
{
'X-Mailgun-Tag' => 'invite_email',
'X-Mailgun-Variables' => { 'invite_token' => @token }.to_json
}
else
{}
end
end
def member_exists? def member_exists?
Gitlab::AppLogger.info("Tried to send an email invitation for a deleted group. Member id: #{@member_id}") if member.blank? Gitlab::AppLogger.info("Tried to send an email invitation for a deleted group. Member id: #{@member_id}") if member.blank?
member.present? member.present?
......
...@@ -146,7 +146,7 @@ class NotifyPreview < ActionMailer::Preview ...@@ -146,7 +146,7 @@ class NotifyPreview < ActionMailer::Preview
end end
def member_invited_email def member_invited_email
Notify.member_invited_email('project', user.id, '1234').message Notify.member_invited_email('project', member.id, '1234').message
end end
def pages_domain_enabled_email def pages_domain_enabled_email
......
...@@ -831,6 +831,19 @@ RSpec.describe Notify do ...@@ -831,6 +831,19 @@ RSpec.describe Notify do
is_expected.to have_body_text project_member.invite_token is_expected.to have_body_text project_member.invite_token
end end
end end
context 'when on gitlab.com' do
before do
allow(Gitlab).to receive(:dev_env_or_com?).and_return(true)
end
it 'has custom headers' do
aggregate_failures do
expect(subject).to have_header('X-Mailgun-Tag', 'invite_email')
expect(subject).to have_header('X-Mailgun-Variables', { 'invite_token' => project_member.invite_token }.to_json)
end
end
end
end end
describe 'project invitation accepted' do describe 'project invitation accepted' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment