Commit 2b028525 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add issue/mr participants to reasign events

Also refactor NotificationService a bit
parent 61548815
...@@ -3,7 +3,7 @@ Note: The upcoming release contains empty lines to reduce the number of merge co ...@@ -3,7 +3,7 @@ Note: The upcoming release contains empty lines to reduce the number of merge co
v 7.8.0 v 7.8.0
- Replace highlight.js with rouge-fork rugments (Stefan Tatschner) - Replace highlight.js with rouge-fork rugments (Stefan Tatschner)
- Make project search case insensitive (Hannes Rosenögger) - Make project search case insensitive (Hannes Rosenögger)
- Include issue/mr participants in list of recipients for close/reopen emails - Include issue/mr participants in list of recipients for reassign/close/reopen emails
- Expose description in groups API - Expose description in groups API
- -
- -
......
...@@ -314,15 +314,7 @@ class NotificationService ...@@ -314,15 +314,7 @@ class NotificationService
end end
def new_resource_email(target, project, method) def new_resource_email(target, project, method)
if target.respond_to?(:participants) recipients = build_recipients(target, project)
recipients = target.participants
else
recipients = []
end
recipients = reject_muted_users(recipients, project)
recipients = reject_mention_users(recipients, project)
recipients = recipients.concat(project_watchers(project)).uniq
recipients.delete(target.author) recipients.delete(target.author)
recipients.each do |recipient| recipients.each do |recipient|
...@@ -331,16 +323,7 @@ class NotificationService ...@@ -331,16 +323,7 @@ class NotificationService
end end
def close_resource_email(target, project, current_user, method) def close_resource_email(target, project, current_user, method)
participants = recipients = build_recipients(target, project)
if target.respond_to?(:participants)
target.participants
else
[target.author, target.assignee]
end
recipients = reject_muted_users(participants, project)
recipients = reject_mention_users(recipients, project)
recipients = recipients.concat(project_watchers(project)).uniq
recipients.delete(current_user) recipients.delete(current_user)
recipients.each do |recipient| recipients.each do |recipient|
...@@ -350,17 +333,7 @@ class NotificationService ...@@ -350,17 +333,7 @@ class NotificationService
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") assignee_id_was = previous_record(target, "assignee_id")
recipients = build_recipients(target, project)
recipients = User.where(id: [target.assignee_id, assignee_id_was])
# Add watchers to email list
recipients = recipients.concat(project_watchers(project))
# reject users with disabled notifications
recipients = reject_muted_users(recipients, project)
recipients = reject_mention_users(recipients, project)
# Reject me from recipients if I reassign an item
recipients.delete(current_user) recipients.delete(current_user)
recipients.each do |recipient| recipients.each do |recipient|
...@@ -369,21 +342,26 @@ class NotificationService ...@@ -369,21 +342,26 @@ class NotificationService
end end
def reopen_resource_email(target, project, current_user, method, status) def reopen_resource_email(target, project, current_user, method, status)
participants = recipients = build_recipients(target, project)
recipients.delete(current_user)
recipients.each do |recipient|
mailer.send(method, recipient.id, target.id, status, current_user.id)
end
end
def build_recipients(target, project)
recipients =
if target.respond_to?(:participants) if target.respond_to?(:participants)
target.participants target.participants
else else
[target.author, target.assignee] [target.author, target.assignee]
end end
recipients = reject_muted_users(participants, project) recipients = reject_muted_users(recipients, project)
recipients = reject_mention_users(recipients, project) recipients = reject_mention_users(recipients, project)
recipients = recipients.concat(project_watchers(project)).uniq recipients = recipients.concat(project_watchers(project)).uniq
recipients.delete(current_user) recipients
recipients.each do |recipient|
mailer.send(method, recipient.id, target.id, status, current_user.id)
end
end end
def mailer def mailer
......
...@@ -187,7 +187,7 @@ describe NotificationService do ...@@ -187,7 +187,7 @@ describe NotificationService do
end end
describe 'Issues' do describe 'Issues' do
let(:issue) { create :issue, assignee: create(:user) } let(:issue) { create :issue, assignee: create(:user), description: 'cc @participant' }
before do before do
build_team(issue.project) build_team(issue.project)
...@@ -197,6 +197,7 @@ describe NotificationService do ...@@ -197,6 +197,7 @@ describe NotificationService do
it do it do
should_email(issue.assignee_id) should_email(issue.assignee_id)
should_email(@u_watcher.id) should_email(@u_watcher.id)
should_email(@u_participant_mentioned.id)
should_not_email(@u_mentioned.id) should_not_email(@u_mentioned.id)
should_not_email(@u_participating.id) should_not_email(@u_participating.id)
should_not_email(@u_disabled.id) should_not_email(@u_disabled.id)
...@@ -222,6 +223,7 @@ describe NotificationService do ...@@ -222,6 +223,7 @@ describe NotificationService do
it 'should email new assignee' do it 'should email new assignee' do
should_email(issue.assignee_id) should_email(issue.assignee_id)
should_email(@u_watcher.id) should_email(@u_watcher.id)
should_email(@u_participant_mentioned.id)
should_not_email(@u_participating.id) should_not_email(@u_participating.id)
should_not_email(@u_disabled.id) should_not_email(@u_disabled.id)
...@@ -242,6 +244,7 @@ describe NotificationService do ...@@ -242,6 +244,7 @@ describe NotificationService do
should_email(issue.assignee_id) should_email(issue.assignee_id)
should_email(issue.author_id) should_email(issue.author_id)
should_email(@u_watcher.id) should_email(@u_watcher.id)
should_email(@u_participant_mentioned.id)
should_not_email(@u_participating.id) should_not_email(@u_participating.id)
should_not_email(@u_disabled.id) should_not_email(@u_disabled.id)
...@@ -262,6 +265,7 @@ describe NotificationService do ...@@ -262,6 +265,7 @@ describe NotificationService do
should_email(issue.assignee_id) should_email(issue.assignee_id)
should_email(issue.author_id) should_email(issue.author_id)
should_email(@u_watcher.id) should_email(@u_watcher.id)
should_email(@u_participant_mentioned.id)
should_not_email(@u_participating.id) should_not_email(@u_participating.id)
should_not_email(@u_disabled.id) should_not_email(@u_disabled.id)
...@@ -404,6 +408,7 @@ describe NotificationService do ...@@ -404,6 +408,7 @@ describe NotificationService do
def build_team(project) def build_team(project)
@u_watcher = create(:user, notification_level: Notification::N_WATCH) @u_watcher = create(:user, notification_level: Notification::N_WATCH)
@u_participating = create(:user, notification_level: Notification::N_PARTICIPATING) @u_participating = create(:user, notification_level: Notification::N_PARTICIPATING)
@u_participant_mentioned = create(:user, username: 'participant', notification_level: Notification::N_PARTICIPATING)
@u_disabled = create(:user, notification_level: Notification::N_DISABLED) @u_disabled = create(:user, notification_level: Notification::N_DISABLED)
@u_mentioned = create(:user, username: 'mention', notification_level: Notification::N_MENTION) @u_mentioned = create(:user, username: 'mention', notification_level: Notification::N_MENTION)
@u_committer = create(:user, username: 'committer') @u_committer = create(:user, username: 'committer')
......
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