Commit 1a0d3650 authored by Andy Soiron's avatar Andy Soiron

Merge branch 'ph/345366/attentionRequestEmail' into 'master'

Sends email notifications on attention requested requests

See merge request gitlab-org/gitlab!75201
parents 889c4301 d37b84e3
......@@ -97,6 +97,13 @@ module Emails
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
end
def attention_requested_merge_request_email(recipient_id, merge_request_id, updated_by_user_id, reason = nil)
setup_merge_request_mail(merge_request_id, recipient_id)
@updated_by = User.find(updated_by_user_id)
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id, reason))
end
def merge_request_status_email(recipient_id, merge_request_id, status, updated_by_user_id, reason = nil)
setup_merge_request_mail(merge_request_id, recipient_id)
......
......@@ -6,6 +6,7 @@ class NotificationReason
OWN_ACTIVITY = 'own_activity'
ASSIGNED = 'assigned'
REVIEW_REQUESTED = 'review_requested'
ATTENTION_REQUESTED = 'attention_requested'
MENTIONED = 'mentioned'
SUBSCRIBED = 'subscribed'
......@@ -14,6 +15,7 @@ class NotificationReason
OWN_ACTIVITY,
ASSIGNED,
REVIEW_REQUESTED,
ATTENTION_REQUESTED,
MENTIONED,
SUBSCRIBED
].freeze
......
......@@ -31,6 +31,7 @@ module MergeRequests
private
def notity_user
notification_service.async.attention_requested_of_merge_request(merge_request, current_user, user)
todo_service.create_attention_requested_todo(merge_request, current_user, user)
end
......
......@@ -40,5 +40,9 @@ module NotificationRecipients
def self.build_requested_review_recipients(*args)
::NotificationRecipients::Builder::RequestReview.new(*args).notification_recipients
end
def self.build_attention_requested_recipients(*args)
::NotificationRecipients::Builder::AttentionRequested.new(*args).notification_recipients
end
end
end
# frozen_string_literal: true
module NotificationRecipients
module Builder
class AttentionRequested < Base
attr_reader :merge_request, :current_user, :user
def initialize(merge_request, current_user, user)
@merge_request = merge_request
@current_user = current_user
@user = user
end
def target
merge_request
end
def build!
add_recipients(user, :mention, NotificationReason::ATTENTION_REQUESTED)
end
end
end
end
......@@ -301,6 +301,14 @@ class NotificationService
end
end
def attention_requested_of_merge_request(merge_request, current_user, user)
recipients = NotificationRecipients::BuildService.build_attention_requested_recipients(merge_request, current_user, user)
recipients.each do |recipient|
mailer.attention_requested_merge_request_email(recipient.user.id, merge_request.id, current_user.id, recipient.reason).deliver_later
end
end
# When we add labels to a merge request we should send an email to:
#
# * watchers of the mr's labels
......
%p
#{sanitize_name(@updated_by.name)} requested your attention on #{merge_request_reference_link(@merge_request)}.
<%= sanitize_name(@updated_by.name) %> requested your attention on <%= merge_request_reference_link(@merge_request) %>.
......@@ -13,9 +13,12 @@ RSpec.describe MergeRequests::ToggleAttentionRequestedService do
let(:service) { described_class.new(project: project, current_user: current_user, merge_request: merge_request, user: user) }
let(:result) { service.execute }
let(:todo_service) { spy('todo service') }
let(:notification_service) { spy('notification service') }
before do
allow(NotificationService).to receive(:new) { notification_service }
allow(service).to receive(:todo_service).and_return(todo_service)
allow(service).to receive(:notification_service).and_return(notification_service)
project.add_developer(current_user)
project.add_developer(user)
......@@ -59,6 +62,12 @@ RSpec.describe MergeRequests::ToggleAttentionRequestedService do
service.execute
end
it 'sends email to reviewer' do
expect(notification_service).to receive_message_chain(:async, :attention_requested_of_merge_request).with(merge_request, current_user, user)
service.execute
end
end
context 'assignee exists' do
......
......@@ -2425,6 +2425,45 @@ RSpec.describe NotificationService, :mailer do
let(:notification_trigger) { notification.review_requested_of_merge_request(merge_request, current_user, reviewer) }
end
end
describe '#attention_requested_of_merge_request' do
let_it_be(:current_user) { create(:user) }
let_it_be(:reviewer) { create(:user) }
let_it_be(:merge_request) { create(:merge_request, source_project: project, reviewers: [reviewer]) }
it 'sends email to reviewer', :aggregate_failures do
notification.attention_requested_of_merge_request(merge_request, current_user, reviewer)
merge_request.reviewers.each { |reviewer| should_email(reviewer) }
should_not_email(merge_request.author)
should_not_email(@u_watcher)
should_not_email(@u_participant_mentioned)
should_not_email(@subscriber)
should_not_email(@watcher_and_subscriber)
should_not_email(@u_guest_watcher)
should_not_email(@u_guest_custom)
should_not_email(@u_custom_global)
should_not_email(@unsubscriber)
should_not_email(@u_participating)
should_not_email(@u_disabled)
should_not_email(@u_lazy_participant)
end
it 'adds "attention requested" reason' do
notification.attention_requested_of_merge_request(merge_request, current_user, [reviewer])
merge_request.reviewers.each do |reviewer|
email = find_email_for(reviewer)
expect(email).to have_header('X-GitLab-NotificationReason', NotificationReason::ATTENTION_REQUESTED)
end
end
it_behaves_like 'project emails are disabled' do
let(:notification_target) { merge_request }
let(:notification_trigger) { notification.attention_requested_of_merge_request(merge_request, current_user, reviewer) }
end
end
end
describe 'Projects', :deliver_mails_inline do
......
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