summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Eipert <leipert@gitlab.com>2018-10-10 14:30:40 +0200
committerLukas Eipert <leipert@gitlab.com>2018-10-16 14:54:18 +0200
commit2063dcf511acf41800f3370372b73a03b066e9f4 (patch)
treed95e1a0c862276fd9ca52d22739cc34864c890e1
parente11ff3b6bc3700b93f4893903ff29c8914c70464 (diff)
downloadgitlab-ce-2063dcf511acf41800f3370372b73a03b066e9f4.tar.gz
Add IID headers to E-Mail notifications
These headers can be used to build URLs for API requests. Good examples would be Issues and Merge Requests
-rw-r--r--app/mailers/notify.rb1
-rw-r--r--changelogs/unreleased/52477-add-iid-headers-to-emails.yml5
-rw-r--r--spec/support/shared_examples/notify_shared_examples.rb17
3 files changed, 23 insertions, 0 deletions
diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb
index f7347ee61b4..662f3e00047 100644
--- a/app/mailers/notify.rb
+++ b/app/mailers/notify.rb
@@ -118,6 +118,7 @@ class Notify < BaseMailer
add_unsubscription_headers_and_links
headers["X-GitLab-#{model.class.name}-ID"] = model.id
+ headers["X-GitLab-#{model.class.name}-IID"] = model.iid if model.respond_to?(:iid)
headers['X-GitLab-Reply-Key'] = reply_key
@reason = headers['X-GitLab-NotificationReason']
diff --git a/changelogs/unreleased/52477-add-iid-headers-to-emails.yml b/changelogs/unreleased/52477-add-iid-headers-to-emails.yml
new file mode 100644
index 00000000000..c17b66c5f54
--- /dev/null
+++ b/changelogs/unreleased/52477-add-iid-headers-to-emails.yml
@@ -0,0 +1,5 @@
+---
+title: Add IID headers to E-Mail notifications
+merge_request: 22263
+author:
+type: changed
diff --git a/spec/support/shared_examples/notify_shared_examples.rb b/spec/support/shared_examples/notify_shared_examples.rb
index 5fb9ced3b63..66536e80db2 100644
--- a/spec/support/shared_examples/notify_shared_examples.rb
+++ b/spec/support/shared_examples/notify_shared_examples.rb
@@ -45,6 +45,20 @@ shared_examples 'an email that contains a header with author username' do
end
end
+shared_examples 'an email with X-GitLab headers containing IDs' do
+ it 'has X-GitLab-*-ID header' do
+ is_expected.to have_header "X-GitLab-#{model.class.name}-ID", "#{model.id}"
+ end
+
+ it 'has X-GitLab-*-IID header if model has iid defined' do
+ if model.respond_to?(:iid)
+ is_expected.to have_header "X-GitLab-#{model.class.name}-IID", "#{model.iid}"
+ else
+ expect(subject.header["X-GitLab-#{model.class.name}-IID"]).to eq nil
+ end
+ end
+end
+
shared_examples 'an email with X-GitLab headers containing project details' do
it 'has X-GitLab-Project headers' do
aggregate_failures do
@@ -69,6 +83,7 @@ end
shared_examples 'a thread answer email with reply-by-email enabled' do
include_examples 'an email with X-GitLab headers containing project details'
+ include_examples 'an email with X-GitLab headers containing IDs'
it 'has the characteristics of a threaded reply' do
host = Gitlab.config.gitlab.host
@@ -85,6 +100,7 @@ end
shared_examples 'an email starting a new thread with reply-by-email enabled' do
include_examples 'an email with X-GitLab headers containing project details'
+ include_examples 'an email with X-GitLab headers containing IDs'
include_examples 'a new thread email with reply-by-email enabled'
it 'includes "Reply to this email directly or <View it on GitLab>"' do
@@ -109,6 +125,7 @@ end
shared_examples 'an answer to an existing thread with reply-by-email enabled' do
include_examples 'an email with X-GitLab headers containing project details'
+ include_examples 'an email with X-GitLab headers containing IDs'
include_examples 'a thread answer email with reply-by-email enabled'
context 'when reply-by-email is enabled with incoming address with %{key}' do