FIX: Message triggering on topic creation (#222)

before topic tags changes trigger would fire on topic creation, now it only fires on tags changes
This commit is contained in:
Gabriel Grubba 2024-10-07 21:07:35 +02:00 committed by GitHub
parent aaa2da6111
commit c72c01e955
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 0 deletions

View File

@ -103,6 +103,10 @@ after_initialize do
triggerables %i[topic_tags_changed] triggerables %i[topic_tags_changed]
script do |context, fields, automation| 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") provider = fields.dig("provider", "value")
channel_name = fields.dig("channel_name", "value") channel_name = fields.dig("channel_name", "value")

View File

@ -7,6 +7,7 @@ RSpec.describe "Triggering notifications" do
fab!(:admin) fab!(:admin)
fab!(:category) fab!(:category)
fab!(:tag) fab!(:tag)
let(:valid_attrs) { Fabricate.attributes_for(:topic) }
fab!(:automation) do fab!(:automation) do
Fabricate( Fabricate(
@ -74,5 +75,14 @@ RSpec.describe "Triggering notifications" do
expect(validated_provider.sent_messages.length).to eq(0) expect(validated_provider.sent_messages.length).to eq(0)
end 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
end end