FIX: Automation should not fire on PMS

automation on topic tags should not fire on PMS
This commit is contained in:
Gabriel Grubba 2024-10-07 16:49:01 -03:00
parent c72c01e955
commit e906290311
No known key found for this signature in database
GPG Key ID: 5FE41764F62D556C
2 changed files with 23 additions and 0 deletions

View File

@ -103,6 +103,8 @@ after_initialize do
triggerables %i[topic_tags_changed]
script do |context, fields, automation|
next if context["topic"].private_message?
# 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?

View File

@ -29,6 +29,8 @@ RSpec.describe "Triggering notifications" do
SiteSetting.create_tag_allowed_groups = Group::AUTO_GROUPS[:everyone]
SiteSetting.tag_topic_allowed_groups = Group::AUTO_GROUPS[:everyone]
SiteSetting.pm_tags_allowed_for_groups = Group::AUTO_GROUPS[:everyone]
automation.upsert_field!(
"watching_categories",
"categories",
@ -84,5 +86,24 @@ RSpec.describe "Triggering notifications" do
)
expect(validated_provider.sent_messages.length).to eq(0)
end
it "should not trigger notifications for PMs" do
automation.upsert_field!(
"watching_categories",
"categories",
{ "value" => [nil] },
target: "trigger",
)
topic =
TopicCreator.create(
admin,
Guardian.new(admin),
valid_attrs.merge(archetype: Archetype.private_message, target_usernames: admin.username),
)
DiscourseTagging.tag_topic_by_names(topic, Guardian.new(admin), [tag.name])
expect(validated_provider.sent_messages.length).to eq(0)
end
end
end