2018-07-05 10:18:17 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-17 17:56:04 +00:00
|
|
|
#
|
|
|
|
# Used by NotificationService to determine who should receive notification
|
|
|
|
#
|
2017-07-26 15:36:49 +00:00
|
|
|
module NotificationRecipientService
|
2017-07-26 15:43:27 +00:00
|
|
|
def self.notifiable_users(users, *args)
|
2017-08-01 19:51:14 +00:00
|
|
|
users.compact.map { |u| NotificationRecipient.new(u, *args) }.select(&:notifiable?).map(&:user)
|
2017-07-26 15:43:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.notifiable?(user, *args)
|
|
|
|
NotificationRecipient.new(user, *args).notifiable?
|
2017-07-26 15:36:49 +00:00
|
|
|
end
|
2017-07-20 18:57:42 +00:00
|
|
|
|
2018-07-04 14:02:01 +00:00
|
|
|
def self.build_recipients(*args)
|
|
|
|
Builder::Default.new(*args).notification_recipients
|
2017-07-26 15:36:49 +00:00
|
|
|
end
|
2017-07-20 18:57:42 +00:00
|
|
|
|
2018-07-04 14:02:01 +00:00
|
|
|
def self.build_new_note_recipients(*args)
|
|
|
|
Builder::NewNote.new(*args).notification_recipients
|
2017-03-17 17:56:04 +00:00
|
|
|
end
|
|
|
|
|
2018-07-04 14:02:01 +00:00
|
|
|
def self.build_merge_request_unmergeable_recipients(*args)
|
|
|
|
Builder::MergeRequestUnmergeable.new(*args).notification_recipients
|
2018-05-09 09:49:33 +00:00
|
|
|
end
|
|
|
|
|
2018-12-05 15:22:52 +00:00
|
|
|
def self.build_project_maintainers_recipients(*args)
|
|
|
|
Builder::ProjectMaintainers.new(*args).notification_recipients
|
|
|
|
end
|
|
|
|
|
2017-07-20 19:21:47 +00:00
|
|
|
module Builder
|
|
|
|
class Base
|
2017-07-20 19:25:32 +00:00
|
|
|
def initialize(*)
|
|
|
|
raise 'abstract'
|
|
|
|
end
|
|
|
|
|
2017-08-01 19:55:04 +00:00
|
|
|
def build!
|
|
|
|
raise 'abstract'
|
|
|
|
end
|
|
|
|
|
|
|
|
def filter!
|
2017-08-01 19:55:13 +00:00
|
|
|
recipients.select!(&:notifiable?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def acting_user
|
|
|
|
current_user
|
2017-07-20 19:21:47 +00:00
|
|
|
end
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2017-07-20 19:36:37 +00:00
|
|
|
def target
|
2017-07-20 19:21:47 +00:00
|
|
|
raise 'abstract'
|
|
|
|
end
|
2018-07-02 13:57:38 +00:00
|
|
|
|
2017-08-01 18:53:43 +00:00
|
|
|
def project
|
|
|
|
target.project
|
|
|
|
end
|
|
|
|
|
2018-05-03 21:32:20 +00:00
|
|
|
def group
|
|
|
|
project&.group || target.try(:group)
|
|
|
|
end
|
|
|
|
|
2017-07-20 23:10:01 +00:00
|
|
|
def recipients
|
|
|
|
@recipients ||= []
|
|
|
|
end
|
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-12-28 17:25:02 +00:00
|
|
|
def add_recipients(users, type, reason)
|
2017-08-01 01:56:56 +00:00
|
|
|
if users.is_a?(ActiveRecord::Relation)
|
|
|
|
users = users.includes(:notification_settings)
|
|
|
|
end
|
|
|
|
|
2018-04-09 08:16:40 +00:00
|
|
|
users = Array(users).compact
|
2017-12-28 17:25:02 +00:00
|
|
|
recipients.concat(users.map { |u| make_recipient(u, type, reason) })
|
2017-07-26 05:22:31 +00:00
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-07-26 05:22:31 +00:00
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-08-01 01:56:56 +00:00
|
|
|
def user_scope
|
|
|
|
User.includes(:notification_settings)
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-08-01 01:56:56 +00:00
|
|
|
|
2017-12-28 17:25:02 +00:00
|
|
|
def make_recipient(user, type, reason)
|
2017-07-31 22:04:42 +00:00
|
|
|
NotificationRecipient.new(
|
|
|
|
user, type,
|
2017-12-28 17:25:02 +00:00
|
|
|
reason: reason,
|
2017-07-31 16:30:35 +00:00
|
|
|
project: project,
|
2018-05-03 21:32:20 +00:00
|
|
|
group: group,
|
2017-07-26 05:22:31 +00:00
|
|
|
custom_action: custom_action,
|
|
|
|
target: target,
|
2017-08-03 01:54:18 +00:00
|
|
|
acting_user: acting_user
|
2017-07-26 05:22:31 +00:00
|
|
|
)
|
2017-08-01 19:55:04 +00:00
|
|
|
end
|
|
|
|
|
2017-12-28 17:25:02 +00:00
|
|
|
def notification_recipients
|
|
|
|
@notification_recipients ||=
|
2017-08-01 19:55:04 +00:00
|
|
|
begin
|
|
|
|
build!
|
|
|
|
filter!
|
2017-12-28 17:25:02 +00:00
|
|
|
recipients = self.recipients.sort_by { |r| NotificationReason.priority(r.reason) }.uniq(&:user)
|
|
|
|
recipients.freeze
|
2017-08-01 19:55:04 +00:00
|
|
|
end
|
2017-07-20 23:10:01 +00:00
|
|
|
end
|
|
|
|
|
2017-07-26 16:32:37 +00:00
|
|
|
def custom_action
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2017-07-20 19:21:47 +00:00
|
|
|
protected
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2017-07-20 23:10:01 +00:00
|
|
|
def add_participants(user)
|
2017-07-20 19:21:47 +00:00
|
|
|
return unless target.respond_to?(:participants)
|
2017-03-30 11:29:52 +00:00
|
|
|
|
2017-12-28 17:25:02 +00:00
|
|
|
add_recipients(target.participants(user), :participating, nil)
|
2017-03-30 11:29:52 +00:00
|
|
|
end
|
|
|
|
|
2017-12-01 15:47:28 +00:00
|
|
|
def add_mentions(user, target:)
|
|
|
|
return unless target.respond_to?(:mentioned_users)
|
|
|
|
|
2017-12-28 17:25:02 +00:00
|
|
|
add_recipients(target.mentioned_users(user), :mention, NotificationReason::MENTIONED)
|
2017-12-01 15:47:28 +00:00
|
|
|
end
|
|
|
|
|
2017-07-20 19:21:47 +00:00
|
|
|
# Get project/group users with CUSTOM notification level
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-08-01 19:55:13 +00:00
|
|
|
def add_custom_notifications
|
2017-07-20 19:21:47 +00:00
|
|
|
user_ids = []
|
2017-03-30 11:29:52 +00:00
|
|
|
|
2017-07-20 19:21:47 +00:00
|
|
|
# Users with a notification setting on group or project
|
2017-08-01 19:55:13 +00:00
|
|
|
user_ids += user_ids_notifiable_on(project, :custom)
|
2018-05-03 21:32:20 +00:00
|
|
|
user_ids += user_ids_notifiable_on(group, :custom)
|
2017-03-30 11:29:52 +00:00
|
|
|
|
2017-07-20 19:21:47 +00:00
|
|
|
# Users with global level custom
|
|
|
|
user_ids_with_project_level_global = user_ids_notifiable_on(project, :global)
|
2018-05-03 21:32:20 +00:00
|
|
|
user_ids_with_group_level_global = user_ids_notifiable_on(group, :global)
|
2017-03-30 11:29:52 +00:00
|
|
|
|
2017-07-20 19:21:47 +00:00
|
|
|
global_users_ids = user_ids_with_project_level_global.concat(user_ids_with_group_level_global)
|
2017-08-01 19:55:13 +00:00
|
|
|
user_ids += user_ids_with_global_level_custom(global_users_ids, custom_action)
|
2017-03-30 11:29:52 +00:00
|
|
|
|
2019-04-17 09:10:42 +00:00
|
|
|
add_recipients(user_scope.where(id: user_ids), :custom, nil)
|
2017-07-20 19:21:47 +00:00
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-03-30 11:29:52 +00:00
|
|
|
|
2017-07-20 23:10:01 +00:00
|
|
|
def add_project_watchers
|
2018-07-30 09:38:20 +00:00
|
|
|
add_recipients(project_watchers, :watch, nil) if project
|
2017-07-20 19:21:47 +00:00
|
|
|
end
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2018-05-03 21:32:20 +00:00
|
|
|
def add_group_watchers
|
|
|
|
add_recipients(group_watchers, :watch, nil)
|
|
|
|
end
|
|
|
|
|
2017-07-20 19:21:47 +00:00
|
|
|
# Get project users with WATCH notification level
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-07-20 19:21:47 +00:00
|
|
|
def project_watchers
|
|
|
|
project_members_ids = user_ids_notifiable_on(project)
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2017-07-20 19:21:47 +00:00
|
|
|
user_ids_with_project_global = user_ids_notifiable_on(project, :global)
|
|
|
|
user_ids_with_group_global = user_ids_notifiable_on(project.group, :global)
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2017-07-20 19:21:47 +00:00
|
|
|
user_ids = user_ids_with_global_level_watch((user_ids_with_project_global + user_ids_with_group_global).uniq)
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2017-08-01 18:53:43 +00:00
|
|
|
user_ids_with_project_setting = select_project_members_ids(user_ids_with_project_global, user_ids)
|
2017-07-20 19:21:47 +00:00
|
|
|
user_ids_with_group_setting = select_group_members_ids(project.group, project_members_ids, user_ids_with_group_global, user_ids)
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2017-08-01 01:56:56 +00:00
|
|
|
user_scope.where(id: user_ids_with_project_setting.concat(user_ids_with_group_setting).uniq)
|
2017-07-20 19:21:47 +00:00
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-05-03 21:32:20 +00:00
|
|
|
def group_watchers
|
|
|
|
user_ids_with_group_global = user_ids_notifiable_on(group, :global)
|
|
|
|
user_ids = user_ids_with_global_level_watch(user_ids_with_group_global)
|
|
|
|
user_ids_with_group_setting = select_group_members_ids(group, [], user_ids_with_group_global, user_ids)
|
|
|
|
|
|
|
|
user_scope.where(id: user_ids_with_group_setting)
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-05-03 21:32:20 +00:00
|
|
|
|
2017-07-20 23:10:01 +00:00
|
|
|
def add_subscribed_users
|
|
|
|
return unless target.respond_to? :subscribers
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2017-12-28 17:25:02 +00:00
|
|
|
add_recipients(target.subscribers(project), :subscription, nil)
|
2017-07-20 19:21:47 +00:00
|
|
|
end
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-08-01 19:55:13 +00:00
|
|
|
def user_ids_notifiable_on(resource, notification_level = nil)
|
2017-07-20 19:21:47 +00:00
|
|
|
return [] unless resource
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2017-08-01 19:55:13 +00:00
|
|
|
scope = resource.notification_settings
|
|
|
|
|
2017-07-20 19:21:47 +00:00
|
|
|
if notification_level
|
2017-08-01 19:55:13 +00:00
|
|
|
scope = scope.where(level: NotificationSetting.levels[notification_level])
|
2017-07-20 19:21:47 +00:00
|
|
|
end
|
2017-08-01 19:55:13 +00:00
|
|
|
|
|
|
|
scope.pluck(:user_id)
|
2017-07-20 19:21:47 +00:00
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2017-07-20 19:21:47 +00:00
|
|
|
# Build a list of user_ids based on project notification settings
|
2017-08-01 18:53:43 +00:00
|
|
|
def select_project_members_ids(global_setting, user_ids_global_level_watch)
|
2017-07-20 19:21:47 +00:00
|
|
|
user_ids = user_ids_notifiable_on(project, :watch)
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2017-07-20 19:21:47 +00:00
|
|
|
# If project setting is global, add to watch list if global setting is watch
|
2017-07-26 16:33:01 +00:00
|
|
|
user_ids + (global_setting & user_ids_global_level_watch)
|
2017-07-20 19:21:47 +00:00
|
|
|
end
|
2017-06-28 10:44:32 +00:00
|
|
|
|
2017-07-20 19:21:47 +00:00
|
|
|
# Build a list of user_ids based on group notification settings
|
|
|
|
def select_group_members_ids(group, project_members, global_setting, user_ids_global_level_watch)
|
|
|
|
uids = user_ids_notifiable_on(group, :watch)
|
|
|
|
|
|
|
|
# Group setting is global, add to user_ids list if global setting is watch
|
2017-07-26 16:33:01 +00:00
|
|
|
uids + (global_setting & user_ids_global_level_watch) - project_members
|
2017-07-20 19:21:47 +00:00
|
|
|
end
|
2017-06-28 10:44:32 +00:00
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-07-20 19:21:47 +00:00
|
|
|
def user_ids_with_global_level_watch(ids)
|
|
|
|
settings_with_global_level_of(:watch, ids).pluck(:user_id)
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-07-20 19:21:47 +00:00
|
|
|
def user_ids_with_global_level_custom(ids, action)
|
2017-08-01 00:09:01 +00:00
|
|
|
settings_with_global_level_of(:custom, ids).pluck(:user_id)
|
2017-07-20 19:21:47 +00:00
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-07-20 19:21:47 +00:00
|
|
|
def settings_with_global_level_of(level, ids)
|
|
|
|
NotificationSetting.where(
|
|
|
|
user_id: ids,
|
|
|
|
source_type: nil,
|
|
|
|
level: NotificationSetting.levels[level]
|
|
|
|
)
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2017-07-20 23:10:01 +00:00
|
|
|
def add_labels_subscribers(labels: nil)
|
|
|
|
return unless target.respond_to? :labels
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2017-07-20 19:21:47 +00:00
|
|
|
(labels || target.labels).each do |label|
|
2017-12-28 17:25:02 +00:00
|
|
|
add_recipients(label.subscribers(project), :subscription, nil)
|
2017-07-20 19:21:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2017-07-20 19:21:47 +00:00
|
|
|
class Default < Base
|
2018-07-30 10:30:36 +00:00
|
|
|
MENTION_TYPE_ACTIONS = [:new_issue, :new_merge_request].freeze
|
|
|
|
|
2017-07-20 19:25:32 +00:00
|
|
|
attr_reader :target
|
|
|
|
attr_reader :current_user
|
|
|
|
attr_reader :action
|
2019-04-07 18:35:16 +00:00
|
|
|
attr_reader :previous_assignees
|
2017-07-20 19:25:32 +00:00
|
|
|
attr_reader :skip_current_user
|
2019-02-06 12:41:17 +00:00
|
|
|
|
2019-04-07 18:35:16 +00:00
|
|
|
def initialize(target, current_user, action:, custom_action: nil, previous_assignees: nil, skip_current_user: true)
|
2017-07-20 19:25:32 +00:00
|
|
|
@target = target
|
|
|
|
@current_user = current_user
|
|
|
|
@action = action
|
2018-03-30 12:25:46 +00:00
|
|
|
@custom_action = custom_action
|
2019-04-07 18:35:16 +00:00
|
|
|
@previous_assignees = previous_assignees
|
2017-07-20 19:25:32 +00:00
|
|
|
@skip_current_user = skip_current_user
|
|
|
|
end
|
|
|
|
|
2019-02-06 12:41:17 +00:00
|
|
|
def add_watchers
|
|
|
|
add_project_watchers
|
|
|
|
end
|
|
|
|
|
2017-08-01 19:55:04 +00:00
|
|
|
def build!
|
2017-07-20 23:10:01 +00:00
|
|
|
add_participants(current_user)
|
2019-02-06 12:41:17 +00:00
|
|
|
add_watchers
|
2017-08-01 19:55:13 +00:00
|
|
|
add_custom_notifications
|
2017-07-20 19:21:47 +00:00
|
|
|
|
2017-08-01 19:55:13 +00:00
|
|
|
# Re-assign is considered as a mention of the new assignee
|
2017-07-20 19:21:47 +00:00
|
|
|
case custom_action
|
2019-04-07 18:35:16 +00:00
|
|
|
when :reassign_merge_request, :reassign_issue
|
2017-12-28 17:25:02 +00:00
|
|
|
add_recipients(previous_assignees, :mention, nil)
|
|
|
|
add_recipients(target.assignees, :mention, NotificationReason::ASSIGNED)
|
2017-07-20 19:21:47 +00:00
|
|
|
end
|
|
|
|
|
2017-07-20 23:10:01 +00:00
|
|
|
add_subscribed_users
|
2017-07-20 19:21:47 +00:00
|
|
|
|
2018-07-30 10:30:36 +00:00
|
|
|
if self.class.mention_type_actions.include?(custom_action)
|
2017-12-01 15:47:28 +00:00
|
|
|
# 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)
|
|
|
|
|
2017-12-28 17:25:02 +00:00
|
|
|
# We use the `:participating` notification level in order to match existing legacy behavior as captured
|
|
|
|
# in existing specs (notification_service_spec.rb ~ line 507)
|
2019-04-07 18:35:16 +00:00
|
|
|
if target.is_a?(Issuable)
|
|
|
|
add_recipients(target.assignees, :participating, NotificationReason::ASSIGNED)
|
|
|
|
end
|
2017-12-28 17:25:02 +00:00
|
|
|
|
2017-07-20 23:10:01 +00:00
|
|
|
add_labels_subscribers
|
2017-07-20 19:21:47 +00:00
|
|
|
end
|
2017-08-01 19:55:04 +00:00
|
|
|
end
|
2017-07-20 19:21:47 +00:00
|
|
|
|
2017-08-01 19:55:13 +00:00
|
|
|
def acting_user
|
|
|
|
current_user if skip_current_user
|
2017-03-17 17:56:04 +00:00
|
|
|
end
|
2017-07-20 19:37:36 +00:00
|
|
|
|
|
|
|
# Build event key to search on custom notification level
|
2018-07-23 02:42:19 +00:00
|
|
|
# Check NotificationSetting.email_events
|
2017-07-20 19:37:36 +00:00
|
|
|
def custom_action
|
|
|
|
@custom_action ||= "#{action}_#{target.class.model_name.name.underscore}".to_sym
|
|
|
|
end
|
2018-07-30 10:30:36 +00:00
|
|
|
|
|
|
|
def self.mention_type_actions
|
|
|
|
MENTION_TYPE_ACTIONS.dup
|
|
|
|
end
|
2017-03-17 17:56:04 +00:00
|
|
|
end
|
|
|
|
|
2017-07-20 19:21:47 +00:00
|
|
|
class NewNote < Base
|
2017-07-20 19:25:32 +00:00
|
|
|
attr_reader :note
|
2017-08-01 18:53:43 +00:00
|
|
|
def initialize(note)
|
2017-07-20 19:25:32 +00:00
|
|
|
@note = note
|
2017-08-01 18:53:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def target
|
|
|
|
note.noteable
|
|
|
|
end
|
|
|
|
|
2017-08-02 21:21:31 +00:00
|
|
|
# NOTE: may be nil, in the case of a PersonalSnippet
|
|
|
|
#
|
|
|
|
# (this is okay because NotificationRecipient is written
|
|
|
|
# to handle nil projects)
|
2017-08-01 18:53:43 +00:00
|
|
|
def project
|
|
|
|
note.project
|
2017-07-20 19:25:32 +00:00
|
|
|
end
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2018-05-03 21:32:20 +00:00
|
|
|
def group
|
|
|
|
if note.for_project_noteable?
|
|
|
|
project.group
|
|
|
|
else
|
|
|
|
target.try(:group)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-01 19:55:04 +00:00
|
|
|
def build!
|
2017-07-20 19:21:47 +00:00
|
|
|
# Add all users participating in the thread (author, assignee, comment authors)
|
2017-07-20 23:10:01 +00:00
|
|
|
add_participants(note.author)
|
2017-12-01 15:47:28 +00:00
|
|
|
add_mentions(note.author, target: note)
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2018-02-28 07:48:23 +00:00
|
|
|
if note.for_project_noteable?
|
2017-07-20 19:21:47 +00:00
|
|
|
# Merge project watchers
|
2017-07-20 23:10:01 +00:00
|
|
|
add_project_watchers
|
2018-05-03 21:32:20 +00:00
|
|
|
else
|
|
|
|
add_group_watchers
|
2017-07-20 19:21:47 +00:00
|
|
|
end
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2018-05-03 21:32:20 +00:00
|
|
|
add_custom_notifications
|
2017-07-20 23:10:01 +00:00
|
|
|
add_subscribed_users
|
2017-08-01 19:55:04 +00:00
|
|
|
end
|
|
|
|
|
2017-08-01 19:55:13 +00:00
|
|
|
def custom_action
|
|
|
|
:new_note
|
|
|
|
end
|
2017-03-17 17:56:04 +00:00
|
|
|
|
2017-08-01 19:55:13 +00:00
|
|
|
def acting_user
|
|
|
|
note.author
|
2017-07-20 19:21:47 +00:00
|
|
|
end
|
2017-03-17 17:56:04 +00:00
|
|
|
end
|
2018-05-09 09:49:33 +00:00
|
|
|
|
|
|
|
class MergeRequestUnmergeable < Base
|
|
|
|
attr_reader :target
|
|
|
|
def initialize(merge_request)
|
|
|
|
@target = merge_request
|
|
|
|
end
|
|
|
|
|
|
|
|
def build!
|
|
|
|
target.merge_participants.each do |user|
|
|
|
|
add_recipients(user, :participating, nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def custom_action
|
|
|
|
:unmergeable_merge_request
|
|
|
|
end
|
|
|
|
|
|
|
|
def acting_user
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
2018-12-05 15:22:52 +00:00
|
|
|
|
|
|
|
class ProjectMaintainers < Base
|
|
|
|
attr_reader :target
|
|
|
|
|
|
|
|
def initialize(target, action:)
|
|
|
|
@target = target
|
|
|
|
@action = action
|
|
|
|
end
|
|
|
|
|
|
|
|
def build!
|
|
|
|
return [] unless project
|
|
|
|
|
2019-04-17 09:10:42 +00:00
|
|
|
add_recipients(project.team.maintainers, :mention, nil)
|
2018-12-05 15:22:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def acting_user
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
2017-03-17 17:56:04 +00:00
|
|
|
end
|
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
|
|
|
NotificationRecipientService::Builder::Default.prepend_if_ee('EE::NotificationRecipientBuilders::Default') # rubocop: disable Cop/InjectEnterpriseEditionModule
|
|
|
|
NotificationRecipientService.prepend_if_ee('EE::NotificationRecipientService')
|