Commit b010a556 authored by http://jneen.net/'s avatar http://jneen.net/

factor out the `target` argument to helpers

parent 947bff88
...@@ -30,7 +30,7 @@ class NotificationRecipientService ...@@ -30,7 +30,7 @@ class NotificationRecipientService
raise 'abstract' raise 'abstract'
end end
def build(*) def target
raise 'abstract' raise 'abstract'
end end
...@@ -44,7 +44,7 @@ class NotificationRecipientService ...@@ -44,7 +44,7 @@ class NotificationRecipientService
# Ensure that if we modify this array, we aren't modifying the memoised # Ensure that if we modify this array, we aren't modifying the memoised
# participants on the target. # participants on the target.
def participants(target, user) def participants(user)
return unless target.respond_to?(:participants) return unless target.respond_to?(:participants)
target.participants(user).dup target.participants(user).dup
...@@ -92,7 +92,7 @@ class NotificationRecipientService ...@@ -92,7 +92,7 @@ class NotificationRecipientService
reject_users(users, :mention) reject_users(users, :mention)
end end
def add_subscribed_users(recipients, target) def add_subscribed_users(recipients)
return recipients unless target.respond_to? :subscribers return recipients unless target.respond_to? :subscribers
recipients + target.subscribers(project) recipients + target.subscribers(project)
...@@ -184,7 +184,7 @@ class NotificationRecipientService ...@@ -184,7 +184,7 @@ class NotificationRecipientService
end end
end end
def reject_unsubscribed_users(recipients, target) def reject_unsubscribed_users(recipients)
return recipients unless target.respond_to? :subscriptions return recipients unless target.respond_to? :subscriptions
recipients.reject do |user| recipients.reject do |user|
...@@ -193,7 +193,7 @@ class NotificationRecipientService ...@@ -193,7 +193,7 @@ class NotificationRecipientService
end end
end end
def reject_users_without_access(recipients, target) def reject_users_without_access(recipients)
recipients = recipients.select { |u| u.can?(:receive_notifications) } recipients = recipients.select { |u| u.can?(:receive_notifications) }
ability = case target ability = case target
...@@ -210,7 +210,7 @@ class NotificationRecipientService ...@@ -210,7 +210,7 @@ class NotificationRecipientService
end end
end end
def add_labels_subscribers(recipients, target, labels: nil) def add_labels_subscribers(recipients, 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|
...@@ -246,7 +246,7 @@ class NotificationRecipientService ...@@ -246,7 +246,7 @@ class NotificationRecipientService
def build def build
custom_action = build_custom_key(action, target) custom_action = build_custom_key(action, target)
recipients = participants(target, current_user) recipients = participants(current_user)
recipients = add_project_watchers(recipients) recipients = add_project_watchers(recipients)
recipients = add_custom_notifications(recipients, custom_action) recipients = add_custom_notifications(recipients, custom_action)
recipients = reject_mention_users(recipients) recipients = reject_mention_users(recipients)
...@@ -265,14 +265,14 @@ class NotificationRecipientService ...@@ -265,14 +265,14 @@ class NotificationRecipientService
end end
recipients = reject_muted_users(recipients) recipients = reject_muted_users(recipients)
recipients = add_subscribed_users(recipients, target) recipients = add_subscribed_users(recipients)
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)
end end
recipients = reject_unsubscribed_users(recipients, target) recipients = reject_unsubscribed_users(recipients)
recipients = reject_users_without_access(recipients, target) recipients = reject_users_without_access(recipients)
recipients.delete(current_user) if skip_current_user && !current_user.notified_of_own_activity? recipients.delete(current_user) if skip_current_user && !current_user.notified_of_own_activity?
...@@ -311,7 +311,7 @@ class NotificationRecipientService ...@@ -311,7 +311,7 @@ class NotificationRecipientService
return [] if (notification_setting.watch? || notification_setting.participating?) && NotificationSetting::EXCLUDED_WATCHER_EVENTS.include?(custom_action) return [] if (notification_setting.watch? || notification_setting.participating?) && NotificationSetting::EXCLUDED_WATCHER_EVENTS.include?(custom_action)
reject_users_without_access([current_user], target) reject_users_without_access([current_user])
end end
end end
...@@ -328,9 +328,9 @@ class NotificationRecipientService ...@@ -328,9 +328,9 @@ class NotificationRecipientService
end end
def build def build
recipients = add_labels_subscribers([], target, labels: labels) recipients = add_labels_subscribers([], labels: labels)
recipients = reject_unsubscribed_users(recipients, target) recipients = reject_unsubscribed_users(recipients)
recipients = reject_users_without_access(recipients, target) recipients = reject_users_without_access(recipients)
recipients.delete(current_user) unless current_user.notified_of_own_activity? recipients.delete(current_user) unless current_user.notified_of_own_activity?
recipients.uniq recipients.uniq
end end
...@@ -356,7 +356,7 @@ class NotificationRecipientService ...@@ -356,7 +356,7 @@ class NotificationRecipientService
mentioned_users = note.mentioned_users.select { |user| user.can?(ability, subject) } mentioned_users = note.mentioned_users.select { |user| user.can?(ability, subject) }
# Add all users participating in the thread (author, assignee, comment authors) # Add all users participating in the thread (author, assignee, comment authors)
recipients = participants(target, note.author) || mentioned_users recipients = participants(note.author) || mentioned_users
unless note.for_personal_snippet? unless note.for_personal_snippet?
# Merge project watchers # Merge project watchers
...@@ -372,9 +372,9 @@ class NotificationRecipientService ...@@ -372,9 +372,9 @@ class NotificationRecipientService
recipients = reject_muted_users(recipients) recipients = reject_muted_users(recipients)
recipients = add_subscribed_users(recipients, note.noteable) recipients = add_subscribed_users(recipients)
recipients = reject_unsubscribed_users(recipients, note.noteable) recipients = reject_unsubscribed_users(recipients)
recipients = reject_users_without_access(recipients, note.noteable) recipients = reject_users_without_access(recipients)
recipients.delete(note.author) unless note.author.notified_of_own_activity? recipients.delete(note.author) unless note.author.notified_of_own_activity?
recipients.uniq recipients.uniq
......
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