Commit 34bf8b9f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch '34416-subscribed-notification-header' into 'master'

Set X-GitLab-NotificationReason header if notification reason is explicit subscription

See merge request gitlab-org/gitlab!18812
parents 59ac8880 51d9eca0
......@@ -6,12 +6,14 @@ class NotificationReason
OWN_ACTIVITY = 'own_activity'
ASSIGNED = 'assigned'
MENTIONED = 'mentioned'
SUBSCRIBED = 'subscribed'
# Priority list for selecting which reason to return in the notification
REASON_PRIORITY = [
OWN_ACTIVITY,
ASSIGNED,
MENTIONED
MENTIONED,
SUBSCRIBED
].freeze
# returns the priority of a reason as an integer
......
......@@ -181,7 +181,7 @@ module NotificationRecipientService
def add_subscribed_users
return unless target.respond_to? :subscribers
add_recipients(target.subscribers(project), :subscription, nil)
add_recipients(target.subscribers(project), :subscription, NotificationReason::SUBSCRIBED)
end
# rubocop: disable CodeReuse/ActiveRecord
......@@ -240,7 +240,7 @@ module NotificationRecipientService
return unless target.respond_to? :labels
(labels || target.labels).each do |label|
add_recipients(label.subscribers(project), :subscription, nil)
add_recipients(label.subscribers(project), :subscription, NotificationReason::SUBSCRIBED)
end
end
end
......
---
title: Set X-GitLab-NotificationReason header if notification reason is explicit subscription
merge_request: 18812
author:
type: added
......@@ -869,6 +869,18 @@ describe NotificationService, :mailer do
should_email(user_4)
end
it 'adds "subscribed" reason to subscriber emails' do
user_1 = create(:user)
label = create(:label, project: project, issues: [issue])
issue.reload
label.subscribe(user_1)
notification.new_issue(issue, @u_disabled)
email = find_email_for(user_1)
expect(email).to have_header('X-GitLab-NotificationReason', NotificationReason::SUBSCRIBED)
end
it_behaves_like 'project emails are disabled' do
let(:notification_target) { issue }
let(:notification_trigger) { notification.new_issue(issue, @u_disabled) }
......@@ -1272,6 +1284,17 @@ describe NotificationService, :mailer do
let(:notification_target) { issue }
let(:notification_trigger) { notification.close_issue(issue, @u_disabled) }
end
it 'adds "subscribed" reason to subscriber emails' do
user_1 = create(:user)
issue.subscribe(user_1)
issue.reload
notification.close_issue(issue, @u_disabled)
email = find_email_for(user_1)
expect(email).to have_header('X-GitLab-NotificationReason', NotificationReason::SUBSCRIBED)
end
end
describe '#reopen_issue' 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