mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:23:25 +08:00
FEATURE: Post created/edited trigger can skip posts created via email (#28615)
This commit is contained in:
parent
6f91014d64
commit
715f49c3fe
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user