FIX: staff tags are stripped by non-staff
This commit is contained in:
parent
02b21a26dd
commit
846597f563
|
@ -29,7 +29,14 @@ module DiscourseTagging
|
||||||
|
|
||||||
if tag_names.present?
|
if tag_names.present?
|
||||||
category = topic.category
|
category = topic.category
|
||||||
tags = filter_allowed_tags(Tag.where(name: tag_names), guardian, { for_input: true, category: category, selected_tags: tag_names }).to_a
|
|
||||||
|
# guardian is explicitly nil cause we don't want to strip all
|
||||||
|
# staff tags that already passed validation
|
||||||
|
tags = filter_allowed_tags(Tag.where(name: tag_names), nil, {
|
||||||
|
for_input: true,
|
||||||
|
category: category,
|
||||||
|
selected_tags: tag_names
|
||||||
|
}).to_a
|
||||||
|
|
||||||
if tags.size < tag_names.size && (category.nil? || category.tags.count == 0)
|
if tags.size < tag_names.size && (category.nil? || category.tags.count == 0)
|
||||||
tag_names.each do |name|
|
tag_names.each do |name|
|
||||||
|
|
|
@ -158,6 +158,36 @@ describe TagUser do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "correctly handles staff tags" do
|
||||||
|
|
||||||
|
staff = Fabricate(:admin)
|
||||||
|
topic = create_post.topic
|
||||||
|
|
||||||
|
SiteSetting.staff_tags = "foo"
|
||||||
|
|
||||||
|
result = DiscourseTagging.tag_topic_by_names(topic, Guardian.new(user), ["foo"])
|
||||||
|
expect(result).to eq(false)
|
||||||
|
expect(topic.errors[:base].length).to eq(1)
|
||||||
|
|
||||||
|
result = DiscourseTagging.tag_topic_by_names(topic, Guardian.new(staff), ["foo"])
|
||||||
|
expect(result).to eq(true)
|
||||||
|
|
||||||
|
topic.errors[:base].clear
|
||||||
|
|
||||||
|
result = DiscourseTagging.tag_topic_by_names(topic, Guardian.new(user), [])
|
||||||
|
expect(result).to eq(false)
|
||||||
|
expect(topic.errors[:base].length).to eq(1)
|
||||||
|
|
||||||
|
topic.reload
|
||||||
|
|
||||||
|
result = DiscourseTagging.tag_topic_by_names(topic, Guardian.new(user), ["foo", "bar"])
|
||||||
|
expect(result).to eq(true)
|
||||||
|
|
||||||
|
topic.reload
|
||||||
|
expect(topic.tags.length).to eq(2)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
it "is destroyed when a user is deleted" do
|
it "is destroyed when a user is deleted" do
|
||||||
TagUser.create!(user: user, tag: tracked_tag, notification_level: TagUser.notification_levels[:tracking])
|
TagUser.create!(user: user, tag: tracked_tag, notification_level: TagUser.notification_levels[:tracking])
|
||||||
user.destroy!
|
user.destroy!
|
||||||
|
|
Loading…
Reference in New Issue