Commit 49189664 authored by Sean McGivern's avatar Sean McGivern

Send unapproval emails for MRs

parent 85697bec
......@@ -54,11 +54,20 @@ module Emails
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id))
end
def approved_merge_request_email(recipient_id, merge_request_id, updated_by_user_id)
def approved_merge_request_email(recipient_id, merge_request_id, approved_by_user_id)
setup_merge_request_mail(merge_request_id, recipient_id)
@approved_by = User.find(approved_by_user_id)
@approved_by_users = @merge_request.approved_by_users.map(&:name)
mail_answer_thread(@merge_request, merge_request_thread_options(updated_by_user_id, recipient_id))
mail_answer_thread(@merge_request, merge_request_thread_options(approved_by_user_id, recipient_id))
end
def unapproved_merge_request_email(recipient_id, merge_request_id, unapproved_by_user_id)
setup_merge_request_mail(merge_request_id, recipient_id)
@unapproved_by = User.find(approved_by_user_id)
@unapproved_by_users = @merge_request.approved_by_users.map(&:name)
mail_answer_thread(@merge_request, merge_request_thread_options(approved_by_user_id, recipient_id))
end
def resolved_all_discussions_email(recipient_id, merge_request_id, resolved_by_user_id)
......
......@@ -163,7 +163,7 @@ class NotificationService
end
def unapprove_mr(merge_request, current_user)
# TODO: send unapproval email
unapprove_mr_email(merge_request, merge_request.target_project, current_user)
end
def resolve_all_discussions(merge_request, current_user)
......@@ -612,6 +612,14 @@ class NotificationService
end
end
def unapprove_mr_email(merge_request, project, current_user)
recipients = build_recipients(merge_request, project, current_user)
recipients.each do |recipient|
mailer.unapproved_merge_request_email(recipient.id, merge_request.id, current_user.id).deliver_later
end
end
def add_mr_approvers_email(merge_request, approvers, current_user)
approvers.each do |approver|
recipient = approver.user
......
......@@ -405,6 +405,44 @@ describe Notify do
end
end
describe 'that are unapproved' do
let(:last_unapprover) { create(:user) }
subject { Notify.unapproved_merge_request_email(recipient.id, merge_request.id, last_unapprover.id) }
before do
merge_request.approvals.create(user: merge_request.assignee)
end
it_behaves_like 'a multiple recipients email'
it_behaves_like 'an answer to an existing thread with reply-by-email enabled' do
let(:model) { merge_request }
end
it_behaves_like 'it should show Gmail Actions View Merge request link'
it_behaves_like 'an unsubscribeable thread'
it 'is sent as the last unapprover' do
sender = subject.header[:from].addrs[0]
expect(sender.display_name).to eq(last_unapprover.name)
expect(sender.address).to eq(gitlab_sender)
end
it 'has the correct subject' do
is_expected.to have_subject /#{merge_request.title} \(#{merge_request.to_reference}\)/
end
it 'contains the new status' do
is_expected.to have_body_text /unapproved/i
end
it 'contains a link to the merge request' do
is_expected.to have_body_text /#{namespace_project_merge_request_path project.namespace, project, merge_request}/
end
it 'contains the names of all of the approvers' do
is_expected.to have_body_text /#{merge_request.assignee.name}/
end
end
describe 'that are merged' do
subject { Notify.merged_merge_request_email(recipient.id, merge_request.id, merge_author.id) }
......
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