FIX: Support tag query param on /tag/{name} routes (#20742)

This commit is contained in:
Isaac Janzen 2023-03-20 13:51:39 -05:00 committed by GitHub
parent f0569db49d
commit ca4b73d20c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 2 deletions

View File

@ -545,6 +545,6 @@ class TagsController < ::ApplicationController
end
def tag_params
[@tag_id].concat(Array(@additional_tags))
Array(params[:tags]).concat(Array(@additional_tags))
end
end

View File

@ -3,7 +3,7 @@
module TopicQueryParams
def build_topic_list_options
options = {}
params[:tags] = [params[:tag_id]] if params[:tag_id].present? && guardian.can_tag_pms?
params[:tags] = [params[:tag_id], *Array(params[:tags])].uniq if params[:tag_id].present?
TopicQuery.public_valid_options.each do |key|
if params.key?(key)

View File

@ -434,6 +434,28 @@ RSpec.describe TagsController do
expect(response.status).to eq(200)
end
it "can handle additional tags in query params" do
tag2 = Fabricate(:tag)
topic_with_two_tags = Fabricate(:topic, tags: [tag, tag2])
get "/tag/test.json?match_all_tags=true&tags[]=#{tag2.name}"
expect(response.status).to eq(200)
expect(response.parsed_body["topic_list"]["topics"].map { |t| t["id"] }).to contain_exactly(
topic_with_two_tags.id,
)
end
it "can handle duplicate tags in query params" do
tag2 = Fabricate(:tag)
topic_with_two_tags = Fabricate(:topic, tags: [tag, tag2])
get "/tag/test.json?match_all_tags=true&tags[]=test&tags[]=#{tag2.name}"
expect(response.status).to eq(200)
expect(response.parsed_body["topic_list"]["topics"].map { |t| t["id"] }).to contain_exactly(
topic_with_two_tags.id,
)
end
it "handles special tag 'none'" do
SiteSetting.pm_tags_allowed_for_groups = "1|2|3"