Commit d5773103 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'add-email-subject-suffix' into 'master'

Add configurable email subject suffix

## Why was this MR needed?

I noticed that there is a commit 44ab156e 3 years ago which removes email subject prefix

actually we do need an special part of the email subject which makes the email subject easy to identify

we just need to make it configurable rather than remove it.

See merge request !6172
parents 8d333c87 bb944085
...@@ -19,6 +19,7 @@ v 8.13.0 (unreleased) ...@@ -19,6 +19,7 @@ v 8.13.0 (unreleased)
- Add word-wrap to issue title on issue and milestone boards (ClemMakesApps) - Add word-wrap to issue title on issue and milestone boards (ClemMakesApps)
- Fix robots.txt disallowing access to groups starting with "s" (Matt Harrison) - Fix robots.txt disallowing access to groups starting with "s" (Matt Harrison)
- Close open merge request without source project (Katarzyna Kobierska Ula Budziszewska) - Close open merge request without source project (Katarzyna Kobierska Ula Budziszewska)
- Add configurable email subject suffix (Fu Xu)
- Use a ConnectionPool for Rails.cache on Sidekiq servers - Use a ConnectionPool for Rails.cache on Sidekiq servers
- Replace `alias_method_chain` with `Module#prepend` - Replace `alias_method_chain` with `Module#prepend`
- Enable GitLab Import/Export for non-admin users. - Enable GitLab Import/Export for non-admin users.
......
...@@ -3,4 +3,12 @@ class DeviseMailer < Devise::Mailer ...@@ -3,4 +3,12 @@ class DeviseMailer < Devise::Mailer
default reply_to: Gitlab.config.gitlab.email_reply_to default reply_to: Gitlab.config.gitlab.email_reply_to
layout 'devise_mailer' layout 'devise_mailer'
protected
def subject_for(key)
subject = super
subject << " | #{Gitlab.config.gitlab.email_subject_suffix}" if Gitlab.config.gitlab.email_subject_suffix.present?
subject
end
end end
...@@ -45,7 +45,7 @@ module Emails ...@@ -45,7 +45,7 @@ module Emails
@token = token @token = token
mail(to: member.invite_email, mail(to: member.invite_email,
subject: "Invitation to join the #{member_source.human_name} #{member_source.model_name.singular}") subject: subject("Invitation to join the #{member_source.human_name} #{member_source.model_name.singular}"))
end end
def member_invite_accepted_email(member_source_type, member_id) def member_invite_accepted_email(member_source_type, member_id)
......
...@@ -92,6 +92,7 @@ class Notify < BaseMailer ...@@ -92,6 +92,7 @@ class Notify < BaseMailer
subject = "" subject = ""
subject << "#{@project.name} | " if @project subject << "#{@project.name} | " if @project
subject << extra.join(' | ') if extra.present? subject << extra.join(' | ') if extra.present?
subject << " | #{Gitlab.config.gitlab.email_subject_suffix}" if Gitlab.config.gitlab.email_subject_suffix.present?
subject subject
end end
......
...@@ -70,6 +70,7 @@ production: &base ...@@ -70,6 +70,7 @@ production: &base
email_from: example@example.com email_from: example@example.com
email_display_name: GitLab email_display_name: GitLab
email_reply_to: noreply@example.com email_reply_to: noreply@example.com
email_subject_suffix: ''
# Email server smtp settings are in config/initializers/smtp_settings.rb.sample # Email server smtp settings are in config/initializers/smtp_settings.rb.sample
......
...@@ -186,6 +186,7 @@ Settings.gitlab['email_enabled'] ||= true if Settings.gitlab['email_enabled'].ni ...@@ -186,6 +186,7 @@ Settings.gitlab['email_enabled'] ||= true if Settings.gitlab['email_enabled'].ni
Settings.gitlab['email_from'] ||= ENV['GITLAB_EMAIL_FROM'] || "gitlab@#{Settings.gitlab.host}" Settings.gitlab['email_from'] ||= ENV['GITLAB_EMAIL_FROM'] || "gitlab@#{Settings.gitlab.host}"
Settings.gitlab['email_display_name'] ||= ENV['GITLAB_EMAIL_DISPLAY_NAME'] || 'GitLab' Settings.gitlab['email_display_name'] ||= ENV['GITLAB_EMAIL_DISPLAY_NAME'] || 'GitLab'
Settings.gitlab['email_reply_to'] ||= ENV['GITLAB_EMAIL_REPLY_TO'] || "noreply@#{Settings.gitlab.host}" Settings.gitlab['email_reply_to'] ||= ENV['GITLAB_EMAIL_REPLY_TO'] || "noreply@#{Settings.gitlab.host}"
Settings.gitlab['email_subject_suffix'] ||= ENV['GITLAB_EMAIL_SUBJECT_SUFFIX'] || ""
Settings.gitlab['base_url'] ||= Settings.send(:build_base_gitlab_url) Settings.gitlab['base_url'] ||= Settings.send(:build_base_gitlab_url)
Settings.gitlab['url'] ||= Settings.send(:build_gitlab_url) Settings.gitlab['url'] ||= Settings.send(:build_gitlab_url)
Settings.gitlab['user'] ||= 'git' Settings.gitlab['user'] ||= 'git'
......
...@@ -20,6 +20,8 @@ Variable | Type | Description ...@@ -20,6 +20,8 @@ Variable | Type | Description
`GITLAB_EMAIL_FROM` | string | The e-mail address used in the "From" field in e-mails sent by GitLab `GITLAB_EMAIL_FROM` | string | The e-mail address used in the "From" field in e-mails sent by GitLab
`GITLAB_EMAIL_DISPLAY_NAME` | string | The name used in the "From" field in e-mails sent by GitLab `GITLAB_EMAIL_DISPLAY_NAME` | string | The name used in the "From" field in e-mails sent by GitLab
`GITLAB_EMAIL_REPLY_TO` | string | The e-mail address used in the "Reply-To" field in e-mails sent by GitLab `GITLAB_EMAIL_REPLY_TO` | string | The e-mail address used in the "Reply-To" field in e-mails sent by GitLab
`GITLAB_EMAIL_REPLY_TO` | string | The e-mail address used in the "Reply-To" field in e-mails sent by GitLab
`GITLAB_EMAIL_SUBJECT_SUFFIX` | string | The e-mail subject suffix used in e-mails sent by GitLab
`GITLAB_UNICORN_MEMORY_MIN` | integer | The minimum memory threshold (in bytes) for the Unicorn worker killer `GITLAB_UNICORN_MEMORY_MIN` | integer | The minimum memory threshold (in bytes) for the Unicorn worker killer
`GITLAB_UNICORN_MEMORY_MAX` | integer | The maximum memory threshold (in bytes) for the Unicorn worker killer `GITLAB_UNICORN_MEMORY_MAX` | integer | The maximum memory threshold (in bytes) for the Unicorn worker killer
......
...@@ -831,6 +831,7 @@ describe Notify do ...@@ -831,6 +831,7 @@ describe Notify do
let(:user) { create(:user, email: 'old-email@mail.com') } let(:user) { create(:user, email: 'old-email@mail.com') }
before do before do
stub_config_setting(email_subject_suffix: 'A Nice Suffix')
perform_enqueued_jobs do perform_enqueued_jobs do
user.email = "new-email@mail.com" user.email = "new-email@mail.com"
user.save user.save
...@@ -847,7 +848,7 @@ describe Notify do ...@@ -847,7 +848,7 @@ describe Notify do
end end
it 'has the correct subject' do it 'has the correct subject' do
is_expected.to have_subject "Confirmation instructions" is_expected.to have_subject /^Confirmation instructions/
end end
it 'includes a link to the site' do it 'includes a link to the site' do
......
...@@ -37,6 +37,16 @@ shared_examples 'an email sent from GitLab' do ...@@ -37,6 +37,16 @@ shared_examples 'an email sent from GitLab' do
reply_to = subject.header[:reply_to].addresses reply_to = subject.header[:reply_to].addresses
expect(reply_to).to eq([gitlab_sender_reply_to]) expect(reply_to).to eq([gitlab_sender_reply_to])
end end
context 'when custom suffix for email subject is set' do
before do
stub_config_setting(email_subject_suffix: 'A Nice Suffix')
end
it 'ends the subject with the suffix' do
is_expected.to have_subject /\ \| A Nice Suffix$/
end
end
end end
shared_examples 'an email that contains a header with author username' do shared_examples 'an email that contains a header with author username' 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