Skip to content

A platform for community discussion. Free, open, simple.

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

Dan Ungureanu38c9c8712897
diff --git a/lib/search.rb b/lib/search.rb
index 9180e1a105e..23d274b6010 100644
--- a/lib/search.rb
+++ b/lib/search.rb
@@ -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
diff --git a/spec/lib/search_spec.rb b/spec/lib/search_spec.rb
index e37367bee2e..784b4f8c544 100644
--- a/spec/lib/search_spec.rb
+++ b/spec/lib/search_spec.rb
@@ -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