diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index aa3c6c57bb7..54f29248b65 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -848,7 +848,24 @@ class TopicsController < ApplicationController def feed raise Discourse::NotFound if !Post.exists?(topic_id: params[:topic_id]) - @topic_view = TopicView.new(params[:topic_id]) + begin + @topic_view = TopicView.new(params[:topic_id]) + rescue Discourse::NotLoggedIn + raise Discourse::NotFound + rescue Discourse::InvalidAccess => ex + + deleted = guardian.can_see_topic?(ex.obj, false) || + (!guardian.can_see_topic?(ex.obj) && + ex.obj&.access_topic_via_group && + ex.obj.deleted_at) + + raise Discourse::NotFound.new( + nil, + check_permalinks: deleted, + original_path: ex.obj.relative_url + ) + end + discourse_expires_in 1.minute render 'topics/show', formats: [:rss] end diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index 71a7b9ba9e9..ee3c2ddde75 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -2540,6 +2540,12 @@ RSpec.describe TopicsController do get "/t/foo/#{topic.id}.rss" expect(response.status).to eq(404) end + + it 'returns 404 when the topic is deleted' do + topic.trash! + get "/t/foo/#{topic.id}.rss" + expect(response.status).to eq(404) + end end describe '#invite_group' do