A platform for community discussion. Free, open, simple.
FIX: Hide badge notifications for badges that have been deleted (#36990)
Alan Guo Xiang Tana6d3fb1c4ab3
diff --git a/app/models/notification.rb b/app/models/notification.rbindex 9930709a351..d1248d992a4 100644--- a/app/models/notification.rb+++ b/app/models/notification.rb@@ -255,11 +255,11 @@ class Notification < ActiveRecord::Basereturn notifications if badge_ids.empty?- disabled_badge_ids = Badge.where(id: badge_ids, enabled: false).distinct.pluck(:id)+ enabled_badge_ids = Badge.where(id: badge_ids, enabled: true).pluck(:id).to_setnotifications.reject do |n|n.notification_type == types[:granted_badge] &&- disabled_badge_ids.include?(n.data_hash[:badge_id])+ !enabled_badge_ids.include?(n.data_hash[:badge_id])endenddiff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rbindex ef2cce5bca4..42ec13cddc4 100644--- a/spec/models/notification_spec.rb+++ b/spec/models/notification_spec.rb@@ -892,5 +892,13 @@ RSpec.describe Notification doexpect(result).to contain_exactly(enabled_badge_notification, regular_notification)end++ it "filters badge notifications for badges that do not exist" do+ enabled_badge.destroy!++ result = Notification.filter_disabled_badge_notifications([enabled_badge_notification])++ expect(result).to eq([])+ endendend