Skip to content
代码片段 群组 项目
提交 a9b82b8d 编辑于 作者: Vasilii Iakliushin's avatar Vasilii Iakliushin
浏览文件

Add missing email suffix for Emails On Push and Admin emails

Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/213383

**Problem**

A custom email suffix is missing for `Emails on Push` and `Admin
notifications`.

**Solution**

Use `#subject` method to wrap subject text. It automatically applies
email suffix if it's missing.

Changelog: fixed
上级 170c36fc
No related branches found
No related tags found
无相关合并请求
...@@ -2,18 +2,18 @@ ...@@ -2,18 +2,18 @@
module Emails module Emails
module AdminNotification module AdminNotification
def send_admin_notification(user_id, subject, body) def send_admin_notification(user_id, subj, body)
user = User.find(user_id) user = User.find(user_id)
email = user.notification_email_or_default email = user.notification_email_or_default
@unsubscribe_url = unsubscribe_url(email: Base64.urlsafe_encode64(email)) @unsubscribe_url = unsubscribe_url(email: Base64.urlsafe_encode64(email))
@body = body @body = body
mail_with_locale to: email, subject: subject mail_with_locale to: email, subject: subject(subj)
end end
def send_unsubscribed_notification(user_id) def send_unsubscribed_notification(user_id)
user = User.find(user_id) user = User.find(user_id)
email = user.notification_email_or_default email = user.notification_email_or_default
mail_with_locale to: email, subject: "Unsubscribed from GitLab administrator notifications" mail_with_locale to: email, subject: subject("Unsubscribed from GitLab administrator notifications")
end end
end end
end end
......
...@@ -82,7 +82,7 @@ def repository_push_email(project_id, opts = {}) ...@@ -82,7 +82,7 @@ def repository_push_email(project_id, opts = {})
mail_with_locale( mail_with_locale(
from: sender(@message.author_id, send_from_user_email: @message.send_from_committer_email?), from: sender(@message.author_id, send_from_user_email: @message.send_from_committer_email?),
reply_to: @message.reply_to, reply_to: @message.reply_to,
subject: @message.subject subject: subject_with_suffix([@message.subject])
) )
end end
......
...@@ -11,4 +11,26 @@ ...@@ -11,4 +11,26 @@
expect(Notify).to be_respond_to(email_method) expect(Notify).to be_respond_to(email_method)
end end
end end
describe '#send_admin_notification' do
subject { Notify.send_admin_notification(recipient.id, 'Subject', 'Body') }
it 'sends an email' do
expect(subject).to have_subject 'Subject'
expect(subject).to have_body_text 'Body'
end
it_behaves_like 'an email with suffix'
end
describe '#send_unsubscribed_notification' do
subject { Notify.send_unsubscribed_notification(recipient.id) }
it 'sends an email' do
expect(subject).to have_subject 'Unsubscribed from GitLab administrator notifications'
expect(subject).to have_body_text 'You have been unsubscribed'
end
it_behaves_like 'an email with suffix'
end
end end
...@@ -180,6 +180,24 @@ ...@@ -180,6 +180,24 @@
end end
end end
describe '#repository_push_email' do
let(:recipient) { user }
subject { Notify.repository_push_email(project.id, { author_id: user.id, ref: 'main', action: :create }) }
it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like 'a user cannot unsubscribe through footer link'
it_behaves_like 'appearance header and footer enabled'
it_behaves_like 'appearance header and footer not enabled'
it_behaves_like 'an email with suffix'
it 'has the correct subject and body' do
is_expected.to have_subject("[Git][#{project.full_path}] Pushed new branch main")
is_expected.to have_body_text(project.full_path)
is_expected.to have_body_text("#{user.name} pushed new branch main at")
end
end
describe '.inactive_project_deletion_warning_email' do describe '.inactive_project_deletion_warning_email' do
let(:recipient) { user } let(:recipient) { user }
let(:deletion_date) { "2022-01-10" } let(:deletion_date) { "2022-01-10" }
......
...@@ -36,6 +36,16 @@ ...@@ -36,6 +36,16 @@
end end
end end
RSpec.shared_examples 'an email with suffix' do
before do
stub_config_setting(email_subject_suffix: 'Suffix')
end
it 'adds a correct suffix to subject' do
expect(subject.subject).to end_with('| Suffix')
end
end
RSpec.shared_examples 'an email that contains a header with author username' do RSpec.shared_examples 'an email that contains a header with author username' do
it 'has X-GitLab-Author header containing author\'s username' do it 'has X-GitLab-Author header containing author\'s username' do
is_expected.to have_header 'X-GitLab-Author', user.username is_expected.to have_header 'X-GitLab-Author', user.username
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册