FIX: Add to tags result set only visible tags (#10580)

This commit is contained in:
Dan Ungureanu 2020-09-02 13:24:40 +03:00 committed by GitHub
parent fc7bd3e605
commit 38c9c87128
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -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

View File

@ -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