Class: NotificationRecipients::Builder::Default

Inherits:
Base
  • Object
show all
Defined in:
app/services/notification_recipients/builder/default.rb

Constant Summary collapse

MENTION_TYPE_ACTIONS =
[:new_issue, :new_merge_request].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#add_recipients, #filter!, #group, #make_recipient, #notification_recipients, #project, #recipients, #recipients_target, #user_scope

Constructor Details

#initialize(target, current_user, action:, custom_action: nil, previous_assignees: nil, skip_current_user: true) ⇒ Default

Returns a new instance of Default.



14
15
16
17
18
19
20
21
# File 'app/services/notification_recipients/builder/default.rb', line 14

def initialize(target, current_user, action:, custom_action: nil, previous_assignees: nil, skip_current_user: true)
  @target = target
  @current_user = current_user
  @action = action
  @custom_action = custom_action
  @previous_assignees = previous_assignees
  @skip_current_user = skip_current_user
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



10
11
12
# File 'app/services/notification_recipients/builder/default.rb', line 10

def action
  @action
end

#current_userObject (readonly)

Returns the value of attribute current_user.



9
10
11
# File 'app/services/notification_recipients/builder/default.rb', line 9

def current_user
  @current_user
end

#previous_assigneesObject (readonly)

Returns the value of attribute previous_assignees.



11
12
13
# File 'app/services/notification_recipients/builder/default.rb', line 11

def previous_assignees
  @previous_assignees
end

#skip_current_userObject (readonly)

Returns the value of attribute skip_current_user.



12
13
14
# File 'app/services/notification_recipients/builder/default.rb', line 12

def skip_current_user
  @skip_current_user
end

#targetObject (readonly)

Returns the value of attribute target.



8
9
10
# File 'app/services/notification_recipients/builder/default.rb', line 8

def target
  @target
end

Class Method Details

.mention_type_actionsObject



70
71
72
# File 'app/services/notification_recipients/builder/default.rb', line 70

def self.mention_type_actions
  MENTION_TYPE_ACTIONS.dup
end

Instance Method Details

#acting_userObject



60
61
62
# File 'app/services/notification_recipients/builder/default.rb', line 60

def acting_user
  current_user if skip_current_user
end

#add_watchersObject



23
24
25
# File 'app/services/notification_recipients/builder/default.rb', line 23

def add_watchers
  add_project_watchers
end

#build!Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/services/notification_recipients/builder/default.rb', line 27

def build!
  add_participants(current_user)
  add_watchers
  add_custom_notifications

  # Re-assign is considered as a mention of the new assignee
  case custom_action
  when :reassign_merge_request, :reassign_issue
    add_recipients(previous_assignees, :mention, nil)
    add_recipients(target.assignees, :mention, NotificationReason::ASSIGNED)
  when :change_reviewer_merge_request
    add_recipients(previous_assignees, :mention, nil)
    add_recipients(target.reviewers, :mention, NotificationReason::REVIEW_REQUESTED)
  end

  add_subscribed_users

  if self.class.mention_type_actions.include?(custom_action)
    # These will all be participants as well, but adding with the :mention
    # type ensures that users with the mention notification level will
    # receive them, too.
    add_mentions(current_user, target: target)

    # We use the `:participating` notification level in order to match existing legacy behavior as captured
    # in existing specs (notification_service_spec.rb ~ line 507)
    if target.is_a?(Issuable)
      add_recipients(target.assignees, :participating, NotificationReason::ASSIGNED)
    end

    add_labels_subscribers
  end
end

#custom_actionObject

Build event key to search on custom notification level Check NotificationSetting.email_events



66
67
68
# File 'app/services/notification_recipients/builder/default.rb', line 66

def custom_action
  @custom_action ||= "#{action}_#{target.class.model_name.name.underscore}".to_sym
end