mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:15:05 +08:00
FIX: Support tag query param on /tag/{name}
routes (#20742)
This commit is contained in:
parent
f0569db49d
commit
ca4b73d20c
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user