diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-01-26 07:31:02 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-01-26 07:31:02 +0300 |
commit | 2b02852507466c8cd7dc9a7db7a7e0dd4c7b5183 (patch) | |
tree | 593378ad5166b4351e2feb0c47d603f8e6de83ab /app | |
parent | 615488150bd176088d5b37a2441fd1f11396edf7 (diff) |
Add issue/mr participants to reasign events
Also refactor NotificationService a bit
Diffstat (limited to 'app')
-rw-r--r-- | app/services/notification_service.rb | 52 |
1 files changed, 15 insertions, 37 deletions
diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index 87366b65725..2fc63b9f4b7 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -314,15 +314,7 @@ class NotificationService end def new_resource_email(target, project, method) - if target.respond_to?(:participants) - 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 = build_recipients(target, project) recipients.delete(target.author) recipients.each do |recipient| @@ -331,16 +323,7 @@ class NotificationService end def close_resource_email(target, project, current_user, method) - participants = - 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 = build_recipients(target, project) recipients.delete(current_user) recipients.each do |recipient| @@ -350,17 +333,7 @@ class NotificationService def reassign_resource_email(target, project, current_user, method) assignee_id_was = previous_record(target, "assignee_id") - - 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 = build_recipients(target, project) recipients.delete(current_user) recipients.each do |recipient| @@ -369,21 +342,26 @@ class NotificationService end 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) target.participants else [target.author, target.assignee] end - recipients = reject_muted_users(participants, project) + recipients = reject_muted_users(recipients, project) recipients = reject_mention_users(recipients, project) recipients = recipients.concat(project_watchers(project)).uniq - recipients.delete(current_user) - - recipients.each do |recipient| - mailer.send(method, recipient.id, target.id, status, current_user.id) - end + recipients end def mailer |