A platform for community discussion. Free, open, simple.
FIX: Filter inaccessible topic notifications in user menu messages (#41167)
Gabriel Grubbafafe1fcc2cff
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rbindex 3c7c313af83..003b1914d1c 100644--- a/app/controllers/users_controller.rb+++ b/app/controllers/users_controller.rb@@ -2029,6 +2029,8 @@ class UsersController < ApplicationController],).to_a+ unread_notifications =+ Notification.filter_inaccessible_topic_notifications(guardian, unread_notifications)if unread_notifications.size < USER_MENU_LIST_LIMITexclude_topic_ids = unread_notifications.filter_map(&:topic_id).uniq@@ -2053,6 +2055,8 @@ class UsersController < ApplicationController.for_user_menu(current_user.id, limit: limit).where(read: true, notification_type: Notification.types[:group_message_summary]).to_a+ read_notifications =+ Notification.filter_inaccessible_topic_notifications(guardian, read_notifications)endif unread_notifications.present?diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rbindex f272289e63e..d78320cbaec 100644--- a/spec/requests/users_controller_spec.rb+++ b/spec/requests/users_controller_spec.rb@@ -8190,6 +8190,47 @@ RSpec.describe UsersController do)end+ context "with notifications for inaccessible private messages" do+ fab!(:sender, :coding_horror)++ fab!(:forbidden_pm) do+ Fabricate(+ :private_message_topic,+ title: "Confidential Acquisition Plan",+ user: sender,+ recipient: user,+ )+ end++ fab!(:forbidden_post) { Fabricate(:post, topic: forbidden_pm, user: sender) }++ fab!(:forbidden_pm_notification) do+ Fabricate(+ :private_message_notification,+ read: false,+ user: user,+ topic: forbidden_pm,+ post: forbidden_post,+ created_at: 3.minutes.ago,+ )+ end++ before { TopicAllowedUser.where(topic: forbidden_pm, user: user).delete_all }++ it "does not disclose titles of PMs the user can no longer access" do+ get "/u/#{user.username}/user-menu-private-messages"++ expect(response.status).to eq(200)+ expect(response.body).not_to include(forbidden_pm.title)+ expect(+ response.parsed_body["unread_notifications"].map { |notification| notification["id"] },+ ).to contain_exactly(+ unread_pm_notification.id,+ unread_group_message_summary_notification.id,+ )+ end+ end+it "sends an array of read group_message_summary notifications" doread_group_message_summary_notification2 =Fabricate(