From c72c01e955e8b05dc394a7e98f7fc7a27c3c0614 Mon Sep 17 00:00:00 2001 From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com> Date: Mon, 7 Oct 2024 21:07:35 +0200 Subject: [PATCH] FIX: Message triggering on topic creation (#222) before topic tags changes trigger would fire on topic creation, now it only fires on tags changes --- plugin.rb | 4 ++++ spec/integration/automation_spec.rb | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/plugin.rb b/plugin.rb index d7a0e37..c8a466e 100644 --- a/plugin.rb +++ b/plugin.rb @@ -103,6 +103,10 @@ after_initialize do triggerables %i[topic_tags_changed] script do |context, fields, automation| + # DiscourseTagging.tag_topic_by_names runs on topic creation and on tags change + # we only want to send a message when tags change + next if context["topic"].new_record? + provider = fields.dig("provider", "value") channel_name = fields.dig("channel_name", "value") diff --git a/spec/integration/automation_spec.rb b/spec/integration/automation_spec.rb index 8ba4c75..081de47 100644 --- a/spec/integration/automation_spec.rb +++ b/spec/integration/automation_spec.rb @@ -7,6 +7,7 @@ RSpec.describe "Triggering notifications" do fab!(:admin) fab!(:category) fab!(:tag) + let(:valid_attrs) { Fabricate.attributes_for(:topic) } fab!(:automation) do Fabricate( @@ -74,5 +75,14 @@ RSpec.describe "Triggering notifications" do expect(validated_provider.sent_messages.length).to eq(0) end + + it "should not trigger a provider notification on topic creation for topic_tags_changed script" do + TopicCreator.create( + admin, + Guardian.new(admin), + valid_attrs.merge(tags: [tag.name], category: category.id), + ) + expect(validated_provider.sent_messages.length).to eq(0) + end end end