mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Search by tag context was broken (#23006)
This commit is contained in:
@@ -136,7 +136,7 @@ export default Controller.extend({
|
|||||||
return (!skip && context) || skip === "false";
|
return (!skip && context) || skip === "false";
|
||||||
},
|
},
|
||||||
set(val) {
|
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"
|
"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]
|
search_context = params[:search_context]
|
||||||
unless search_context
|
unless search_context
|
||||||
if (context = params[:context]) && (id = params[:context_id])
|
if (context = params[:context]) && (id = params[:context_id])
|
||||||
search_context = { type: context, id: id }
|
search_context = { type: context, id: id, name: id }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -234,7 +234,9 @@ class SearchController < ApplicationController
|
|||||||
elsif "topic" == search_context[:type]
|
elsif "topic" == search_context[:type]
|
||||||
context_obj = Topic.find_by(id: search_context[:id].to_i)
|
context_obj = Topic.find_by(id: search_context[:id].to_i)
|
||||||
elsif "tag" == search_context[:type]
|
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
|
end
|
||||||
|
|
||||||
type_filter = nil
|
type_filter = nil
|
||||||
|
|||||||
@@ -364,6 +364,61 @@ RSpec.describe SearchController do
|
|||||||
expect(SearchLog.where(term: "bantha")).to be_blank
|
expect(SearchLog.where(term: "bantha")).to be_blank
|
||||||
end
|
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
|
context "when rate limited" do
|
||||||
before { RateLimiter.enable }
|
before { RateLimiter.enable }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user