Commit 2fa49b3d authored by Stan Hu's avatar Stan Hu

Merge branch '323631-send-rotation-email-inline-for-deleted-user' into 'master'

Send email inline to rotation members when deleting participant user

See merge request gitlab-org/gitlab!68811
parents 72f0f338 22a12c01
...@@ -76,9 +76,10 @@ module EE ...@@ -76,9 +76,10 @@ module EE
end end
end end
def oncall_user_removed(rotation, user) def oncall_user_removed(rotation, user, async_notification = true)
project_owners_and_participants(rotation, user).each do |recipient| project_owners_and_participants(rotation, user).each do |recipient|
mailer.user_removed_from_rotation_email(user, rotation, [recipient]).deliver_later email = mailer.user_removed_from_rotation_email(user, rotation, [recipient])
async_notification ? email.deliver_later : email.deliver_now
end end
end end
......
...@@ -35,7 +35,8 @@ module EE ...@@ -35,7 +35,8 @@ module EE
def oncall_rotations_cleanup(user) def oncall_rotations_cleanup(user)
::IncidentManagement::OncallRotations::RemoveParticipantsService.new( ::IncidentManagement::OncallRotations::RemoveParticipantsService.new(
user.oncall_rotations, user.oncall_rotations,
user user,
false
).execute ).execute
end end
......
...@@ -6,9 +6,11 @@ module IncidentManagement ...@@ -6,9 +6,11 @@ module IncidentManagement
include IncidentManagement::OncallRotations::SharedRotationLogic include IncidentManagement::OncallRotations::SharedRotationLogic
# @param oncall_rotations [IncidentManagement::OncallRotation] # @param oncall_rotations [IncidentManagement::OncallRotation]
# @param user_to_remove [User] # @param user_to_remove [User]
def initialize(oncall_rotation, user_to_remove) # @param async_email [Boolean]
def initialize(oncall_rotation, user_to_remove, async_email = true)
@oncall_rotation = oncall_rotation @oncall_rotation = oncall_rotation
@user_to_remove = user_to_remove @user_to_remove = user_to_remove
@async_email = async_email
end end
def execute def execute
...@@ -24,7 +26,7 @@ module IncidentManagement ...@@ -24,7 +26,7 @@ module IncidentManagement
private private
attr_reader :oncall_rotation, :user_to_remove attr_reader :oncall_rotation, :user_to_remove, :async_email
def remove_user_from_rotation def remove_user_from_rotation
participant = oncall_rotation.participants.for_user(user_to_remove).first participant = oncall_rotation.participants.for_user(user_to_remove).first
...@@ -37,7 +39,7 @@ module IncidentManagement ...@@ -37,7 +39,7 @@ module IncidentManagement
end end
def send_notification def send_notification
NotificationService.new.oncall_user_removed(oncall_rotation, user_to_remove) NotificationService.new.oncall_user_removed(oncall_rotation, user_to_remove, async_email)
end end
end end
end end
......
...@@ -5,16 +5,18 @@ module IncidentManagement ...@@ -5,16 +5,18 @@ module IncidentManagement
class RemoveParticipantsService class RemoveParticipantsService
# @param oncall_rotations [Array<IncidentManagement::OncallRotation>] # @param oncall_rotations [Array<IncidentManagement::OncallRotation>]
# @param user_to_remove [User] # @param user_to_remove [User]
def initialize(oncall_rotations, user_to_remove) # @param async_email [Boolean]
def initialize(oncall_rotations, user_to_remove, async_email = true)
@oncall_rotations = oncall_rotations @oncall_rotations = oncall_rotations
@user_to_remove = user_to_remove @user_to_remove = user_to_remove
@async_email = async_email
end end
attr_reader :oncall_rotations, :user_to_remove attr_reader :oncall_rotations, :user_to_remove, :async_email
def execute def execute
oncall_rotations.each do |oncall_rotation| oncall_rotations.each do |oncall_rotation|
RemoveParticipantService.new(oncall_rotation, user_to_remove).execute RemoveParticipantService.new(oncall_rotation, user_to_remove, async_email).execute
end end
end end
end end
......
...@@ -934,6 +934,10 @@ RSpec.describe EE::NotificationService, :mailer do ...@@ -934,6 +934,10 @@ RSpec.describe EE::NotificationService, :mailer do
subject.oncall_user_removed(rotation, user) subject.oncall_user_removed(rotation, user)
end end
it 'sends the email inline when async = false' do
expect { subject.oncall_user_removed(rotation, user, false) }.to change(ActionMailer::Base.deliveries, :size).by(2)
end
end end
end end
end end
...@@ -46,6 +46,7 @@ RSpec.describe Users::DestroyService do ...@@ -46,6 +46,7 @@ RSpec.describe Users::DestroyService do
let(:schedule) { create(:incident_management_oncall_schedule, project: project) } let(:schedule) { create(:incident_management_oncall_schedule, project: project) }
let(:rotation) { create(:incident_management_oncall_rotation, schedule: schedule) } let(:rotation) { create(:incident_management_oncall_rotation, schedule: schedule) }
let!(:participant) { create(:incident_management_oncall_participant, rotation: rotation, user: user) } let!(:participant) { create(:incident_management_oncall_participant, rotation: rotation, user: user) }
let!(:other_participant) { create(:incident_management_oncall_participant, rotation: rotation) }
context 'in their own project' do context 'in their own project' do
let(:project) { create(:project, namespace: user.namespace) } let(:project) { create(:project, namespace: user.namespace) }
...@@ -73,6 +74,10 @@ RSpec.describe Users::DestroyService do ...@@ -73,6 +74,10 @@ RSpec.describe Users::DestroyService do
expect(rotation.participants.reload).not_to include(participant) expect(rotation.participants.reload).not_to include(participant)
end end
it 'sends an email about the user being removed from the rotation' do
expect { operation }.to change(ActionMailer::Base.deliveries, :size).by(1)
end
end end
end end
......
...@@ -20,12 +20,12 @@ RSpec.describe IncidentManagement::OncallRotations::RemoveParticipantsService do ...@@ -20,12 +20,12 @@ RSpec.describe IncidentManagement::OncallRotations::RemoveParticipantsService do
expect(IncidentManagement::OncallRotations::RemoveParticipantService) expect(IncidentManagement::OncallRotations::RemoveParticipantService)
.to receive(:new) .to receive(:new)
.with(rotation, user) .with(rotation, user, true)
.and_return(remove_service) .and_return(remove_service)
expect(IncidentManagement::OncallRotations::RemoveParticipantService) expect(IncidentManagement::OncallRotations::RemoveParticipantService)
.to receive(:new) .to receive(:new)
.with(rotation_2, user) .with(rotation_2, user, true)
.and_return(remove_service) .and_return(remove_service)
expect(remove_service).to receive(:execute).twice expect(remove_service).to receive(:execute).twice
......
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