A platform for community discussion. Free, open, simple.
FIX: Process tag synonyms when approving reviewable queued post (#30810)
Martin Brennan35507d4090fd
diff --git a/lib/topic_creator.rb b/lib/topic_creator.rbindex c3f5e3b3346..92c8703e218 100644--- a/lib/topic_creator.rb+++ b/lib/topic_creator.rb@@ -192,11 +192,14 @@ class TopicCreatordef setup_tags(topic)if @opts[:tags].present?- if @opts[:skip_validations]- DiscourseTagging.add_or_create_tags_by_name(topic, @opts[:tags])- else- valid_tags = DiscourseTagging.tag_topic_by_names(topic, @guardian, @opts[:tags])- unless valid_tags+ # We can try the full tagging workflow which does validations and other+ # things like replacing synonyms first, but if this fails then we can try+ # the simple workflow if validations are skipped.+ valid_tags = DiscourseTagging.tag_topic_by_names(topic, @guardian, @opts[:tags])+ if !valid_tags+ if @opts[:skip_validations]+ DiscourseTagging.add_or_create_tags_by_name(topic, @opts[:tags])+ elsetopic.errors.add(:base, :unable_to_tag)rollback_from_errors!(topic)enddiff --git a/spec/models/reviewable_queued_post_spec.rb b/spec/models/reviewable_queued_post_spec.rbindex bd929c0baa2..094d6774012 100644--- a/spec/models/reviewable_queued_post_spec.rb+++ b/spec/models/reviewable_queued_post_spec.rb@@ -320,6 +320,16 @@ RSpec.describe ReviewableQueuedPost, type: :model doexpect(Topic.count).to eq(topic_count)expect(Post.count).to eq(post_count)end++ it "remaps tags with synonyms when approved" do+ syn_tag = Fabricate(:tag, name: "syntag", target_tag: Fabricate(:tag, name: "maintag"))+ reviewable.payload["tags"] += ["syntag"]++ result = reviewable.perform(moderator, :approve_post)++ expect(result.success?).to eq(true)+ expect(result.created_post_topic.tags.pluck(:name)).to match_array(%w[cool neat maintag])+ endenddescribe "Callbacks" do