FIX: Preserve `preview_theme_id` param on topic redirects (#23965)

Why this change?

When the URL `/t/1234?preview_theme_id=21` is loaded, we redirect to
`/t/<topic slug>/1234` stripping the `preview_theme_id` query params.

What does this change do?

This change builds on 61248652cd and
simply adds the `preview_theme_id` query param when redirecting.
This commit is contained in:
Alan Guo Xiang Tan 2023-10-19 09:32:56 +08:00 committed by GitHub
parent 788651467b
commit b4eb078b0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -1253,7 +1253,7 @@ class TopicsController < ApplicationController
raise(SiteSetting.detailed_404 ? ex : Discourse::NotFound)
end
opts = params.slice(:page, :print, :filter_top_level_replies)
opts = params.slice(:page, :print, :filter_top_level_replies, :preview_theme_id)
opts.delete(:page) if params[:page] == 0
url = topic.relative_url

View File

@ -2177,7 +2177,7 @@ RSpec.describe TopicsController do
it "preserves only select query params" do
get "/t/external_id/asdf.json", params: { filter_top_level_replies: true }
expect(response.status).to eq(301)
expect(response).to redirect_to(topic.relative_url + ".json?filter_top_level_replies=true")
expect(response).to redirect_to("#{topic.relative_url}.json?filter_top_level_replies=true")
get "/t/external_id/asdf.json", params: { not_valid: true }
expect(response.status).to eq(301)
@ -2186,13 +2186,18 @@ RSpec.describe TopicsController do
get "/t/external_id/asdf.json", params: { filter_top_level_replies: true, post_number: 9999 }
expect(response.status).to eq(301)
expect(response).to redirect_to(
topic.relative_url + "/9999.json?filter_top_level_replies=true",
"#{topic.relative_url}/9999.json?filter_top_level_replies=true",
)
get "/t/external_id/asdf.json", params: { filter_top_level_replies: true, print: true }
get "/t/external_id/asdf.json",
params: {
filter_top_level_replies: true,
print: true,
preview_theme_id: 9999,
}
expect(response.status).to eq(301)
expect(response).to redirect_to(
topic.relative_url + ".json?print=true&filter_top_level_replies=true",
"#{topic.relative_url}.json?print=true&filter_top_level_replies=true&preview_theme_id=9999",
)
end