mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 22:21:55 +08:00
FIX: ensures global notices are destroyed on post created (#28684)
Prior to this fix we could exit early if tags was `[]` as `tags && (tags & post.topic.tags.map(&:name)).empty?` would have returned true. This commit ensures it's not the case anymore and adds a test for it. Co-Authored-By: Martin Brennan <mjrbrennan@gmail.com>
This commit is contained in:
parent
b771d3173f
commit
0a1432e1cc
|
@ -330,7 +330,7 @@ module DiscourseAutomation
|
||||||
next if categories && !categories.include?(post.topic.category_id)
|
next if categories && !categories.include?(post.topic.category_id)
|
||||||
|
|
||||||
tags = fields.dig("tags", "value")
|
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
|
DiscourseAutomation::UserGlobalNotice
|
||||||
.where(identifier: automation.id)
|
.where(identifier: automation.id)
|
||||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue
Block a user