Commit 1e970f62 authored by Nick Thomas's avatar Nick Thomas

Merge branch '58433-email-notifications-do-not-work-properly-issue-due-date' into 'master'

Resolve "Email notifications do not work properly (issue due date)"

Closes #58433

See merge request gitlab-org/gitlab-ce!28835
parents 14fef151 ef5235cb
......@@ -101,6 +101,7 @@ class NotificationRecipient
end
def excluded_watcher_action?
return false unless @type == :watch
return false unless @custom_action
NotificationSetting::EXCLUDED_WATCHER_EVENTS.include?(@custom_action)
......@@ -140,7 +141,7 @@ class NotificationRecipient
return project_setting unless project_setting.nil? || project_setting.global?
group_setting = closest_non_global_group_notification_settting
group_setting = closest_non_global_group_notification_setting
return group_setting unless group_setting.nil?
......@@ -148,7 +149,7 @@ class NotificationRecipient
end
# Returns the notification_setting of the lowest group in hierarchy with non global level
def closest_non_global_group_notification_settting
def closest_non_global_group_notification_setting
return unless @group
@group
......
---
title: Fix email notifications for user excluded actions
merge_request: 28835
author:
type: fixed
......@@ -91,4 +91,237 @@ describe NotificationRecipient do
end
end
end
describe '#suitable_notification_level?' do
context 'when notification level is mention' do
before do
user.notification_settings_for(project).mention!
end
context 'when type is mention' do
let(:recipient) { described_class.new(user, :mention, target: target, project: project) }
it 'returns true' do
expect(recipient.suitable_notification_level?).to eq true
end
end
context 'when type is not mention' do
it 'returns false' do
expect(recipient.suitable_notification_level?).to eq false
end
end
end
context 'when notification level is participating' do
let(:notification_setting) { user.notification_settings_for(project) }
context 'when type is participating' do
let(:recipient) { described_class.new(user, :participating, target: target, project: project) }
it 'returns true' do
expect(recipient.suitable_notification_level?).to eq true
end
end
context 'when type is mention' do
let(:recipient) { described_class.new(user, :mention, target: target, project: project) }
it 'returns true' do
expect(recipient.suitable_notification_level?).to eq true
end
end
context 'with custom action' do
context "when action is failed_pipeline" do
let(:recipient) do
described_class.new(
user,
:watch,
custom_action: :failed_pipeline,
target: target,
project: project
)
end
before do
notification_setting.update!(failed_pipeline: true)
end
it 'returns true' do
expect(recipient.suitable_notification_level?).to eq true
end
end
context "when action is not failed_pipeline" do
let(:recipient) do
described_class.new(
user,
:watch,
custom_action: :success_pipeline,
target: target,
project: project
)
end
before do
notification_setting.update!(success_pipeline: true)
end
it 'returns false' do
expect(recipient.suitable_notification_level?).to eq false
end
end
end
end
context 'when notification level is custom' do
before do
user.notification_settings_for(project).custom!
end
context 'when type is participating' do
let(:notification_setting) { user.notification_settings_for(project) }
let(:recipient) do
described_class.new(
user,
:participating,
custom_action: :new_note,
target: target,
project: project
)
end
context 'with custom event enabled' do
before do
notification_setting.update!(new_note: true)
end
it 'returns true' do
expect(recipient.suitable_notification_level?).to eq true
end
end
context 'without custom event enabled' do
before do
notification_setting.update!(new_note: false)
end
it 'returns true' do
expect(recipient.suitable_notification_level?).to eq true
end
end
end
context 'when type is mention' do
let(:notification_setting) { user.notification_settings_for(project) }
let(:recipient) do
described_class.new(
user,
:mention,
custom_action: :new_issue,
target: target,
project: project
)
end
context 'with custom event enabled' do
before do
notification_setting.update!(new_issue: true)
end
it 'returns true' do
expect(recipient.suitable_notification_level?).to eq true
end
end
context 'without custom event enabled' do
before do
notification_setting.update!(new_issue: false)
end
it 'returns true' do
expect(recipient.suitable_notification_level?).to eq true
end
end
end
context 'when type is watch' do
let(:notification_setting) { user.notification_settings_for(project) }
let(:recipient) do
described_class.new(
user,
:watch,
custom_action: :failed_pipeline,
target: target,
project: project
)
end
context 'with custom event enabled' do
before do
notification_setting.update!(failed_pipeline: true)
end
it 'returns true' do
expect(recipient.suitable_notification_level?).to eq true
end
end
context 'without custom event enabled' do
before do
notification_setting.update!(failed_pipeline: false)
end
it 'returns false' do
expect(recipient.suitable_notification_level?).to eq false
end
end
end
end
context 'when notification level is watch' do
before do
user.notification_settings_for(project).watch!
end
context 'when type is watch' do
context 'without excluded watcher events' do
it 'returns true' do
expect(recipient.suitable_notification_level?).to eq true
end
end
context 'with excluded watcher events' do
let(:recipient) do
described_class.new(user, :watch, custom_action: :issue_due, target: target, project: project)
end
it 'returns false' do
expect(recipient.suitable_notification_level?).to eq false
end
end
end
context 'when type is not watch' do
context 'without excluded watcher events' do
let(:recipient) { described_class.new(user, :participating, target: target, project: project) }
it 'returns true' do
expect(recipient.suitable_notification_level?).to eq true
end
end
context 'with excluded watcher events' do
let(:recipient) do
described_class.new(user, :participating, custom_action: :issue_due, target: target, project: project)
end
it 'returns true' do
expect(recipient.suitable_notification_level?).to eq true
end
end
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