FIX: Hide badge notifications for badges that have been deleted (#36990)

Follow-up to 121eb1b0f8
This commit is contained in:
Alan Guo Xiang Tan
2026-01-08 08:21:00 +08:00
committed by GitHub
parent b6fd490792
commit a6d3fb1c4a
2 changed files with 10 additions and 2 deletions
+2 -2
View File
@@ -255,11 +255,11 @@ class Notification < ActiveRecord::Base
return 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_set
notifications.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])
end
end
+8
View File
@@ -892,5 +892,13 @@ RSpec.describe Notification do
expect(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([])
end
end
end