Commit c9f03247 authored by Robert Speicher's avatar Robert Speicher Committed by Robert Speicher

Merge branch 'adamliesko/gitlab-ce-notification-upon-unassignment' into 'master'

Add notification to the former assignee upon unassignment

Replaces !1769

Fixes #3395

See merge request !1818
parent 8a1cafeb
...@@ -34,6 +34,7 @@ v 8.2.0 ...@@ -34,6 +34,7 @@ v 8.2.0
- Add "added", "modified" and "removed" properties to commit object in webhook - Add "added", "modified" and "removed" properties to commit object in webhook
- Rename "Back to" links to "Go to" because its not always a case it point to place user come from - Rename "Back to" links to "Go to" because its not always a case it point to place user come from
- Allow groups to appear in the search results if the group owner allows it - Allow groups to appear in the search results if the group owner allows it
- Add email notification to former assignee upon unassignment (Adam Lieskovský)
- New design for project graphs page - New design for project graphs page
- Remove deprecated dumped yaml file generated from previous job definitions - Remove deprecated dumped yaml file generated from previous job definitions
- Fix incoming email config defaults - Fix incoming email config defaults
......
...@@ -361,11 +361,13 @@ class NotificationService ...@@ -361,11 +361,13 @@ class NotificationService
end end
def reassign_resource_email(target, project, current_user, method) def reassign_resource_email(target, project, current_user, method)
assignee_id_was = previous_record(target, "assignee_id") previous_assignee_id = previous_record(target, "assignee_id")
recipients = build_recipients(target, project, current_user) previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id
recipients = build_recipients(target, project, current_user, [previous_assignee])
recipients.each do |recipient| recipients.each do |recipient|
mailer.send(method, recipient.id, target.id, assignee_id_was, current_user.id) mailer.send(method, recipient.id, target.id, previous_assignee_id, current_user.id)
end end
end end
...@@ -377,9 +379,11 @@ class NotificationService ...@@ -377,9 +379,11 @@ class NotificationService
end end
end end
def build_recipients(target, project, current_user) def build_recipients(target, project, current_user, extra_recipients = nil)
recipients = target.participants(current_user) recipients = target.participants(current_user)
recipients = recipients.concat(extra_recipients).compact.uniq if extra_recipients
recipients = add_project_watchers(recipients, project) recipients = add_project_watchers(recipients, project)
recipients = reject_mention_users(recipients, project) recipients = reject_mention_users(recipients, project)
recipients = reject_muted_users(recipients, project) recipients = reject_muted_users(recipients, project)
......
...@@ -3,13 +3,15 @@ require 'spec_helper' ...@@ -3,13 +3,15 @@ require 'spec_helper'
describe Issues::UpdateService do describe Issues::UpdateService do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
let(:issue) { create(:issue, title: 'Old title') } let(:user3) { create(:user) }
let(:issue) { create(:issue, title: 'Old title', assignee_id: user3.id) }
let(:label) { create(:label) } let(:label) { create(:label) }
let(:project) { issue.project } let(:project) { issue.project }
before do before do
project.team << [user, :master] project.team << [user, :master]
project.team << [user2, :developer] project.team << [user2, :developer]
project.team << [user3, :developer]
end end
describe 'execute' do describe 'execute' do
...@@ -34,9 +36,11 @@ describe Issues::UpdateService do ...@@ -34,9 +36,11 @@ describe Issues::UpdateService do
it { expect(@issue.labels.count).to eq(1) } it { expect(@issue.labels.count).to eq(1) }
it { expect(@issue.labels.first.title).to eq('Bug') } it { expect(@issue.labels.first.title).to eq('Bug') }
it 'should send email to user2 about assign of new issue' do it 'should send email to user2 about assign of new issue and email to user3 about issue unassignment' do
email = ActionMailer::Base.deliveries.last deliveries = ActionMailer::Base.deliveries
expect(email.to.first).to eq(user2.email) email = deliveries.last
recipients = deliveries.last(2).map(&:to).flatten
expect(recipients).to include(user2.email, user3.email)
expect(email.subject).to include(issue.title) expect(email.subject).to include(issue.title)
end end
......
...@@ -3,7 +3,8 @@ require 'spec_helper' ...@@ -3,7 +3,8 @@ require 'spec_helper'
describe MergeRequests::UpdateService do describe MergeRequests::UpdateService do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
let(:merge_request) { create(:merge_request, :simple, title: 'Old title') } let(:user3) { create(:user) }
let(:merge_request) { create(:merge_request, :simple, title: 'Old title', assignee_id: user3.id) }
let(:project) { merge_request.project } let(:project) { merge_request.project }
let(:label) { create(:label) } let(:label) { create(:label) }
...@@ -47,9 +48,11 @@ describe MergeRequests::UpdateService do ...@@ -47,9 +48,11 @@ describe MergeRequests::UpdateService do
with(@merge_request, 'update') with(@merge_request, 'update')
end end
it 'should send email to user2 about assign of new merge_request' do it 'should send email to user2 about assign of new merge request and email to user3 about merge request unassignment' do
email = ActionMailer::Base.deliveries.last deliveries = ActionMailer::Base.deliveries
expect(email.to.first).to eq(user2.email) email = deliveries.last
recipients = deliveries.last(2).map(&:to).flatten
expect(recipients).to include(user2.email, user3.email)
expect(email.subject).to include(merge_request.title) expect(email.subject).to include(merge_request.title)
end end
......
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