diff options
author | Mayra Cabrera <mcabrera@gitlab.com> | 2019-09-02 18:41:57 +0000 |
---|---|---|
committer | Mayra Cabrera <mcabrera@gitlab.com> | 2019-09-02 18:41:57 +0000 |
commit | 138d886d0d9d7c55bbc1bab4233810aa8f5593c0 (patch) | |
tree | 83e80a23c2bd3c82eb54a53b6ff8840c47b1edef | |
parent | 183d9ed70873860c9cc0722ea9a2d0723d4e034e (diff) | |
parent | 075f6d3559f0a0127fb322b40fad7985df621fcd (diff) | |
download | gitlab-ce-138d886d0d9d7c55bbc1bab4233810aa8f5593c0.tar.gz |
Merge branch 'add-notification-reason-to-note-emails' into 'master'
Add X-GitLab-NotificationReason header to note emails
See merge request gitlab-org/gitlab-ce!32422
-rw-r--r-- | app/mailers/emails/notes.rb | 25 | ||||
-rw-r--r-- | app/services/notification_service.rb | 2 | ||||
-rw-r--r-- | changelogs/unreleased/add-notification-reason-to-note-emails.yml | 5 | ||||
-rw-r--r-- | spec/services/notification_service_spec.rb | 4 |
4 files changed, 23 insertions, 13 deletions
diff --git a/app/mailers/emails/notes.rb b/app/mailers/emails/notes.rb index 04db1980b99..8b93ead0ee6 100644 --- a/app/mailers/emails/notes.rb +++ b/app/mailers/emails/notes.rb @@ -2,44 +2,44 @@ module Emails 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) @commit = @note.noteable @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 - 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) @issue = @note.noteable @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 - 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) @merge_request = @note.noteable @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 - 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) @snippet = @note.noteable @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 - 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) @snippet = @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 private @@ -48,11 +48,12 @@ module Emails [@project || @group, @note.noteable, anchor: "note_#{@note.id}"] end - def note_thread_options(recipient_id) + def note_thread_options(recipient_id, reason) { from: sender(@note.author_id), 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 diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index 5b8c1288854..a4243b7bc5e 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -285,7 +285,7 @@ class NotificationService recipients = NotificationRecipientService.build_new_note_recipients(note) 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 diff --git a/changelogs/unreleased/add-notification-reason-to-note-emails.yml b/changelogs/unreleased/add-notification-reason-to-note-emails.yml new file mode 100644 index 00000000000..c27247b22cb --- /dev/null +++ b/changelogs/unreleased/add-notification-reason-to-note-emails.yml @@ -0,0 +1,5 @@ +--- +title: Add X-GitLab-NotificationReason header to note emails +merge_request: 32422 +author: +type: fixed diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index ab0e01e27d7..bd6734634cb 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -278,6 +278,7 @@ describe NotificationService, :mailer do notification.new_note(note) should_email(note.author) + expect(find_email_for(note.author)).to have_header('X-GitLab-NotificationReason', 'own_activity') end it_behaves_like 'project emails are disabled' do @@ -335,6 +336,9 @@ describe NotificationService, :mailer do should_not_email(@u_participating) should_not_email(@u_disabled) 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 |