FIX: return 404 `not found` error if a topic is deleted. (#11987)

Currently, it's returning 403 invalid access error which causes issue in Google webmaster tools.
This commit is contained in:
Vinoth Kannan 2021-02-09 11:17:06 +05:30 committed by GitHub
parent f4db1675f3
commit 7354636502
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -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

View File

@ -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