FIX: Add to tags result set only visible tags (#10580)
This commit is contained in:
parent
fc7bd3e605
commit
38c9c87128
|
@ -809,8 +809,10 @@ class Search
|
|||
.order("name asc")
|
||||
.limit(limit)
|
||||
|
||||
hidden_tag_names = DiscourseTagging.hidden_tag_names(@guardian)
|
||||
|
||||
tags.each do |tag|
|
||||
@results.add(tag)
|
||||
@results.add(tag) if !hidden_tag_names.include?(tag.name)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -64,4 +64,34 @@ describe Search do
|
|||
end
|
||||
end
|
||||
|
||||
context "#execute" do
|
||||
before do
|
||||
SiteSetting.tagging_enabled = true
|
||||
end
|
||||
|
||||
context "staff tags" do
|
||||
fab!(:hidden_tag) { Fabricate(:tag) }
|
||||
let!(:staff_tag_group) { Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name]) }
|
||||
fab!(:topic) { Fabricate(:topic, tags: [hidden_tag]) }
|
||||
fab!(:post) { Fabricate(:post, topic: topic) }
|
||||
|
||||
before do
|
||||
SiteSetting.tagging_enabled = true
|
||||
|
||||
SearchIndexer.enable
|
||||
SearchIndexer.index(hidden_tag, force: true)
|
||||
SearchIndexer.index(topic, force: true)
|
||||
end
|
||||
|
||||
it "are visible to staff users" do
|
||||
result = Search.execute(hidden_tag.name, guardian: Guardian.new(Fabricate(:admin)))
|
||||
expect(result.tags).to contain_exactly(hidden_tag)
|
||||
end
|
||||
|
||||
it "are hidden to regular users" do
|
||||
result = Search.execute(hidden_tag.name, guardian: Guardian.new(Fabricate(:user)))
|
||||
expect(result.tags).to contain_exactly()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue