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.
This commit is contained in:
Joffrey JAFFEUX 2024-09-05 11:18:26 +02:00 committed by GitHub
parent dc1afeac89
commit 1a96269be0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 0 deletions

View File

@ -230,6 +230,10 @@ module DiscourseAutomation
"topic" => topic, "topic" => topic,
"removed_tags" => removed_tags, "removed_tags" => removed_tags,
"added_tags" => added_tags, "added_tags" => added_tags,
"placeholders" => {
"topic_url" => topic.relative_url,
"topic_title" => topic.title,
},
) )
end end
end end

View File

@ -3,4 +3,7 @@
DiscourseAutomation::Triggerable.add(DiscourseAutomation::Triggers::TOPIC_TAGS_CHANGED) do DiscourseAutomation::Triggerable.add(DiscourseAutomation::Triggers::TOPIC_TAGS_CHANGED) do
field :watching_categories, component: :categories field :watching_categories, component: :categories
field :watching_tags, component: :tags field :watching_tags, component: :tags
placeholder :topic_url
placeholder :topic_title
end end

View File

@ -32,6 +32,19 @@ describe DiscourseAutomation::Triggers::TOPIC_TAGS_CHANGED do
automation.reload automation.reload
end 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 it "should fire the trigger if the tag is added" do
topic_0 = Fabricate(:topic, user: user, tags: [], category: category) topic_0 = Fabricate(:topic, user: user, tags: [], category: category)