A platform for community discussion. Free, open, simple.
FIX: Exclude hidden topic posts and small actions from the RSS feed. (#18649)
Roman Rizzid25ca2a468ec
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rbindex 520aab3bccd..c404cb6969b 100644--- a/app/controllers/posts_controller.rb+++ b/app/controllers/posts_controller.rb@@ -79,6 +79,8 @@ class PostsController < ApplicationControllerrss_description = I18n.t("rss_description.private_posts")elseposts = Post.public_posts+ .visible+ .where(post_type: Post.types[:regular]).order(created_at: :desc).where('posts.id <= ?', last_post_id).where('posts.id > ?', last_post_id - 50)@@ -122,6 +124,7 @@ class PostsController < ApplicationControllerraise Discourse::NotFound unless guardian.can_see_profile?(user)posts = Post.public_posts+ .visible.where(user_id: user.id).where(post_type: Post.types[:regular]).order(created_at: :desc)diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rbindex 348a5d026a8..a7ffbdb8bee 100644--- a/spec/requests/posts_controller_spec.rb+++ b/spec/requests/posts_controller_spec.rb@@ -2063,6 +2063,29 @@ RSpec.describe PostsController doexpect(body).to include(public_post.url)end+ it "doesn't include posts from hidden topics" do+ public_post.topic.update!(visible: false)++ get "/u/#{user.username}/activity.rss"++ expect(response.status).to eq(200)++ body = response.body+ expect(body).not_to include(public_post.url)+ end++ it "excludes small actions" do+ small_action = Fabricate(:small_action, user: user)++ get "/u/#{user.username}/activity.rss"++ expect(response.status).to eq(200)++ body = response.body++ expect(body).not_to include(small_action.canonical_url)+ end+it 'returns public posts as JSON' dopublic_postprivate_post@@ -2164,6 +2187,33 @@ RSpec.describe PostsController doexpect(body).to_not include(private_post.url)end+ it "doesn't include posts from hidden topics" do+ public_post.topic.update!(visible: false)++ get "/posts.rss"++ expect(response.status).to eq(200)++ body = response.body++ # we cache in redis, in rare cases this can cause a flaky test+ PostsHelper.clear_canonical_cache!(public_post)++ expect(body).not_to include(public_post.canonical_url)+ end++ it "excludes small actions" do+ small_action = Fabricate(:small_action)++ get "/posts.rss"++ expect(response.status).to eq(200)++ body = response.body++ expect(body).not_to include(small_action.canonical_url)+ end+it 'returns public posts with topic for json' dotopicless_post.update topic_id: -100