diff options
Diffstat (limited to 'app/models/notification_recipient.rb')
-rw-r--r-- | app/models/notification_recipient.rb | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/app/models/notification_recipient.rb b/app/models/notification_recipient.rb index 793cce191fa..6889e0d776b 100644 --- a/app/models/notification_recipient.rb +++ b/app/models/notification_recipient.rb @@ -47,14 +47,14 @@ class NotificationRecipient def suitable_notification_level? case notification_level - when :disabled, nil - false - when :custom - custom_enabled? || %i[participating mention].include?(@type) - when :watch, :participating - !action_excluded? when :mention @type == :mention + when :participating + !excluded_participating_action? && %i[participating mention watch].include?(@type) + when :custom + custom_enabled? || %i[participating mention].include?(@type) + when :watch + !excluded_watcher_action? else false end @@ -100,18 +100,14 @@ class NotificationRecipient end end - def action_excluded? - excluded_watcher_action? || excluded_participating_action? - end - def excluded_watcher_action? - return false unless @custom_action && notification_level == :watch + return false unless @custom_action NotificationSetting::EXCLUDED_WATCHER_EVENTS.include?(@custom_action) end def excluded_participating_action? - return false unless @custom_action && notification_level == :participating + return false unless @custom_action NotificationSetting::EXCLUDED_PARTICIPATING_EVENTS.include?(@custom_action) end @@ -123,15 +119,19 @@ class NotificationRecipient return @read_ability if instance_variable_defined?(:@read_ability) @read_ability = - case @target - when Issuable - :"read_#{@target.to_ability_name}" - when Ci::Pipeline + if @target.is_a?(Ci::Pipeline) :read_build # We have build trace in pipeline emails - when ActiveRecord::Base - :"read_#{@target.class.model_name.name.underscore}" - else - nil + elsif default_ability_for_target + :"read_#{default_ability_for_target}" + end + end + + def default_ability_for_target + @default_ability_for_target ||= + if @target.respond_to?(:to_ability_name) + @target.to_ability_name + elsif @target.class.respond_to?(:model_name) + @target.class.model_name.name.underscore end end |