Skip to content

A platform for community discussion. Free, open, simple.

FIX: Exclude unreadable bookmarkables from the user `.ics` feed (#39876)

Alan Guo Xiang Tan5c1d29b1320d
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 1e8e40746b9..70c29298ffb 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1946,7 +1946,9 @@ class UsersController < ApplicationController
@bookmark_reminders =
bookmark_query
.order(:reminder_at)
- .map do |bookmark|
+ .filter_map do |bookmark|
+ next if !bookmark.registered_bookmarkable.can_see?(user_guardian, bookmark)
+
bookmark.registered_bookmarkable.serializer.new(
bookmark,
scope: user_guardian,
diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb
index bd5438df238..af276a6c700 100644
--- a/spec/requests/users_controller_spec.rb
+++ b/spec/requests/users_controller_spec.rb
@@ -7376,6 +7376,33 @@ RSpec.describe UsersController do
ICS
end
+ it "excludes bookmark reminders for topics the user cannot see from .ics feed" do
+ Bookmark.where(user: user1).destroy_all
+ private_category = Fabricate(:private_category, group: Fabricate(:group))
+ private_topic = Fabricate(:topic_with_op, category: private_category)
+ Fabricate(
+ :bookmark,
+ name: nil,
+ user: user1,
+ bookmarkable: private_topic,
+ reminder_at: 1.day.from_now,
+ )
+
+ sign_in(user1)
+ get "/u/#{user1.username}/bookmarks.ics"
+
+ expect(response.status).to eq(200)
+ calendar_name =
+ I18n.t("calendar_subscriptions.bookmarks_feed_name", site_title: SiteSetting.title)
+ expect(response.body).to eq(<<~ICS)
+ BEGIN:VCALENDAR
+ VERSION:2.0
+ PRODID:-//Discourse//#{Discourse.current_hostname}//#{Discourse.full_version}//EN
+ X-WR-CALNAME:#{IcalEncoder.encode(calendar_name)}
+ END:VCALENDAR
+ ICS
+ end
+
it "excludes bookmark reminders older than 3 months from .ics feed" do
bookmark1.update_columns(name: nil, reminder_at: 4.months.ago)
bookmark2.update!(name: "Recent reminder", reminder_at: 1.day.from_now)