diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb index ec7871349..406f1fc5c 100644 --- a/lib/post_revisor.rb +++ b/lib/post_revisor.rb @@ -84,6 +84,17 @@ class PostRevisor 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: # - revised_at: changes the date of the revision # - force_new_version: bypass ninja-edit window diff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rb index 402ebf6bf..977c5f24f 100644 --- a/spec/components/post_revisor_spec.rb +++ b/spec/components/post_revisor_spec.rb @@ -415,6 +415,14 @@ describe PostRevisor do expect(post.topic.tags.size).to eq(0) 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 SiteSetting.staff_tags = "important" result = subject.revise!(Fabricate(:user), { raw: "lets totally update the body", tags: ['important', 'stuff'] })