mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FIX: Show deleted bookmark reminders in user bookmarks menu (#25905)
When we send a bookmark reminder, there is an option to delete the underlying bookmark. The Notification record stays around. However, if you want to filter your notifications user menu to only bookmark-based notifications, we were not showing unread bookmark notifications for deleted bookmarks. This commit fixes the issue _going forward_ by adding the bookmarkable_id and bookmarkable_type to the Notification data, so we can look up the underlying Post/Topic/Chat::Message for a deleted bookmark and check user access in this way. Then, it doesn't matter if the bookmark was deleted.
This commit is contained in:
@ -7087,6 +7087,37 @@ RSpec.describe UsersController do
|
||||
expect(notifications.first["data"]["bookmark_id"]).to eq(bookmark_with_reminder.id)
|
||||
end
|
||||
|
||||
it "shows unread notifications even if the bookmark has been deleted if they have bookmarkable data" do
|
||||
bookmark_with_reminder.destroy!
|
||||
|
||||
get "/u/#{user.username}/user-menu-bookmarks"
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
notifications = response.parsed_body["notifications"]
|
||||
expect(notifications.size).to eq(1)
|
||||
expect(notifications.first["data"]["bookmark_id"]).to eq(bookmark_with_reminder.id)
|
||||
end
|
||||
|
||||
it "does not show unread notifications if the bookmark has been deleted if they only have the bookmark_id data" do
|
||||
notif =
|
||||
Notification.find_by(
|
||||
topic: bookmark_with_reminder.bookmarkable.topic,
|
||||
post_number: bookmark_with_reminder.bookmarkable.post_number,
|
||||
)
|
||||
new_data = notif.data_hash
|
||||
new_data.delete(:bookmarkable_type)
|
||||
new_data.delete(:bookmarkable_id)
|
||||
notif.update!(data: JSON.dump(new_data))
|
||||
|
||||
bookmark_with_reminder.destroy!
|
||||
|
||||
get "/u/#{user.username}/user-menu-bookmarks"
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
notifications = response.parsed_body["notifications"]
|
||||
expect(notifications.size).to eq(0)
|
||||
end
|
||||
|
||||
context "with `show_user_menu_avatars` setting enabled" do
|
||||
before { SiteSetting.show_user_menu_avatars = true }
|
||||
|
||||
|
Reference in New Issue
Block a user