Commit c1dc6bef authored by Sean Arnold's avatar Sean Arnold

Add mailer for user removed from rotation

- Html and text templates
parent a35b2fa9
...@@ -13,6 +13,7 @@ module EE ...@@ -13,6 +13,7 @@ module EE
include ::Emails::Epics include ::Emails::Epics
include ::Emails::Requirements include ::Emails::Requirements
include ::Emails::UserCap include ::Emails::UserCap
include ::Emails::OncallRotation
end end
attr_reader :group 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,24 @@ module EE ...@@ -76,8 +76,24 @@ module EE
end end
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 private
def project_owners_and_participants(rotation, user)
project = rotation.project
owners = project.members.owners.map(&:user).presence || [project.owner] || project.group&.owners
excluding_user = [owners, rotation.participants.map(&:user)].uniq - [user]
excluding_user.compact.flatten
end
def add_mr_approvers_email(merge_request, approvers, current_user) def add_mr_approvers_email(merge_request, approvers, current_user)
approvers.each do |approver| approvers.each do |approver|
mailer.add_merge_request_approver_email(approver.id, merge_request.id, current_user.id).deliver_later mailer.add_merge_request_approver_email(approver.id, merge_request.id, current_user.id).deliver_later
......
...@@ -18,6 +18,7 @@ module IncidentManagement ...@@ -18,6 +18,7 @@ module IncidentManagement
if deleted if deleted
save_current_shift! save_current_shift!
send_notification
end end
end end
...@@ -34,6 +35,10 @@ module IncidentManagement ...@@ -34,6 +35,10 @@ module IncidentManagement
oncall_rotation.touch oncall_rotation.touch
end end
def send_notification
NotificationService.new.oncall_user_removed(oncall_rotation, user_to_remove)
end
end end
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 ...@@ -896,8 +896,9 @@ RSpec.describe EE::NotificationService, :mailer do
end end
context 'IncidentManagement::Oncall' do context 'IncidentManagement::Oncall' do
describe '#notify_oncall_users_of_alert' do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
describe '#notify_oncall_users_of_alert' do
let_it_be(:alert) { create(:alert_management_alert) } let_it_be(:alert) { create(:alert_management_alert) }
let_it_be(:project) { alert.project } let_it_be(:project) { alert.project }
...@@ -921,5 +922,18 @@ RSpec.describe EE::NotificationService, :mailer do ...@@ -921,5 +922,18 @@ RSpec.describe EE::NotificationService, :mailer do
.by 1 .by 1
end end
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
end end
...@@ -800,6 +800,12 @@ msgstr "" ...@@ -800,6 +800,12 @@ msgstr ""
msgid "%{retryButtonStart}Try again%{retryButtonEnd} or %{newFileButtonStart}attach a new file%{newFileButtonEnd}." msgid "%{retryButtonStart}Try again%{retryButtonEnd} or %{newFileButtonStart}attach a new file%{newFileButtonEnd}."
msgstr "" 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" msgid "%{seconds}s"
msgstr "" msgstr ""
...@@ -964,6 +970,9 @@ msgstr "" ...@@ -964,6 +970,9 @@ msgstr ""
msgid "%{userName}'s avatar" msgid "%{userName}'s avatar"
msgstr "" msgstr ""
msgid "%{user_name} (%{user_username}) was removed from %{rotation} in %{schedule} in %{project}. "
msgstr ""
msgid "%{user_name} profile page" msgid "%{user_name} profile page"
msgstr "" 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