Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Editing tags in sidebar should show all tags visible to user #22628

Merged
merged 1 commit into from Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/tags_controller.rb
Expand Up @@ -104,7 +104,7 @@ def index

def list
offset = params[:offset].to_i || 0
tags = guardian.can_admin_tags? ? Tag.all : Tag.used_tags_in_regular_topics(guardian)
tags = guardian.can_admin_tags? ? Tag.all : Tag.visible(guardian)

load_more_query_params = { offset: offset + 1 }

Expand Down
20 changes: 8 additions & 12 deletions spec/requests/tags_controller_spec.rb
Expand Up @@ -1443,20 +1443,16 @@ def parse_topic_ids
end

describe "#list" do
fab!(:tag3) do
Fabricate(:tag, name: "tag3").tap { |tag| Fabricate.times(1, :topic, tags: [tag]) }
end
fab!(:tag3) { Fabricate(:tag, name: "tag3") }
fab!(:tag2) { Fabricate(:tag, name: "tag2") }
fab!(:tag1) { Fabricate(:tag, name: "tag") }

fab!(:tag2) do
Fabricate(:tag, name: "tag2").tap { |tag| Fabricate.times(1, :topic, tags: [tag]) }
end
fab!(:staff_only_tag) { Fabricate(:tag, name: "tag4") }

fab!(:tag1) do
Fabricate(:tag, name: "tag").tap { |tag| Fabricate.times(1, :topic, tags: [tag]) }
let!(:staff_tag_group) do
Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [staff_only_tag.name])
end

fab!(:tag_not_used_in_topics) { Fabricate(:tag, name: "tag4") }

it "should return 403 for an anonymous user" do
get "/tags/list.json"

Expand All @@ -1473,7 +1469,7 @@ def parse_topic_ids
expect(response.status).to eq(404)
end

it "should only return tags used in topics for non admin users" do
it "should only return tags that are visible to the user for non admin users" do
stub_const(TagsController, "LIST_LIMIT", 2) do
sign_in(user)

Expand Down Expand Up @@ -1525,7 +1521,7 @@ def parse_topic_ids
expect(response.status).to eq(200)

expect(response.parsed_body["list_tags"].map { |tag| tag["name"] }).to eq(
[tag3.name, tag_not_used_in_topics.name],
[tag3.name, staff_only_tag.name],
)

expect(response.parsed_body["meta"]["total_rows_list_tags"]).to eq(4)
Expand Down