summaryrefslogtreecommitdiff
path: root/app/mailers/notify.rb
diff options
context:
space:
mode:
authorWei-Meng Lee <wlee@gitlab.com>2019-04-26 23:17:06 +0800
committerWei-Meng Lee <wlee@gitlab.com>2019-05-31 20:49:27 +0800
commit03e08ab775312b92440caadc06a88b6f6805bc18 (patch)
tree668f476b3207c62488267f72e0205b7b97fca67d /app/mailers/notify.rb
parent31775ad83aa35fa29e66d3322e6bdf921f4e1792 (diff)
downloadgitlab-ce-03e08ab775312b92440caadc06a88b6f6805bc18.tar.gz
Guarantee order of notification settings
Diffstat (limited to 'app/mailers/notify.rb')
-rw-r--r--app/mailers/notify.rb12
1 files changed, 2 insertions, 10 deletions
diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb
index 11738afecb9..f78be3882d6 100644
--- a/app/mailers/notify.rb
+++ b/app/mailers/notify.rb
@@ -82,16 +82,8 @@ class Notify < BaseMailer
group_notification_email = nil
if notification_group
- # Get notification group's and ancestors' notification settings
- group_ids = notification_group.self_and_ancestors_ids
- notification_settings = notification_group.notification_settings.where(user: @current_user) # rubocop: disable CodeReuse/ActiveRecord
-
- # Exploit notification_group.self_and_ancestors_ids being ordered from
- # most nested to least nested to iterate through group ancestors
- group_ids.each do |group_id|
- group_notification_email = notification_settings.find { |ns| ns.source_id == group_id }&.notification_email
- break if group_notification_email.present?
- end
+ notification_settings = notification_group.notification_settings(hierarchy_order: :asc).where(user: @current_user) # rubocop: disable CodeReuse/ActiveRecord
+ group_notification_email = notification_settings.find { |n| n.notification_email.present? }&.notification_email
end
# Return group-specific email address if present, otherwise return global