Skip to content

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

FIX: staff members should see all tags

Régis Hanol37232fcb58b5
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index 4069ab60930..f566dc453ce 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -32,22 +32,20 @@ class TagsController < ::ApplicationController
end
format.json do
+ ungrouped_tags = Tag.where("tags.id NOT IN (select tag_id from tag_group_memberships)")
+ ungrouped_tags = ungrouped_tags.where("tags.topic_count > 0") unless guardian.can_admin_tags?
+
if SiteSetting.tags_listed_by_group
grouped_tag_counts = TagGroup.allowed(guardian).order('name ASC').includes(:tags).map do |tag_group|
{ id: tag_group.id, name: tag_group.name, tags: self.class.tag_counts_json(tag_group.tags) }
end
- ungrouped_tags = Tag.where("tags.id NOT IN (select tag_id from tag_group_memberships) AND tags.topic_count > 0")
-
render json: {
tags: self.class.tag_counts_json(ungrouped_tags), # tags that don't belong to a group
extras: { tag_groups: grouped_tag_counts }
}
else
- unrestricted_tags = DiscourseTagging.filter_visible(
- Tag.where("tags.id NOT IN (select tag_id from category_tags) AND tags.topic_count > 0"),
- guardian
- )
+ unrestricted_tags = DiscourseTagging.filter_visible(ungrouped_tags, guardian)
categories = Category.where("id in (select category_id from category_tags)")
.where("id in (?)", guardian.allowed_category_ids)
diff --git a/spec/requests/tags_controller_spec.rb b/spec/requests/tags_controller_spec.rb
index 1c6ca7d8111..13a991ad8d3 100644
--- a/spec/requests/tags_controller_spec.rb
+++ b/spec/requests/tags_controller_spec.rb
@@ -8,8 +8,8 @@ describe TagsController do
describe '#index' do
before do
- tag = Fabricate(:tag, name: 'test')
- topic_tag = Fabricate(:tag, name: 'topic-test', topic_count: 1)
+ Fabricate(:tag, name: 'test')
+ Fabricate(:tag, name: 'topic-test', topic_count: 1)
end
shared_examples "successfully retrieve tags with topic_count > 0" do
@@ -25,19 +25,28 @@ describe TagsController do
end
context "with tags_listed_by_group enabled" do
- before do
- SiteSetting.tags_listed_by_group = true
- end
-
+ before { SiteSetting.tags_listed_by_group = true }
include_examples "successfully retrieve tags with topic_count > 0"
end
context "with tags_listed_by_group disabled" do
- before do
- SiteSetting.tags_listed_by_group = false
+ before { SiteSetting.tags_listed_by_group = false }
+ include_examples "successfully retrieve tags with topic_count > 0"
+ end
+
+ context "when user can admin tags" do
+
+ it "succesfully retrieve all tags" do
+ sign_in(Fabricate(:admin))
+
+ get "/tags.json"
+
+ expect(response).to be_success
+
+ tags = JSON.parse(response.body)["tags"]
+ expect(tags.length).to eq(2)
end
- include_examples "successfully retrieve tags with topic_count > 0"
end
end