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

move the build arguments to the initializers

parent b1334ed9
...@@ -21,11 +21,13 @@ class NotificationRecipientService ...@@ -21,11 +21,13 @@ class NotificationRecipientService
end end
module Builder module Builder
class Base class Base
attr_reader :project def initialize(*)
def initialize(project) raise 'abstract'
@project = project end
def build
raise 'abstract'
end end
def build(*) def build(*)
...@@ -226,7 +228,22 @@ class NotificationRecipientService ...@@ -226,7 +228,22 @@ class NotificationRecipientService
end end
class Default < Base class Default < Base
def build(target, current_user, action:, previous_assignee: nil, skip_current_user: true) attr_reader :project
attr_reader :target
attr_reader :current_user
attr_reader :action
attr_reader :previous_assignee
attr_reader :skip_current_user
def initialize(project, target, current_user, action:, previous_assignee: nil, skip_current_user: true)
@project = project
@target = target
@current_user = current_user
@action = action
@previous_assignee = previous_assignee
@skip_current_user = skip_current_user
end
def build
custom_action = build_custom_key(action, target) custom_action = build_custom_key(action, target)
recipients = participants(target, current_user) recipients = participants(target, current_user)
...@@ -264,7 +281,18 @@ class NotificationRecipientService ...@@ -264,7 +281,18 @@ class NotificationRecipientService
end end
class Pipeline < Base class Pipeline < Base
def build(target, current_user, action:) attr_reader :project
attr_reader :target
attr_reader :current_user
attr_reader :action
def initialize(project, target, current_user, action:)
@project = project
@target = target
@current_user = current_user
@action = action
end
def build
return [] unless current_user return [] unless current_user
custom_action = custom_action =
...@@ -288,7 +316,18 @@ class NotificationRecipientService ...@@ -288,7 +316,18 @@ class NotificationRecipientService
end end
class Relabeled < Base class Relabeled < Base
def build(target, current_user, labels:) attr_reader :project
attr_reader :target
attr_reader :current_user
attr_reader :labels
def initialize(project, target, current_user, labels:)
@project = project
@target = target
@current_user = current_user
@labels = labels
end
def build
recipients = add_labels_subscribers([], target, labels: labels) recipients = add_labels_subscribers([], 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)
...@@ -298,9 +337,16 @@ class NotificationRecipientService ...@@ -298,9 +337,16 @@ class NotificationRecipientService
end end
class NewNote < Base class NewNote < Base
def build(note) attr_reader :project
target = note.noteable attr_reader :note
attr_reader :target
def initialize(project, note)
@project = project
@note = note
@target = note.noteable
end
def build(note)
ability, subject = if note.for_personal_snippet? ability, subject = if note.for_personal_snippet?
[:read_personal_snippet, note.noteable] [:read_personal_snippet, note.noteable]
else else
...@@ -337,18 +383,18 @@ class NotificationRecipientService ...@@ -337,18 +383,18 @@ class NotificationRecipientService
end end
def build_recipients(*a) def build_recipients(*a)
Builder::Default.new(@project).build(*a) Builder::Default.new(@project, *a).build
end end
def build_pipeline_recipients(*a) def build_pipeline_recipients(*a)
Builder::Pipeline.new(@project).build(*a) Builder::Pipeline.new(@project, *a).build
end end
def build_relabeled_recipients(*a) def build_relabeled_recipients(*a)
Builder::Relabeled.new(@project).build(*a) Builder::Relabeled.new(@project, *a).build
end end
def build_new_note_recipients(note) def build_new_note_recipients(*a)
Builder::NewNote.new(@project).build(note) Builder::NewNote.new(@project, *a).build
end end
end end
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