Commit abb412d4 authored by Mark Chao's avatar Mark Chao

Allow global event list containing all events

This way we can globally set group only ee events too.
Use nil to indicate global.
parent aec92d16
......@@ -4,6 +4,11 @@ module EE
module NotificationSetting
extend ActiveSupport::Concern
EMAIL_EVENTS_MAPPING = {
::Group => [:new_epic]
}.freeze
FULL_EMAIL_EVENTS = EMAIL_EVENTS_MAPPING.values.flatten.freeze
class_methods do
extend ::Gitlab::Utils::Override
......@@ -11,9 +16,14 @@ module EE
def email_events(source = nil)
result = super.dup
case target
when Group, :group
result << :new_epic
if source.nil?
# Global setting
result.concat(FULL_EMAIL_EVENTS)
else
source_class = source.is_a?(Class) ? source : source.class
EMAIL_EVENTS_MAPPING[source_class]&.tap do |events|
result.concat(events)
end
end
result
......
......@@ -56,5 +56,31 @@ describe NotificationSetting do
)
end
end
context 'global' do
let(:target) { nil }
it 'appends EE specific events' do
expect(subject).to eq(
[
:new_note,
:new_issue,
:reopen_issue,
:close_issue,
:reassign_issue,
:issue_due,
:new_merge_request,
:push_to_merge_request,
:reopen_merge_request,
:close_merge_request,
:reassign_merge_request,
:merge_merge_request,
:failed_pipeline,
:success_pipeline,
:new_epic
]
)
end
end
end
end
......@@ -50,7 +50,9 @@ module API
end
end
%w[group project].each do |source_type|
[Group, Project].each do |source_class|
source_type = source_class.name.underscore
params do
requires :id, type: String, desc: "The #{source_type} ID"
end
......@@ -73,7 +75,7 @@ module API
end
params do
optional :level, type: String, desc: "The #{source_type} notification level"
NotificationSetting.email_events(source_type.to_sym).each do |event|
NotificationSetting.email_events(source_class).each do |event|
optional event, type: Boolean, desc: 'Enable/disable this notification'
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