mirror of
https://github.com/discourse/discourse.git
synced 2026-08-04 10:23:17 -05:00
FEATURE: add the ability to add tagging automation on topic closed (#38134)
Topic closed target is (obviously) a topic. Auto tag topic currently targets a (first) post's topic. Adds support to also pass a topic directly to auto_tag_topic automation. In turn, allows adding `topic_closed` triggerable to the auto_tag_topic automation.
This commit is contained in:
@@ -5,14 +5,19 @@ DiscourseAutomation::Scriptable.add(DiscourseAutomation::Scripts::AUTO_TAG_TOPIC
|
||||
|
||||
version 1
|
||||
|
||||
triggerables %i[post_created_edited pm_created]
|
||||
triggerables %i[post_created_edited pm_created topic_closed]
|
||||
|
||||
script do |context, fields|
|
||||
post = context["post"]
|
||||
topic = nil
|
||||
if context["topic"]
|
||||
topic = context["topic"]
|
||||
else
|
||||
post = context["post"]
|
||||
|
||||
next if !post.is_first_post?
|
||||
next if !post.topic
|
||||
next unless topic = Topic.find_by(id: post.topic.id)
|
||||
next if !post.is_first_post?
|
||||
next if !post.topic
|
||||
next unless topic = Topic.find_by(id: post.topic.id)
|
||||
end
|
||||
|
||||
tags = fields.dig("tags", "value")
|
||||
|
||||
|
||||
@@ -75,4 +75,22 @@ describe "AutoTagTopic" do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with a topic" do
|
||||
context "when tags list is empty" do
|
||||
it "exits early with no error" do
|
||||
expect { automation.trigger!("topic" => topic) }.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context "when there are tags" do
|
||||
before { automation.upsert_field!("tags", "tags", { value: %w[tag1 tag2] }) }
|
||||
|
||||
it "works" do
|
||||
automation.trigger!("topic" => topic)
|
||||
|
||||
expect(topic.reload.tags.pluck(:name)).to match_array(%w[tag1 tag2])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user