Skip to content

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

FIX: ensures global notices are destroyed on post created (#28684)

Joffrey JAFFEUX0a1432e1cc86
diff --git a/plugins/automation/lib/discourse_automation/event_handlers.rb b/plugins/automation/lib/discourse_automation/event_handlers.rb
index 554a75a0adc..edcc821ac3b 100644
--- a/plugins/automation/lib/discourse_automation/event_handlers.rb
+++ b/plugins/automation/lib/discourse_automation/event_handlers.rb
@@ -330,7 +330,7 @@ module DiscourseAutomation
next if categories && !categories.include?(post.topic.category_id)
tags = fields.dig("tags", "value")
- next if tags && (tags & post.topic.tags.map(&:name)).empty?
+ next if tags&.any? && (tags & post.topic.tags.map(&:name)).empty?
DiscourseAutomation::UserGlobalNotice
.where(identifier: automation.id)
diff --git a/plugins/automation/spec/fabricators/user_global_notice_fabricator.rb b/plugins/automation/spec/fabricators/user_global_notice_fabricator.rb
new file mode 100644
index 00000000000..a495d30baaf
--- /dev/null
+++ b/plugins/automation/spec/fabricators/user_global_notice_fabricator.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+Fabricator(:user_global_notice, from: DiscourseAutomation::UserGlobalNotice) do
+ user_id { Fabricate(:user).id }
+ notice "This is an important notice"
+ level "info"
+ identifier "foo"
+end
diff --git a/plugins/automation/spec/lib/discourse_automation/event_handlers_spec.rb b/plugins/automation/spec/lib/discourse_automation/event_handlers_spec.rb
new file mode 100644
index 00000000000..71d7771e0de
--- /dev/null
+++ b/plugins/automation/spec/lib/discourse_automation/event_handlers_spec.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+describe DiscourseAutomation::EventHandlers do
+ describe "#handle_stalled_topic" do
+ context "when tags are empty" do
+ fab!(:automation) do
+ Fabricate(:automation, trigger: DiscourseAutomation::Triggers::STALLED_TOPIC, enabled: true)
+ end
+ fab!(:user)
+ fab!(:post) { Fabricate(:post, user: user) }
+
+ before do
+ automation.upsert_field!("tags", "tags", { value: [] }, target: "trigger")
+ Fabricate(:user_global_notice, identifier: automation.id, user_id: user.id)
+ end
+
+ it "destroys notices" do
+ expect { DiscourseAutomation::EventHandlers.handle_stalled_topic(post) }.to change {
+ DiscourseAutomation::UserGlobalNotice.count
+ }.by(-1)
+ end
+ end
+ end
+end