Commit 51266f41 authored by Rémy Coutable's avatar Rémy Coutable

Consider re-assign as a mention from a notification point of view

This will ensure new assignee gets an email even if his notif level is
"on mention".
parent f093d8cc
...@@ -379,7 +379,7 @@ class NotificationService ...@@ -379,7 +379,7 @@ class NotificationService
previous_assignee_id = previous_record(target, "assignee_id") previous_assignee_id = previous_record(target, "assignee_id")
previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id previous_assignee = User.find_by(id: previous_assignee_id) if previous_assignee_id
recipients = build_recipients(target, project, current_user, [previous_assignee]) recipients = build_recipients(target, project, current_user, action: :reassign, extra_recipients: [previous_assignee])
recipients.each do |recipient| recipients.each do |recipient|
mailer.send( mailer.send(
...@@ -400,22 +400,28 @@ class NotificationService ...@@ -400,22 +400,28 @@ class NotificationService
end end
end end
def build_recipients(target, project, current_user, extra_recipients = nil) def build_recipients(target, project, current_user, action: nil, extra_recipients: nil)
recipients = target.participants(current_user) recipients = target.participants(current_user)
recipients = recipients.concat(extra_recipients).compact.uniq if extra_recipients 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)
# Re-assign is considered as a mention of the new assignee so we add the
# new assignee to the list of recipients after we rejected users with
# the "on mention" notification level
if action == :reassign
recipients << target.assignee
end
recipients = reject_muted_users(recipients, project)
recipients = add_subscribed_users(recipients, target) recipients = add_subscribed_users(recipients, target)
recipients = reject_unsubscribed_users(recipients, target) recipients = reject_unsubscribed_users(recipients, target)
recipients.delete(current_user) recipients.delete(current_user)
recipients = recipients.uniq
recipients recipients.uniq
end end
def mailer def mailer
......
...@@ -227,9 +227,11 @@ describe NotificationService, services: true do ...@@ -227,9 +227,11 @@ describe NotificationService, services: true do
end end
describe :reassigned_issue do describe :reassigned_issue do
it 'should email new assignee' do it 'emails new assignee' do
issue.update_attribute(:assignee, @u_mentioned)
notification.reassigned_issue(issue, @u_disabled) notification.reassigned_issue(issue, @u_disabled)
expect(issue.assignee).to be @u_mentioned
should_email(issue.assignee) should_email(issue.assignee)
should_email(@u_watcher) should_email(@u_watcher)
should_email(@u_participant_mentioned) should_email(@u_participant_mentioned)
...@@ -238,6 +240,20 @@ describe NotificationService, services: true do ...@@ -238,6 +240,20 @@ describe NotificationService, services: true do
should_not_email(@u_participating) should_not_email(@u_participating)
should_not_email(@u_disabled) should_not_email(@u_disabled)
end end
it 'does not email new assignee if they are the current user' do
issue.update_attribute(:assignee, @u_mentioned)
notification.reassigned_issue(issue, @u_mentioned)
expect(issue.assignee).to be @u_mentioned
should_email(@u_watcher)
should_email(@u_participant_mentioned)
should_email(@subscriber)
should_not_email(issue.assignee)
should_not_email(@unsubscriber)
should_not_email(@u_participating)
should_not_email(@u_disabled)
end
end end
describe :close_issue do describe :close_issue 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