Refactoring notification service to find subscriptions per project

parent 7fcd469e
...@@ -75,7 +75,7 @@ class NotificationService ...@@ -75,7 +75,7 @@ class NotificationService
# * watchers of the issue's labels # * watchers of the issue's labels
# #
def relabeled_issue(issue, added_labels, current_user) def relabeled_issue(issue, added_labels, current_user)
relabeled_resource_email(issue, added_labels, current_user, :relabeled_issue_email) relabeled_resource_email(issue, issue.project, added_labels, current_user, :relabeled_issue_email)
end end
# When create a merge request we should send an email to: # When create a merge request we should send an email to:
...@@ -118,7 +118,7 @@ class NotificationService ...@@ -118,7 +118,7 @@ class NotificationService
# * watchers of the mr's labels # * watchers of the mr's labels
# #
def relabeled_merge_request(merge_request, added_labels, current_user) def relabeled_merge_request(merge_request, added_labels, current_user)
relabeled_resource_email(merge_request, added_labels, current_user, :relabeled_merge_request_email) relabeled_resource_email(merge_request, merge_request.target_project, added_labels, current_user, :relabeled_merge_request_email)
end end
def close_mr(merge_request, current_user) def close_mr(merge_request, current_user)
...@@ -205,7 +205,7 @@ class NotificationService ...@@ -205,7 +205,7 @@ class NotificationService
recipients = reject_muted_users(recipients, note.project) recipients = reject_muted_users(recipients, note.project)
recipients = add_subscribed_users(recipients, note.noteable) recipients = add_subscribed_users(recipients, note.project, note.noteable)
recipients = reject_unsubscribed_users(recipients, note.noteable) recipients = reject_unsubscribed_users(recipients, note.noteable)
recipients = reject_users_without_access(recipients, note.noteable) recipients = reject_users_without_access(recipients, note.noteable)
...@@ -505,17 +505,17 @@ class NotificationService ...@@ -505,17 +505,17 @@ class NotificationService
end end
end end
def add_subscribed_users(recipients, target) def add_subscribed_users(recipients, project, target)
return recipients unless target.respond_to? :subscribers return recipients unless target.respond_to? :subscribers
recipients + target.subscribers recipients + target.subscribers(project)
end end
def add_labels_subscribers(recipients, target, labels: nil) def add_labels_subscribers(recipients, project, target, labels: nil)
return recipients unless target.respond_to? :labels return recipients unless target.respond_to? :labels
(labels || target.labels).each do |label| (labels || target.labels).each do |label|
recipients += label.subscribers recipients += label.subscribers(project)
end end
recipients recipients
...@@ -571,8 +571,8 @@ class NotificationService ...@@ -571,8 +571,8 @@ class NotificationService
end end
end end
def relabeled_resource_email(target, labels, current_user, method) def relabeled_resource_email(target, project, labels, current_user, method)
recipients = build_relabeled_recipients(target, current_user, labels: labels) recipients = build_relabeled_recipients(target, project, current_user, labels: labels)
label_names = labels.map(&:name) label_names = labels.map(&:name)
recipients.each do |recipient| recipients.each do |recipient|
...@@ -608,10 +608,10 @@ class NotificationService ...@@ -608,10 +608,10 @@ class NotificationService
end end
recipients = reject_muted_users(recipients, project) recipients = reject_muted_users(recipients, project)
recipients = add_subscribed_users(recipients, target) recipients = add_subscribed_users(recipients, project, target)
if [:new_issue, :new_merge_request].include?(custom_action) if [:new_issue, :new_merge_request].include?(custom_action)
recipients = add_labels_subscribers(recipients, target) recipients = add_labels_subscribers(recipients, project, target)
end end
recipients = reject_unsubscribed_users(recipients, target) recipients = reject_unsubscribed_users(recipients, target)
...@@ -622,8 +622,8 @@ class NotificationService ...@@ -622,8 +622,8 @@ class NotificationService
recipients.uniq recipients.uniq
end end
def build_relabeled_recipients(target, current_user, labels:) def build_relabeled_recipients(target, project, current_user, labels:)
recipients = add_labels_subscribers([], target, labels: labels) recipients = add_labels_subscribers([], project, target, labels: labels)
recipients = reject_unsubscribed_users(recipients, target) recipients = reject_unsubscribed_users(recipients, target)
recipients = reject_users_without_access(recipients, target) recipients = reject_users_without_access(recipients, target)
recipients.delete(current_user) recipients.delete(current_user)
......
This diff is collapsed.
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