mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 05:52:18 +00:00
FIX: Process tag synonyms when approving reviewable queued post (#30810)
Followup 72c4709a5ab26f00e32b65d874b3a206d679181e Previously we made a fix to allow skip validations when tagging a topic via TopicCreator. However, this flow also skips a lot of the more in-depth work on tags we do when creating a topic, like processing tag synonyms. When approving reviewable queued posts, we skip validations, so this would cause an issue where a topic was approved and the tag synonyms weren't applied. This commit changes the logic so we attempt the more complete `DiscourseTagging.tag_topic_by_names` call first and if this fails and skip validations is on, then we do `DiscourseTagging.add_or_create_tags_by_name`. This at least gives a chance for the full workflow to work first.
This commit is contained in:
parent
99f5670c30
commit
35507d4090
@ -192,11 +192,14 @@ class TopicCreator
|
|||||||
|
|
||||||
def setup_tags(topic)
|
def setup_tags(topic)
|
||||||
if @opts[:tags].present?
|
if @opts[:tags].present?
|
||||||
if @opts[:skip_validations]
|
# We can try the full tagging workflow which does validations and other
|
||||||
DiscourseTagging.add_or_create_tags_by_name(topic, @opts[:tags])
|
# things like replacing synonyms first, but if this fails then we can try
|
||||||
else
|
# the simple workflow if validations are skipped.
|
||||||
valid_tags = DiscourseTagging.tag_topic_by_names(topic, @guardian, @opts[:tags])
|
valid_tags = DiscourseTagging.tag_topic_by_names(topic, @guardian, @opts[:tags])
|
||||||
unless valid_tags
|
if !valid_tags
|
||||||
|
if @opts[:skip_validations]
|
||||||
|
DiscourseTagging.add_or_create_tags_by_name(topic, @opts[:tags])
|
||||||
|
else
|
||||||
topic.errors.add(:base, :unable_to_tag)
|
topic.errors.add(:base, :unable_to_tag)
|
||||||
rollback_from_errors!(topic)
|
rollback_from_errors!(topic)
|
||||||
end
|
end
|
||||||
|
@ -320,6 +320,16 @@ RSpec.describe ReviewableQueuedPost, type: :model do
|
|||||||
expect(Topic.count).to eq(topic_count)
|
expect(Topic.count).to eq(topic_count)
|
||||||
expect(Post.count).to eq(post_count)
|
expect(Post.count).to eq(post_count)
|
||||||
end
|
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])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Callbacks" do
|
describe "Callbacks" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user