From 1a96269be0c71575233fe2a5d0ec87dfdbf6b6a8 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 5 Sep 2024 11:18:26 +0200 Subject: [PATCH] DEV: adds topic_url/topic_title placeholders (#28754) `topic_tags_changed` trigger now fills the {{topic_url}} and {{topic_title}} placeholders. `topic_url` is the relative URL. --- .../lib/discourse_automation/event_handlers.rb | 4 ++++ .../triggers/topic_tags_changed.rb | 3 +++ .../spec/triggers/topic_tags_changed_spec.rb | 13 +++++++++++++ 3 files changed, 20 insertions(+) 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)