mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 14:52:46 +08:00
FIX: Search by tag context was broken (#23006)
This commit is contained in:
parent
1b63e046af
commit
cb5ae4dcfa
|
@ -136,7 +136,7 @@ export default Controller.extend({
|
|||
return (!skip && context) || skip === "false";
|
||||
},
|
||||
set(val) {
|
||||
this.set("skip_context", val ? "false" : "true");
|
||||
this.set("skip_context", !val);
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -47,4 +47,24 @@ acceptance("Search - Mobile", function (needs) {
|
|||
"it does not reset input when hitting search icon again"
|
||||
);
|
||||
});
|
||||
|
||||
test("Search context in full page search", async function (assert) {
|
||||
await visit("/search?context=tag&context_id=dev&skip_context=true");
|
||||
|
||||
assert.ok(exists(".search-header .search-context"));
|
||||
|
||||
assert.strictEqual(
|
||||
query(".search-header .search-context input[type='checkbox']").checked,
|
||||
false,
|
||||
"checkbox matches query parameter"
|
||||
);
|
||||
|
||||
await click(".search-header .search-context label");
|
||||
|
||||
assert.strictEqual(
|
||||
query(".search-header .search-context input[type='checkbox']").checked,
|
||||
true,
|
||||
"checkbox toggling works"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -215,7 +215,7 @@ class SearchController < ApplicationController
|
|||
search_context = params[:search_context]
|
||||
unless search_context
|
||||
if (context = params[:context]) && (id = params[:context_id])
|
||||
search_context = { type: context, id: id }
|
||||
search_context = { type: context, id: id, name: id }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -234,7 +234,9 @@ class SearchController < ApplicationController
|
|||
elsif "topic" == search_context[:type]
|
||||
context_obj = Topic.find_by(id: search_context[:id].to_i)
|
||||
elsif "tag" == search_context[:type]
|
||||
context_obj = Tag.where_name(search_context[:name]).first
|
||||
if !DiscourseTagging.hidden_tag_names(guardian).include?(search_context[:id])
|
||||
context_obj = Tag.where_name(search_context[:id]).first
|
||||
end
|
||||
end
|
||||
|
||||
type_filter = nil
|
||||
|
|
|
@ -364,6 +364,61 @@ RSpec.describe SearchController do
|
|||
expect(SearchLog.where(term: "bantha")).to be_blank
|
||||
end
|
||||
|
||||
it "works when using a tag context" do
|
||||
tag = Fabricate(:tag, name: "awesome")
|
||||
awesome_topic.tags << tag
|
||||
SearchIndexer.index(awesome_topic, force: true)
|
||||
|
||||
get "/search.json",
|
||||
params: {
|
||||
q: "awesome",
|
||||
context: "tag",
|
||||
context_id: "awesome",
|
||||
skip_context: false,
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["posts"].length).to eq(1)
|
||||
expect(response.parsed_body["posts"][0]["id"]).to eq(awesome_post.id)
|
||||
end
|
||||
|
||||
context "with restricted tags" do
|
||||
let(:restricted_tag) { Fabricate(:tag) }
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
before do
|
||||
tag_group =
|
||||
Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [restricted_tag.name])
|
||||
awesome_topic.tags << restricted_tag
|
||||
SearchIndexer.index(awesome_topic, force: true)
|
||||
end
|
||||
|
||||
it "works for user with tag group permision" do
|
||||
sign_in(admin)
|
||||
get "/search.json",
|
||||
params: {
|
||||
q: "awesome",
|
||||
context: "tag",
|
||||
context_id: restricted_tag.name,
|
||||
skip_context: false,
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
it "doesn’t work for user without tag group permission" do
|
||||
get "/search.json",
|
||||
params: {
|
||||
q: "awesome",
|
||||
context: "tag",
|
||||
context_id: restricted_tag.name,
|
||||
skip_context: false,
|
||||
}
|
||||
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
end
|
||||
|
||||
context "when rate limited" do
|
||||
before { RateLimiter.enable }
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user