From 74c8e091f40c29a59b99bf7864b9fee303c68e50 Mon Sep 17 00:00:00 2001 From: Fu Xu Date: Fri, 2 Sep 2016 16:57:08 +0800 Subject: add configurable email subject suffix --- CHANGELOG | 4 ++++ app/mailers/notify.rb | 1 + config/gitlab.yml.example | 1 + config/initializers/1_settings.rb | 1 + doc/administration/environment_variables.md | 20 +++++++++++--------- spec/mailers/shared/notify.rb | 4 ++++ 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a52ac53bae7..9c84ef90d71 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -271,6 +271,10 @@ v 8.11.6 v 8.11.5 - Optimize branch lookups and force a repository reload for Repository#find_branch. !6087 - Fix member expiration date picker after update. !6184 + - Add configurable email subject suffix + +v 8.11.5 (unreleased) + - Optimize branch lookups and force a repository reload for Repository#find_branch - Fix suggested colors options for new labels in the admin area. !6138 - Optimize discussion notes resolving and unresolving - Fix GitLab import button diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb index 29f1c527776..1321b42ddf4 100644 --- a/app/mailers/notify.rb +++ b/app/mailers/notify.rb @@ -92,6 +92,7 @@ class Notify < BaseMailer subject = "" subject << "#{@project.name} | " if @project subject << extra.join(' | ') if extra.present? + subject << " | #{Gitlab.config.gitlab.email_subject_suffix}" if Gitlab.config.gitlab.email_subject_suffix.length > 0 subject end diff --git a/config/gitlab.yml.example b/config/gitlab.yml.example index 1470a6e2550..a79356923b2 100644 --- a/config/gitlab.yml.example +++ b/config/gitlab.yml.example @@ -70,6 +70,7 @@ production: &base email_from: example@example.com email_display_name: GitLab email_reply_to: noreply@example.com + email_subject_suffix: '' # Email server smtp settings are in config/initializers/smtp_settings.rb.sample diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb index 195108b921b..c5ed2162c92 100644 --- a/config/initializers/1_settings.rb +++ b/config/initializers/1_settings.rb @@ -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_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_subject_suffix'] ||= ENV['GITLAB_EMAIL_SUBJECT_SUFFIX'] || "" Settings.gitlab['base_url'] ||= Settings.send(:build_base_gitlab_url) Settings.gitlab['url'] ||= Settings.send(:build_gitlab_url) Settings.gitlab['user'] ||= 'git' diff --git a/doc/administration/environment_variables.md b/doc/administration/environment_variables.md index 7f53915a4d7..b4a953d1ccc 100644 --- a/doc/administration/environment_variables.md +++ b/doc/administration/environment_variables.md @@ -13,15 +13,17 @@ override certain values. Variable | Type | Description -------- | ---- | ----------- -`GITLAB_ROOT_PASSWORD` | string | Sets the password for the `root` user on installation -`GITLAB_HOST` | string | The full URL of the GitLab server (including `http://` or `https://`) -`RAILS_ENV` | string | The Rails environment; can be one of `production`, `development`, `staging` or `test` -`DATABASE_URL` | string | The database URL; is of the form: `postgresql://localhost/blog_development` -`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_REPLY_TO` | string | The e-mail address used in the "Reply-To" field 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_MAX` | integer | The maximum memory threshold (in bytes) for the Unicorn worker killer +`GITLAB_ROOT_PASSWORD` | string | Sets the password for the `root` user on installation +`GITLAB_HOST` | string | The full URL of the GitLab server (including `http://` or `https://`) +`RAILS_ENV` | string | The Rails environment; can be one of `production`, `development`, `staging` or `test` +`DATABASE_URL` | string | The database URL; is of the form: `postgresql://localhost/blog_development` +`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_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_MAX` | integer | The maximum memory threshold (in bytes) for the Unicorn worker killer ## Complete database variables diff --git a/spec/mailers/shared/notify.rb b/spec/mailers/shared/notify.rb index 5c9851f14c7..de1d8995534 100644 --- a/spec/mailers/shared/notify.rb +++ b/spec/mailers/shared/notify.rb @@ -2,6 +2,7 @@ shared_context 'gitlab email notification' do let(:gitlab_sender_display_name) { Gitlab.config.gitlab.email_display_name } let(:gitlab_sender) { Gitlab.config.gitlab.email_from } let(:gitlab_sender_reply_to) { Gitlab.config.gitlab.email_reply_to } + let(:gitlab_subject_suffix) { Gitlab.config.gitlab.email_subject_suffix } let(:recipient) { create(:user, email: 'recipient@example.com') } let(:project) { create(:project) } let(:new_user_address) { 'newguy@example.com' } @@ -31,6 +32,9 @@ shared_examples 'an email sent from GitLab' do sender = subject.header[:from].addrs[0] expect(sender.display_name).to eq(gitlab_sender_display_name) expect(sender.address).to eq(gitlab_sender) + if gitlab_subject_suffix.length > 0 + is_expected.to have_subject gitlab_subject_suffix + end end it 'has a Reply-To address' do -- cgit v1.2.1 From f3f7f3fe8410cd8213cbc9b736d005ac85cbe980 Mon Sep 17 00:00:00 2001 From: Fu Xu Date: Tue, 27 Sep 2016 01:02:57 +0800 Subject: move changelog to 8.13 --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 9c84ef90d71..c6eb18be6e5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -42,6 +42,7 @@ v 8.12.4 (unreleased) v 8.12.3 - Update Gitlab Shell to support low IO priority for storage moves + - Add configurable email subject suffix v 8.12.2 (unreleased) - Fix Import/Export not recognising correctly the imported services. @@ -271,7 +272,6 @@ v 8.11.6 v 8.11.5 - Optimize branch lookups and force a repository reload for Repository#find_branch. !6087 - Fix member expiration date picker after update. !6184 - - Add configurable email subject suffix v 8.11.5 (unreleased) - Optimize branch lookups and force a repository reload for Repository#find_branch -- cgit v1.2.1 From 785094e201a7d3e7c88f9556da8d9539281a36d5 Mon Sep 17 00:00:00 2001 From: Fu Xu Date: Tue, 27 Sep 2016 01:06:57 +0800 Subject: create new test in `spec/mailers/notify_spec.rb` --- spec/mailers/notify_spec.rb | 11 +++++++++++ spec/mailers/shared/notify.rb | 4 ---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index cd8578b6f49..03e0bfd3614 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -1094,4 +1094,15 @@ describe Notify do is_expected.to have_body_text /#{diff_path}/ end end + + describe 'email has correct subject' do + let(:gitlab_subject_suffix) { Gitlab.config.gitlab.email_subject_suffix } + + it 'has correct suffix' do + if gitlab_subject_suffix.length > 0 + is_expected.to have_subject gitlab_subject_suffix + end + end + end + end diff --git a/spec/mailers/shared/notify.rb b/spec/mailers/shared/notify.rb index de1d8995534..5c9851f14c7 100644 --- a/spec/mailers/shared/notify.rb +++ b/spec/mailers/shared/notify.rb @@ -2,7 +2,6 @@ shared_context 'gitlab email notification' do let(:gitlab_sender_display_name) { Gitlab.config.gitlab.email_display_name } let(:gitlab_sender) { Gitlab.config.gitlab.email_from } let(:gitlab_sender_reply_to) { Gitlab.config.gitlab.email_reply_to } - let(:gitlab_subject_suffix) { Gitlab.config.gitlab.email_subject_suffix } let(:recipient) { create(:user, email: 'recipient@example.com') } let(:project) { create(:project) } let(:new_user_address) { 'newguy@example.com' } @@ -32,9 +31,6 @@ shared_examples 'an email sent from GitLab' do sender = subject.header[:from].addrs[0] expect(sender.display_name).to eq(gitlab_sender_display_name) expect(sender.address).to eq(gitlab_sender) - if gitlab_subject_suffix.length > 0 - is_expected.to have_subject gitlab_subject_suffix - end end it 'has a Reply-To address' do -- cgit v1.2.1 From 612a5d531722a0b846602ba99a7b2e77dc5cb1d7 Mon Sep 17 00:00:00 2001 From: Fu Xu Date: Tue, 27 Sep 2016 14:11:17 +0800 Subject: remove extra entry --- CHANGELOG | 3 --- 1 file changed, 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c6eb18be6e5..747897b18e9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -272,9 +272,6 @@ v 8.11.6 v 8.11.5 - Optimize branch lookups and force a repository reload for Repository#find_branch. !6087 - Fix member expiration date picker after update. !6184 - -v 8.11.5 (unreleased) - - Optimize branch lookups and force a repository reload for Repository#find_branch - Fix suggested colors options for new labels in the admin area. !6138 - Optimize discussion notes resolving and unresolving - Fix GitLab import button -- cgit v1.2.1 From 89dc70df4614daf95a2284d8171db2a9115ec46e Mon Sep 17 00:00:00 2001 From: Fu Xu Date: Tue, 27 Sep 2016 19:03:24 +0800 Subject: remove empty line at block body end --- spec/mailers/notify_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index 03e0bfd3614..3585432ec75 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -1104,5 +1104,4 @@ describe Notify do end end end - end -- cgit v1.2.1 From 2a438f452c920e57545add519ed7b7a2c15e660e Mon Sep 17 00:00:00 2001 From: Fu Xu Date: Tue, 27 Sep 2016 20:18:10 +0800 Subject: stub config settings in spec --- spec/mailers/notify_spec.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index 3585432ec75..8dc5e0b34d2 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -1096,12 +1096,9 @@ describe Notify do end describe 'email has correct subject' do - let(:gitlab_subject_suffix) { Gitlab.config.gitlab.email_subject_suffix } - it 'has correct suffix' do - if gitlab_subject_suffix.length > 0 - is_expected.to have_subject gitlab_subject_suffix - end + stub_config_setting(email_subject_suffix: 'A Nice Suffix') + is_expected.to have_subject /\| A Nice Suffix$/ end end end -- cgit v1.2.1 From 048f124a0851a51c449881814dbfd2f2fc2dd32d Mon Sep 17 00:00:00 2001 From: Fu Xu Date: Wed, 28 Sep 2016 16:14:47 +0800 Subject: move spec back into shared example `an email sent from GitLab` --- spec/mailers/notify_spec.rb | 7 ------- spec/mailers/shared/notify.rb | 10 ++++++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index 8dc5e0b34d2..cd8578b6f49 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -1094,11 +1094,4 @@ describe Notify do is_expected.to have_body_text /#{diff_path}/ end end - - describe 'email has correct subject' do - it 'has correct suffix' do - stub_config_setting(email_subject_suffix: 'A Nice Suffix') - is_expected.to have_subject /\| A Nice Suffix$/ - end - end end diff --git a/spec/mailers/shared/notify.rb b/spec/mailers/shared/notify.rb index 5c9851f14c7..33d1075c739 100644 --- a/spec/mailers/shared/notify.rb +++ b/spec/mailers/shared/notify.rb @@ -37,6 +37,16 @@ shared_examples 'an email sent from GitLab' do reply_to = subject.header[:reply_to].addresses expect(reply_to).to eq([gitlab_sender_reply_to]) 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 shared_examples 'an email that contains a header with author username' do -- cgit v1.2.1 From 64a60bc4545cbf85b3a025edd63bdaefd8cd9499 Mon Sep 17 00:00:00 2001 From: Fu Xu Date: Thu, 29 Sep 2016 16:09:47 +0800 Subject: wrap subject with method subject --- app/mailers/emails/members.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mailers/emails/members.rb b/app/mailers/emails/members.rb index 45311690293..7b617b359ea 100644 --- a/app/mailers/emails/members.rb +++ b/app/mailers/emails/members.rb @@ -45,7 +45,7 @@ module Emails @token = token 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 def member_invite_accepted_email(member_source_type, member_id) -- cgit v1.2.1 From 064eb2caa671cdd18cd051e49ff2086d004e5516 Mon Sep 17 00:00:00 2001 From: Fu Xu Date: Thu, 29 Sep 2016 16:11:40 +0800 Subject: follow the styleguide: Don't use parentheses around a literal --- spec/mailers/shared/notify.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/mailers/shared/notify.rb b/spec/mailers/shared/notify.rb index 33d1075c739..3956d05060b 100644 --- a/spec/mailers/shared/notify.rb +++ b/spec/mailers/shared/notify.rb @@ -44,7 +44,7 @@ shared_examples 'an email sent from GitLab' do end it 'ends the subject with the suffix' do - is_expected.to have_subject (/ \| A Nice Suffix$/) + is_expected.to have_subject /\ \| A Nice Suffix$/ end end end -- cgit v1.2.1 From 76463c2cb460099559b8544396cf1a6656895e8d Mon Sep 17 00:00:00 2001 From: Fu Xu Date: Fri, 30 Sep 2016 17:46:37 +0800 Subject: override subject method in devise mailer --- app/mailers/devise_mailer.rb | 8 ++++++++ spec/mailers/notify_spec.rb | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/mailers/devise_mailer.rb b/app/mailers/devise_mailer.rb index 415f6e12885..bd4c1c9226a 100644 --- a/app/mailers/devise_mailer.rb +++ b/app/mailers/devise_mailer.rb @@ -3,4 +3,12 @@ class DeviseMailer < Devise::Mailer default reply_to: Gitlab.config.gitlab.email_reply_to layout 'devise_mailer' + + protected + + def subject_for(key) + subject = super + subject << " | #{Gitlab.config.gitlab.email_subject_suffix}" if Gitlab.config.gitlab.email_subject_suffix.length > 0 + subject + end end diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index cd8578b6f49..0e4130e8a3a 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -831,6 +831,7 @@ describe Notify do let(:user) { create(:user, email: 'old-email@mail.com') } before do + stub_config_setting(email_subject_suffix: 'A Nice Suffix') perform_enqueued_jobs do user.email = "new-email@mail.com" user.save @@ -847,7 +848,7 @@ describe Notify do end it 'has the correct subject' do - is_expected.to have_subject "Confirmation instructions" + is_expected.to have_subject /^Confirmation instructions/ end it 'includes a link to the site' do -- cgit v1.2.1 From 867b9b43472508f0f8cead53b0e9fff89edd9064 Mon Sep 17 00:00:00 2001 From: Fu Xu Date: Fri, 30 Sep 2016 21:06:11 +0800 Subject: change determine conditions --- app/mailers/devise_mailer.rb | 2 +- app/mailers/notify.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/mailers/devise_mailer.rb b/app/mailers/devise_mailer.rb index bd4c1c9226a..f7ed61625f4 100644 --- a/app/mailers/devise_mailer.rb +++ b/app/mailers/devise_mailer.rb @@ -8,7 +8,7 @@ class DeviseMailer < Devise::Mailer def subject_for(key) subject = super - subject << " | #{Gitlab.config.gitlab.email_subject_suffix}" if Gitlab.config.gitlab.email_subject_suffix.length > 0 + subject << " | #{Gitlab.config.gitlab.email_subject_suffix}" if Gitlab.config.gitlab.email_subject_suffix.present? subject end end diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb index 1321b42ddf4..2444702104e 100644 --- a/app/mailers/notify.rb +++ b/app/mailers/notify.rb @@ -92,7 +92,7 @@ class Notify < BaseMailer subject = "" subject << "#{@project.name} | " if @project subject << extra.join(' | ') if extra.present? - subject << " | #{Gitlab.config.gitlab.email_subject_suffix}" if Gitlab.config.gitlab.email_subject_suffix.length > 0 + subject << " | #{Gitlab.config.gitlab.email_subject_suffix}" if Gitlab.config.gitlab.email_subject_suffix.present? subject end -- cgit v1.2.1 From 1fde68046e55b13c31217cdad551db7c26733500 Mon Sep 17 00:00:00 2001 From: Fu Xu Date: Fri, 30 Sep 2016 21:11:22 +0800 Subject: credit myself :smile: --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 747897b18e9..e8224cd24fc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -18,6 +18,7 @@ v 8.13.0 (unreleased) - Add word-wrap to issue title on issue and milestone boards (ClemMakesApps) - Fix robots.txt disallowing access to groups starting with "s" (Matt Harrison) - 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 - Replace `alias_method_chain` with `Module#prepend` - Preserve label filters when sorting !6136 (Joseph Frazier) -- cgit v1.2.1 From bb94408537dd8bd0fdb7bc1577c55bde1ee2fc41 Mon Sep 17 00:00:00 2001 From: Fu Xu Date: Mon, 3 Oct 2016 18:08:28 +0800 Subject: resolve duplicated changelog entry --- CHANGELOG | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index e8224cd24fc..164af436af5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -43,7 +43,6 @@ v 8.12.4 (unreleased) v 8.12.3 - Update Gitlab Shell to support low IO priority for storage moves - - Add configurable email subject suffix v 8.12.2 (unreleased) - Fix Import/Export not recognising correctly the imported services. -- cgit v1.2.1