mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FEATURE: Post created/edited trigger can skip posts created via email (#28615)
This commit is contained in:
@ -162,6 +162,9 @@ en:
|
|||||||
first_topic_only:
|
first_topic_only:
|
||||||
label: First topic only
|
label: First topic only
|
||||||
description: Will trigger only if the topic is the first topic a user created
|
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
|
created: Created
|
||||||
edited: Edited
|
edited: Edited
|
||||||
user_updated:
|
user_updated:
|
||||||
|
@ -23,6 +23,11 @@ module DiscourseAutomation
|
|||||||
next if post.user.user_stat.topic_count != 1
|
next if post.user.user_stat.topic_count != 1
|
||||||
end
|
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")
|
valid_trust_levels = automation.trigger_field("valid_trust_levels")
|
||||||
if valid_trust_levels["value"]
|
if valid_trust_levels["value"]
|
||||||
next if valid_trust_levels["value"].exclude?(post.user.trust_level)
|
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 :valid_trust_levels, component: :"trust-levels"
|
||||||
field :first_post_only, component: :boolean
|
field :first_post_only, component: :boolean
|
||||||
field :first_topic_only, component: :boolean
|
field :first_topic_only, component: :boolean
|
||||||
|
field :skip_via_email, component: :boolean
|
||||||
end
|
end
|
||||||
|
@ -74,6 +74,41 @@ describe "PostCreatedEdited" do
|
|||||||
end
|
end
|
||||||
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
|
context "when editing/creating a post" do
|
||||||
it "fires the trigger" do
|
it "fires the trigger" do
|
||||||
post = nil
|
post = nil
|
||||||
|
Reference in New Issue
Block a user