Class: NotificationRecipients::Builder::Base
- Inherits:
-
Object
- Object
- NotificationRecipients::Builder::Base
show all
- Includes:
- Gitlab::Utils::StrongMemoize
- Defined in:
- app/services/notification_recipients/builder/base.rb
Constant Summary
collapse
- BATCH_SIZE =
100
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Base
10
11
12
|
# File 'app/services/notification_recipients/builder/base.rb', line 10
def initialize(*)
raise 'abstract'
end
|
Instance Method Details
#acting_user ⇒ Object
23
24
25
|
# File 'app/services/notification_recipients/builder/base.rb', line 23
def acting_user
current_user
end
|
#add_recipients(users, type, reason) ⇒ Object
rubocop: disable CodeReuse/ActiveRecord
54
55
56
57
58
59
60
61
62
63
64
|
# File 'app/services/notification_recipients/builder/base.rb', line 54
def add_recipients(users, type, reason)
if users.is_a?(ActiveRecord::Relation)
users = users.includes(:notification_settings)
.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/421821')
end
users = Array(users).compact
preload_users_namespace_bans(users)
recipients.concat(users.map { |u| make_recipient(u, type, reason) })
end
|
#build! ⇒ Object
14
15
16
|
# File 'app/services/notification_recipients/builder/base.rb', line 14
def build!
raise 'abstract'
end
|
#custom_action ⇒ Object
95
96
97
|
# File 'app/services/notification_recipients/builder/base.rb', line 95
def custom_action
nil
end
|
#filter! ⇒ Object
18
19
20
21
|
# File 'app/services/notification_recipients/builder/base.rb', line 18
def filter!
preload_notification_settings
recipients.select!(&:notifiable?)
end
|
#group ⇒ Object
41
42
43
44
45
46
|
# File 'app/services/notification_recipients/builder/base.rb', line 41
def group
namespace = target.try(:namespace)
return namespace if namespace.is_a?(Group)
project&.group || target.try(:group)
end
|
#make_recipient(user, type, reason) ⇒ Object
rubocop: enable CodeReuse/ActiveRecord
73
74
75
76
77
78
79
80
81
82
83
|
# File 'app/services/notification_recipients/builder/base.rb', line 73
def make_recipient(user, type, reason)
NotificationRecipient.new(
user, type,
reason: reason,
project: project,
group: group,
custom_action: custom_action,
target: recipients_target,
acting_user: acting_user
)
end
|
#notification_recipients ⇒ Object
85
86
87
88
89
90
91
92
93
|
# File 'app/services/notification_recipients/builder/base.rb', line 85
def notification_recipients
@notification_recipients ||=
begin
build!
filter!
recipients = self.recipients.sort_by { |r| NotificationReason.priority(r.reason) }.uniq(&:user)
recipients.freeze
end
end
|
#project ⇒ Object
36
37
38
|
# File 'app/services/notification_recipients/builder/base.rb', line 36
def project
target.project
end
|
#recipients ⇒ Object
49
50
51
|
# File 'app/services/notification_recipients/builder/base.rb', line 49
def recipients
@recipients ||= []
end
|
#recipients_target ⇒ Object
32
33
34
|
# File 'app/services/notification_recipients/builder/base.rb', line 32
def recipients_target
target
end
|
#target ⇒ Object
27
28
29
|
# File 'app/services/notification_recipients/builder/base.rb', line 27
def target
raise 'abstract'
end
|
#user_scope ⇒ Object
rubocop: disable CodeReuse/ActiveRecord
68
69
70
|
# File 'app/services/notification_recipients/builder/base.rb', line 68
def user_scope
User.includes(:notification_settings)
end
|