Commit 03090652 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '323631-remove-participant-send-email-on-removal' into 'master'

Send email when user is removed from rotation

See merge request gitlab-org/gitlab!59331
parents f9e91f21 dae28c7c
---
title: Send email to oncall rotation participants and project owners when user is
removed
merge_request: 59331
author:
type: added
......@@ -13,6 +13,7 @@ module EE
include ::Emails::Epics
include ::Emails::Requirements
include ::Emails::UserCap
include ::Emails::OncallRotation
end
attr_reader :group
......
# frozen_string_literal: true
module Emails
module OncallRotation
extend ActiveSupport::Concern
def user_removed_from_rotation_email(user, rotation, recipients)
@user = user
@rotation = rotation
@schedule = rotation.schedule
@project = rotation.project
mail(to: recipients.map(&:email), subject: subject('User removed from On-call rotation')) do |format|
format.html { render layout: 'mailer' }
format.text { render layout: 'mailer' }
end
end
end
end
......@@ -76,8 +76,23 @@ module EE
end
end
def oncall_user_removed(rotation, user)
project_owners_and_participants(rotation, user).each do |recipient|
mailer.user_removed_from_rotation_email(user, rotation, [recipient]).deliver_later
end
end
private
def project_owners_and_participants(rotation, user)
project = rotation.project
owners = project.owner.is_a?(Group) ? project.owner.owners : [project.owner]
member_owners = project.members.owners
(owners + member_owners + rotation.participants.map(&:user) - [user]).compact.uniq
end
def add_mr_approvers_email(merge_request, approvers, current_user)
approvers.each do |approver|
mailer.add_merge_request_approver_email(approver.id, merge_request.id, current_user.id).deliver_later
......
......@@ -18,6 +18,7 @@ module IncidentManagement
if deleted
save_current_shift!
send_notification
end
end
......@@ -34,6 +35,10 @@ module IncidentManagement
oncall_rotation.touch
end
def send_notification
NotificationService.new.oncall_user_removed(oncall_rotation, user_to_remove)
end
end
end
end
%p
= _("%{user_name} (%{user_username}) was removed from %{rotation} in %{schedule} in %{project}. ") % { user_name: @user.name, user_username: @user.username, rotation: @rotation.name, schedule: @rotation.schedule.name, project: @project.name }
%p
= html_escape(_("%{rotation} has been recalculated with the remaining participants. Please review the new setup for %{rotation_link}. It is recommended that you reach out to the current on-call responder to ensure continuity of on-call coverage.")) % { rotation: @rotation.name, rotation_link: link_to(@rotation.name, project_incident_management_oncall_schedules_url(@project).html_safe) }
= _("%{user_name} (%{user_username}) was removed from %{rotation} in %{schedule} in %{project}. ") % { user_name: @user.name, user_username: @user.username, rotation: @rotation.name, schedule: @rotation.schedule.name, project: @project.name }
= _("%{rotation} has been recalculated with the remaining participants. Please review the new setup for %{rotation}. It is recommended that you reach out to the current on-call responder to ensure continuity of on-call coverage.") % { rotation: @rotation.name }
......@@ -896,8 +896,9 @@ RSpec.describe EE::NotificationService, :mailer do
end
context 'IncidentManagement::Oncall' do
let_it_be(:user) { create(:user) }
describe '#notify_oncall_users_of_alert' do
let_it_be(:user) { create(:user) }
let_it_be(:alert) { create(:alert_management_alert) }
let_it_be(:project) { alert.project }
......@@ -921,5 +922,18 @@ RSpec.describe EE::NotificationService, :mailer do
.by 1
end
end
describe '#oncall_user_removed' do
let_it_be(:schedule) { create(:incident_management_oncall_schedule) }
let_it_be(:rotation) { create(:incident_management_oncall_rotation, schedule: schedule) }
let_it_be(:participant) { create(:incident_management_oncall_participant, rotation: rotation) }
it 'sends an email to the owner and participants' do
expect(Notify).to receive(:user_removed_from_rotation_email).with(user, rotation, [schedule.project.owner]).once.and_call_original
expect(Notify).to receive(:user_removed_from_rotation_email).with(user, rotation, [participant.user]).once.and_call_original
subject.oncall_user_removed(rotation, user)
end
end
end
end
......@@ -800,6 +800,12 @@ msgstr ""
msgid "%{retryButtonStart}Try again%{retryButtonEnd} or %{newFileButtonStart}attach a new file%{newFileButtonEnd}."
msgstr ""
msgid "%{rotation} has been recalculated with the remaining participants. Please review the new setup for %{rotation_link}. It is recommended that you reach out to the current on-call responder to ensure continuity of on-call coverage."
msgstr ""
msgid "%{rotation} has been recalculated with the remaining participants. Please review the new setup for %{rotation}. It is recommended that you reach out to the current on-call responder to ensure continuity of on-call coverage."
msgstr ""
msgid "%{seconds}s"
msgstr ""
......@@ -964,6 +970,9 @@ msgstr ""
msgid "%{userName}'s avatar"
msgstr ""
msgid "%{user_name} (%{user_username}) was removed from %{rotation} in %{schedule} in %{project}. "
msgstr ""
msgid "%{user_name} profile page"
msgstr ""
......
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