FIX: cannot remove tags from a topic

This commit is contained in:
Neil Lalonde 2016-06-09 12:04:34 -04:00
parent 5a03eca74a
commit 5047979f96
2 changed files with 19 additions and 0 deletions

View File

@ -84,6 +84,17 @@ class PostRevisor
end end
end end
track_topic_field(:tags_empty_array) do |tc, val|
if val.present? && tc.guardian.can_tag_topics?
prev_tags = tc.topic.tags.map(&:name)
if !DiscourseTagging.tag_topic_by_names(tc.topic, tc.guardian, [])
tc.check_result(false)
next
end
tc.record_change('tags', prev_tags, nil)
end
end
# AVAILABLE OPTIONS: # AVAILABLE OPTIONS:
# - revised_at: changes the date of the revision # - revised_at: changes the date of the revision
# - force_new_version: bypass ninja-edit window # - force_new_version: bypass ninja-edit window

View File

@ -415,6 +415,14 @@ describe PostRevisor do
expect(post.topic.tags.size).to eq(0) expect(post.topic.tags.size).to eq(0)
end end
it "can remove all tags using tags_empty_array" do
topic.tags = [Fabricate(:tag, name: "stuff")]
result = subject.revise!(Fabricate(:user), { raw: "lets totally update the body", tags_empty_array: "true" })
expect(result).to eq(true)
post.reload
expect(post.topic.tags.size).to eq(0)
end
it "can't add staff-only tags" do it "can't add staff-only tags" do
SiteSetting.staff_tags = "important" SiteSetting.staff_tags = "important"
result = subject.revise!(Fabricate(:user), { raw: "lets totally update the body", tags: ['important', 'stuff'] }) result = subject.revise!(Fabricate(:user), { raw: "lets totally update the body", tags: ['important', 'stuff'] })