FEATURE: Post created/edited trigger can skip posts created via email (#28615)

This commit is contained in:
Roman Rizzi 2024-08-28 17:34:35 -03:00 committed by GitHub
parent 6f91014d64
commit 715f49c3fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 44 additions and 0 deletions

View File

@ -162,6 +162,9 @@ en:
first_topic_only:
label: First topic only
description: Will trigger only if the topic is the first topic a user created
skip_via_email:
label: "Skip via email"
description: "Skip the trigger if the post was created via email"
created: Created
edited: Edited
user_updated:

View File

@ -23,6 +23,11 @@ module DiscourseAutomation
next if post.user.user_stat.topic_count != 1
end
skip_via_email = automation.trigger_field("skip_via_email")
if skip_via_email["value"]
next if post.via_email?
end
valid_trust_levels = automation.trigger_field("valid_trust_levels")
if valid_trust_levels["value"]
next if valid_trust_levels["value"].exclude?(post.user.trust_level)

View File

@ -19,4 +19,5 @@ DiscourseAutomation::Triggerable.add(DiscourseAutomation::Triggers::POST_CREATED
field :valid_trust_levels, component: :"trust-levels"
field :first_post_only, component: :boolean
field :first_topic_only, component: :boolean
field :skip_via_email, component: :boolean
end

View File

@ -74,6 +74,41 @@ describe "PostCreatedEdited" do
end
end
context "when skipping posts created via email" do
before do
automation.upsert_field!("skip_via_email", "boolean", { value: true }, target: "trigger")
end
let(:parent_post) { create_post(title: "hello world topic", raw: "my name is fred") }
it "fires if the post didn't come via email" do
topic = parent_post.topic
list =
capture_contexts do
PostCreator.create!(user, raw: "this is a test reply", topic_id: topic.id)
end
expect(list.length).to eq(1)
end
it "skips the trigger if the post came via email" do
topic = parent_post.topic
list =
capture_contexts do
PostCreator.create!(
user,
raw: "this is a test reply",
topic_id: topic.id,
via_email: true,
)
end
expect(list.length).to eq(0)
end
end
context "when editing/creating a post" do
it "fires the trigger" do
post = nil