Skip to content

A platform for community discussion. Free, open, simple.

DEV: adds topic_url/topic_title placeholders (#28754)

Joffrey JAFFEUX1a96269be0c7
diff --git a/plugins/automation/lib/discourse_automation/event_handlers.rb b/plugins/automation/lib/discourse_automation/event_handlers.rb
index edcc821ac3b..d03d803d868 100644
--- a/plugins/automation/lib/discourse_automation/event_handlers.rb
+++ b/plugins/automation/lib/discourse_automation/event_handlers.rb
@@ -230,6 +230,10 @@ module DiscourseAutomation
"topic" => topic,
"removed_tags" => removed_tags,
"added_tags" => added_tags,
+ "placeholders" => {
+ "topic_url" => topic.relative_url,
+ "topic_title" => topic.title,
+ },
)
end
end
diff --git a/plugins/automation/lib/discourse_automation/triggers/topic_tags_changed.rb b/plugins/automation/lib/discourse_automation/triggers/topic_tags_changed.rb
index d316573726f..8ee5ba5cc98 100644
--- a/plugins/automation/lib/discourse_automation/triggers/topic_tags_changed.rb
+++ b/plugins/automation/lib/discourse_automation/triggers/topic_tags_changed.rb
@@ -3,4 +3,7 @@
DiscourseAutomation::Triggerable.add(DiscourseAutomation::Triggers::TOPIC_TAGS_CHANGED) do
field :watching_categories, component: :categories
field :watching_tags, component: :tags
+
+ placeholder :topic_url
+ placeholder :topic_title
end
diff --git a/plugins/automation/spec/triggers/topic_tags_changed_spec.rb b/plugins/automation/spec/triggers/topic_tags_changed_spec.rb
index 07c34a8dbdd..1f0133eab22 100644
--- a/plugins/automation/spec/triggers/topic_tags_changed_spec.rb
+++ b/plugins/automation/spec/triggers/topic_tags_changed_spec.rb
@@ -32,6 +32,19 @@ describe DiscourseAutomation::Triggers::TOPIC_TAGS_CHANGED do
automation.reload
end
+ it "fills placeholders correctly" do
+ topic_0 = Fabricate(:topic, user: user, tags: [], category: category)
+
+ list =
+ capture_contexts do
+ DiscourseTagging.tag_topic_by_names(topic_0, Guardian.new(user), [cool_tag.name])
+ end
+
+ expect(list[0]["placeholders"]).to eq(
+ { "topic_title" => topic_0.title, "topic_url" => topic_0.relative_url },
+ )
+ end
+
it "should fire the trigger if the tag is added" do
topic_0 = Fabricate(:topic, user: user, tags: [], category: category)