Commit ca06ff27 authored by Sean McGivern's avatar Sean McGivern

Merge branch '37691-subscription-fires-multiple-notifications' into 'master'

fix multiple notifications from being sent for multiple labels

Closes #37691

See merge request gitlab-org/gitlab-ce!14798
parents f3832206 486da72f
...@@ -390,7 +390,7 @@ class NotificationService ...@@ -390,7 +390,7 @@ class NotificationService
end end
def relabeled_resource_email(target, labels, current_user, method) def relabeled_resource_email(target, labels, current_user, method)
recipients = labels.flat_map { |l| l.subscribers(target.project) } recipients = labels.flat_map { |l| l.subscribers(target.project) }.uniq
recipients = notifiable_users( recipients = notifiable_users(
recipients, :subscription, recipients, :subscription,
target: target, target: target,
......
---
title: Fixed duplicate notifications when added multiple labels on an issue
merge_request: 14798
author:
type: fixed
...@@ -731,6 +731,18 @@ describe NotificationService, :mailer do ...@@ -731,6 +731,18 @@ describe NotificationService, :mailer do
should_not_email(@u_participating) should_not_email(@u_participating)
end end
it "doesn't send multiple email when a user is subscribed to multiple given labels" do
subscriber_to_both = create(:user) do |user|
[label_1, label_2].each { |label| label.toggle_subscription(user, project) }
end
notification.relabeled_issue(issue, [label_1, label_2], @u_disabled)
should_email(subscriber_to_label_1)
should_email(subscriber_to_label_2)
should_email(subscriber_to_both)
end
context 'confidential issues' do context 'confidential issues' do
let(:author) { create(:user) } let(:author) { create(:user) }
let(:assignee) { create(:user) } let(:assignee) { create(:user) }
......
module EmailHelpers module EmailHelpers
def sent_to_user?(user, recipients = email_recipients) def sent_to_user(user, recipients: email_recipients)
recipients.include?(user.notification_email) recipients.count { |to| to == user.notification_email }
end end
def reset_delivered_emails! def reset_delivered_emails!
...@@ -10,17 +10,17 @@ module EmailHelpers ...@@ -10,17 +10,17 @@ module EmailHelpers
def should_only_email(*users, kind: :to) def should_only_email(*users, kind: :to)
recipients = email_recipients(kind: kind) recipients = email_recipients(kind: kind)
users.each { |user| should_email(user, recipients) } users.each { |user| should_email(user, recipients: recipients) }
expect(recipients.count).to eq(users.count) expect(recipients.count).to eq(users.count)
end end
def should_email(user, recipients = email_recipients) def should_email(user, times: 1, recipients: email_recipients)
expect(sent_to_user?(user, recipients)).to be_truthy expect(sent_to_user(user, recipients: recipients)).to eq(times)
end end
def should_not_email(user, recipients = email_recipients) def should_not_email(user, recipients: email_recipients)
expect(sent_to_user?(user, recipients)).to be_falsey should_email(user, times: 0, recipients: recipients)
end end
def should_not_email_anyone def should_not_email_anyone
......
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