From 7341b0d03c2a55c67acc7bf0b92a1a2d3a1e5ef9 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 10 Jan 2017 12:18:48 -0500 Subject: [PATCH] Don't give notifications to admins for trust level notifications --- app/models/badge.rb | 7 +++++++ app/services/badge_granter.rb | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/badge.rb b/app/models/badge.rb index 6851b210dce..13e7916f1b1 100644 --- a/app/models/badge.rb +++ b/app/models/badge.rb @@ -1,3 +1,5 @@ +require_dependency 'slug' + class Badge < ActiveRecord::Base # NOTE: These badge ids are not in order! They are grouped logically. # When picking an id, *search* for it. @@ -119,6 +121,10 @@ class Badge < ActiveRecord::Base } end + def awarded_for_trust_level? + id <= 4 + end + def reset_grant_count! self.grant_count = UserBadge.where(badge_id: id).count save! @@ -208,6 +214,7 @@ SQL def i18n_name self.name.downcase.tr(' ', '_') end + end # == Schema Information diff --git a/app/services/badge_granter.rb b/app/services/badge_granter.rb index ece099e4f1f..206ffc14ed7 100644 --- a/app/services/badge_granter.rb +++ b/app/services/badge_granter.rb @@ -274,7 +274,7 @@ class BadgeGranter /*where*/ RETURNING id, user_id, granted_at ) - select w.*, username, locale FROM w + select w.*, username, locale, u.admin FROM w JOIN users u on u.id = w.user_id " @@ -315,6 +315,8 @@ class BadgeGranter # Make this variable in this scope notification = nil + next if (row.admin && badge.awarded_for_trust_level?) + I18n.with_locale(notification_locale) do notification = Notification.create!( user_id: row.user_id,