Commit 1523f686 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'add-notification-reason-to-note-emails' into 'master'

Add X-GitLab-NotificationReason header to note emails

See merge request gitlab-org/gitlab-ee!15845
parents fa3e483f 4a98d408
...@@ -2,44 +2,44 @@ ...@@ -2,44 +2,44 @@
module Emails module Emails
module Notes module Notes
def note_commit_email(recipient_id, note_id) def note_commit_email(recipient_id, note_id, reason = nil)
setup_note_mail(note_id, recipient_id) setup_note_mail(note_id, recipient_id)
@commit = @note.noteable @commit = @note.noteable
@target_url = project_commit_url(*note_target_url_options) @target_url = project_commit_url(*note_target_url_options)
mail_answer_note_thread(@commit, @note, note_thread_options(recipient_id)) mail_answer_note_thread(@commit, @note, note_thread_options(recipient_id, reason))
end end
def note_issue_email(recipient_id, note_id) def note_issue_email(recipient_id, note_id, reason = nil)
setup_note_mail(note_id, recipient_id) setup_note_mail(note_id, recipient_id)
@issue = @note.noteable @issue = @note.noteable
@target_url = project_issue_url(*note_target_url_options) @target_url = project_issue_url(*note_target_url_options)
mail_answer_note_thread(@issue, @note, note_thread_options(recipient_id)) mail_answer_note_thread(@issue, @note, note_thread_options(recipient_id, reason))
end end
def note_merge_request_email(recipient_id, note_id) def note_merge_request_email(recipient_id, note_id, reason = nil)
setup_note_mail(note_id, recipient_id) setup_note_mail(note_id, recipient_id)
@merge_request = @note.noteable @merge_request = @note.noteable
@target_url = project_merge_request_url(*note_target_url_options) @target_url = project_merge_request_url(*note_target_url_options)
mail_answer_note_thread(@merge_request, @note, note_thread_options(recipient_id)) mail_answer_note_thread(@merge_request, @note, note_thread_options(recipient_id, reason))
end end
def note_project_snippet_email(recipient_id, note_id) def note_project_snippet_email(recipient_id, note_id, reason = nil)
setup_note_mail(note_id, recipient_id) setup_note_mail(note_id, recipient_id)
@snippet = @note.noteable @snippet = @note.noteable
@target_url = project_snippet_url(*note_target_url_options) @target_url = project_snippet_url(*note_target_url_options)
mail_answer_note_thread(@snippet, @note, note_thread_options(recipient_id)) mail_answer_note_thread(@snippet, @note, note_thread_options(recipient_id, reason))
end end
def note_personal_snippet_email(recipient_id, note_id) def note_personal_snippet_email(recipient_id, note_id, reason = nil)
setup_note_mail(note_id, recipient_id) setup_note_mail(note_id, recipient_id)
@snippet = @note.noteable @snippet = @note.noteable
@target_url = snippet_url(@note.noteable) @target_url = snippet_url(@note.noteable)
mail_answer_note_thread(@snippet, @note, note_thread_options(recipient_id)) mail_answer_note_thread(@snippet, @note, note_thread_options(recipient_id, reason))
end end
private private
...@@ -48,11 +48,12 @@ module Emails ...@@ -48,11 +48,12 @@ module Emails
[@project || @group, @note.noteable, anchor: "note_#{@note.id}"] [@project || @group, @note.noteable, anchor: "note_#{@note.id}"]
end end
def note_thread_options(recipient_id) def note_thread_options(recipient_id, reason)
{ {
from: sender(@note.author_id), from: sender(@note.author_id),
to: recipient(recipient_id, @project&.group || @group), to: recipient(recipient_id, @project&.group || @group),
subject: subject("#{@note.noteable.title} (#{@note.noteable.reference_link_text})") subject: subject("#{@note.noteable.title} (#{@note.noteable.reference_link_text})"),
'X-GitLab-NotificationReason' => reason
} }
end end
......
...@@ -285,7 +285,7 @@ class NotificationService ...@@ -285,7 +285,7 @@ class NotificationService
recipients = NotificationRecipientService.build_new_note_recipients(note) recipients = NotificationRecipientService.build_new_note_recipients(note)
recipients.each do |recipient| recipients.each do |recipient|
mailer.send(notify_method, recipient.user.id, note.id).deliver_later mailer.send(notify_method, recipient.user.id, note.id, recipient.reason).deliver_later
end end
end end
......
---
title: Add X-GitLab-NotificationReason header to note emails
merge_request: 32422
author:
type: fixed
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
module EE module EE
module Emails module Emails
module Notes module Notes
def note_epic_email(recipient_id, note_id) def note_epic_email(recipient_id, note_id, reason = nil)
setup_note_mail(note_id, recipient_id) setup_note_mail(note_id, recipient_id)
@epic = @note.noteable @epic = @note.noteable
@target_url = group_epic_url(*note_target_url_options) @target_url = group_epic_url(*note_target_url_options)
mail_answer_note_thread(@epic, @note, note_thread_options(recipient_id)) mail_answer_note_thread(@epic, @note, note_thread_options(recipient_id, reason))
end end
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe EE::NotificationService, :mailer do describe EE::NotificationService, :mailer do
include EmailSpec::Matchers
include NotificationHelpers include NotificationHelpers
let(:subject) { NotificationService.new } let(:subject) { NotificationService.new }
...@@ -417,6 +418,9 @@ describe EE::NotificationService, :mailer do ...@@ -417,6 +418,9 @@ describe EE::NotificationService, :mailer do
should_not_email(@unsubscriber) should_not_email(@unsubscriber)
should_not_email(@u_outsider_mentioned) should_not_email(@u_outsider_mentioned)
should_not_email(@u_lazy_participant) should_not_email(@u_lazy_participant)
expect(find_email_for(@u_mentioned)).to have_header('X-GitLab-NotificationReason', 'mentioned')
expect(find_email_for(@u_custom_global)).to have_header('X-GitLab-NotificationReason', '')
end end
it_behaves_like 'group emails are disabled' do it_behaves_like 'group emails are disabled' do
......
...@@ -278,6 +278,7 @@ describe NotificationService, :mailer do ...@@ -278,6 +278,7 @@ describe NotificationService, :mailer do
notification.new_note(note) notification.new_note(note)
should_email(note.author) should_email(note.author)
expect(find_email_for(note.author)).to have_header('X-GitLab-NotificationReason', 'own_activity')
end end
it_behaves_like 'project emails are disabled' do it_behaves_like 'project emails are disabled' do
...@@ -335,6 +336,9 @@ describe NotificationService, :mailer do ...@@ -335,6 +336,9 @@ describe NotificationService, :mailer do
should_not_email(@u_participating) should_not_email(@u_participating)
should_not_email(@u_disabled) should_not_email(@u_disabled)
should_not_email(@u_lazy_participant) should_not_email(@u_lazy_participant)
expect(find_email_for(@u_mentioned)).to have_header('X-GitLab-NotificationReason', 'mentioned')
expect(find_email_for(@u_custom_global)).to have_header('X-GitLab-NotificationReason', '')
end end
end end
......
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