FIX: staff members should see all tags

This commit is contained in:
Régis Hanol 2018-05-13 17:50:21 +02:00
parent 2cf6fb7359
commit 37232fcb58
2 changed files with 22 additions and 15 deletions

View File

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

View File

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