A platform for community discussion. Free, open, simple.
FIX: Respect query params like `exclude_tag` in RSS feed endpoints (#39130)
Régis HANOL44982c13f0d6
diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rbindex d4d86be8798..3a370c32b14 100644--- a/app/controllers/list_controller.rb+++ b/app/controllers/list_controller.rb@@ -58,13 +58,12 @@ class ListController < ApplicationControllerdefine_method(filter) do |options = nil|list_opts = build_topic_list_optionslist_opts.merge!(options) if options- user = current_userif params[:category].blank? && filter == :latest &&!SiteSetting.show_category_definitions_in_topic_listslist_opts[:no_definitions] = trueend- list = TopicQuery.new(user, list_opts).public_send("list_#{filter}")+ list = TopicQuery.new(current_user, list_opts).public_send("list_#{filter}")if guardian.can_create_shared_draft? && @category.present?if @category.id == SiteSetting.shared_drafts_category.to_i@@ -75,7 +74,7 @@ class ListController < ApplicationController# destination are this categoryshared_drafts =TopicQuery.new(- user,+ current_user,category: SiteSetting.shared_drafts_category,destination_category_id: list_opts[:category],).list_latest@@ -238,13 +237,11 @@ class ListController < ApplicationControllerdef latest_feeddiscourse_expires_in 1.minute- options = { order: "created" }.merge(build_topic_list_options)-@title = "#{SiteSetting.title} - #{I18n.t("rss_description.latest")}"@link = "#{Discourse.base_url}/latest"@atom_link = "#{Discourse.base_url}/latest.rss"@description = I18n.t("rss_description.latest")- @topic_list = TopicQuery.new(nil, options).list_latest+ @topic_list = topic_query(nil, order: "created").list_latestrender "list", formats: [:rss]end@@ -259,7 +256,7 @@ class ListController < ApplicationControllerperiod = params[:period] || SiteSetting.top_page_default_timeframe.to_symTopTopic.validate_period(period)- @topic_list = TopicQuery.new(nil).list_top_for(period)+ @topic_list = topic_query(nil).list_top_for(period)render "list", formats: [:rss]end@@ -272,7 +269,7 @@ class ListController < ApplicationController@atom_link = "#{Discourse.base_url}/hot.rss"@description = I18n.t("rss_description.hot")- @topic_list = TopicQuery.new(nil).list_hot+ @topic_list = topic_query(nil).list_hotrender "list", formats: [:rss]end@@ -286,7 +283,7 @@ class ListController < ApplicationController@atom_link = "#{Discourse.base_url_no_prefix}#{@category.url}.rss"@description ="#{I18n.t("topics_in_category", category: @category.name)} #{@category.description}"- @topic_list = TopicQuery.new(current_user).list_new_in_category(@category)+ @topic_list = topic_query.list_new_in_category(@category)render "list", formats: [:rss]end@@ -302,7 +299,7 @@ class ListController < ApplicationController@atom_link = "#{target_user.full_url}/activity/topics.rss"@description = I18n.t("rss_description.user_topics", username: target_user.username)- @topic_list = TopicQuery.new(nil, order: "created").public_send("list_topics_by", target_user)+ @topic_list = topic_query(nil, order: "created").public_send("list_topics_by", target_user)render "list", formats: [:rss]end@@ -359,7 +356,7 @@ class ListController < ApplicationController@title = "#{SiteSetting.title} - #{@description}"@link = "#{Discourse.base_url}/top?period=#{period}"@atom_link = "#{Discourse.base_url}/top.rss?period=#{period}"- @topic_list = TopicQuery.new(nil).list_top_for(period)+ @topic_list = topic_query(nil).list_top_for(period)render "list", formats: [:rss]end@@ -382,6 +379,10 @@ class ListController < ApplicationControllerprivate+ def topic_query(user = current_user, opts = {})+ TopicQuery.new(user, build_topic_list_options.merge(opts))+ end+def page_paramsroute_params = { format: "json" }diff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rbindex 377687a47b0..d7a9f02bcaa 100644--- a/spec/requests/list_controller_spec.rb+++ b/spec/requests/list_controller_spec.rb@@ -728,6 +728,83 @@ RSpec.describe ListController doexpect(response.media_type).to eq("application/rss+xml")endend++ describe "RSS feeds ignore current user" do+ fab!(:muted_topic, :topic)++ before do+ Fabricate(:post, topic: muted_topic)+ sign_in(user)+ TopicUser.change(+ user.id,+ muted_topic.id,+ notification_level: TopicUser.notification_levels[:muted],+ )+ end++ it "includes muted topics in top RSS" do+ TopTopic.create!(topic: muted_topic, yearly_score: 1.0)+ get "/top.rss?period=yearly"+ expect(response.status).to eq(200)+ expect(response.body).to include(muted_topic.title)+ end++ it "includes muted topics in hot RSS" do+ TopicHotScore.create!(topic: muted_topic, score: 1.0)+ get "/hot.rss"+ expect(response.status).to eq(200)+ expect(response.body).to include(muted_topic.title)+ end+ end++ describe "exclude_tag" do+ fab!(:tag) { Fabricate(:tag, name: "excludeme") }+ fab!(:tagged_topic) { Fabricate(:topic, tags: [tag]) }+ fab!(:untagged_topic, :topic)++ before do+ Fabricate(:post, topic: tagged_topic)+ Fabricate(:post, topic: untagged_topic)+ end++ it "is respected in latest RSS" do+ get "/latest.rss?exclude_tag=excludeme"+ expect(response.status).to eq(200)+ expect(response.body).to include(untagged_topic.title)+ expect(response.body).not_to include(tagged_topic.title)+ end++ it "is respected in top RSS" do+ TopTopic.create!(topic: tagged_topic, yearly_score: 1.0)+ TopTopic.create!(topic: untagged_topic, yearly_score: 1.0)++ get "/top.rss?period=yearly&exclude_tag=excludeme"+ expect(response.status).to eq(200)+ expect(response.body).to include(untagged_topic.title)+ expect(response.body).not_to include(tagged_topic.title)+ end++ it "is respected in hot RSS" do+ TopicHotScore.create!(topic: tagged_topic, score: 1.0)+ TopicHotScore.create!(topic: untagged_topic, score: 1.0)++ get "/hot.rss?exclude_tag=excludeme"+ expect(response.status).to eq(200)+ expect(response.body).to include(untagged_topic.title)+ expect(response.body).not_to include(tagged_topic.title)+ end++ it "is respected in user topics RSS" do+ sign_in(user)+ tagged_topic.update!(user: user)+ untagged_topic.update!(user: user)++ get "/u/#{user.username}/activity/topics.rss?exclude_tag=excludeme"+ expect(response.status).to eq(200)+ expect(response.body).to include(untagged_topic.title)+ expect(response.body).not_to include(tagged_topic.title)+ end+ endenddescribe "Top" do@@ -862,6 +939,19 @@ RSpec.describe ListController doexpect(response.body).to_not include("/forum/forum")expect(response.body).to include("http://test.localhost/forum/c/#{category.slug}")end++ it "respects exclude_tag query param" do+ tag = Fabricate(:tag, name: "excludeme")+ tagged_topic = Fabricate(:topic, category: category, tags: [tag])+ Fabricate(:post, topic: tagged_topic)+ untagged_topic = Fabricate(:topic, category: category)+ Fabricate(:post, topic: untagged_topic)++ get "/c/#{category.slug}/#{category.id}.rss?exclude_tag=excludeme"+ expect(response.status).to eq(200)+ expect(response.body).to include(untagged_topic.title)+ expect(response.body).not_to include(tagged_topic.title)+ endenddescribe "category default views" do