A platform for community discussion. Free, open, simple.
FEATURE: Post created/edited trigger can skip posts created via email (#28615)
Roman Rizzi715f49c3fe2d
diff --git a/plugins/automation/config/locales/client.en.yml b/plugins/automation/config/locales/client.en.ymlindex aad7493d020..907b4f59510 100644--- a/plugins/automation/config/locales/client.en.yml+++ b/plugins/automation/config/locales/client.en.yml@@ -162,6 +162,9 @@ en:first_topic_only:label: First topic onlydescription: 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: Creatededited: Editeduser_updated:diff --git a/plugins/automation/lib/discourse_automation/event_handlers.rb b/plugins/automation/lib/discourse_automation/event_handlers.rbindex 4926e1f0271..554a75a0adc 100644--- a/plugins/automation/lib/discourse_automation/event_handlers.rb+++ b/plugins/automation/lib/discourse_automation/event_handlers.rb@@ -23,6 +23,11 @@ module DiscourseAutomationnext if post.user.user_stat.topic_count != 1end+ 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)diff --git a/plugins/automation/lib/discourse_automation/triggers/post_created_edited.rb b/plugins/automation/lib/discourse_automation/triggers/post_created_edited.rbindex fa0f38e15d6..bb697c07357 100644--- a/plugins/automation/lib/discourse_automation/triggers/post_created_edited.rb+++ b/plugins/automation/lib/discourse_automation/triggers/post_created_edited.rb@@ -19,4 +19,5 @@ DiscourseAutomation::Triggerable.add(DiscourseAutomation::Triggers::POST_CREATEDfield :valid_trust_levels, component: :"trust-levels"field :first_post_only, component: :booleanfield :first_topic_only, component: :boolean+ field :skip_via_email, component: :booleanenddiff --git a/plugins/automation/spec/triggers/post_created_edited_spec.rb b/plugins/automation/spec/triggers/post_created_edited_spec.rbindex 66960ec3f34..ea7d0a07f6b 100644--- a/plugins/automation/spec/triggers/post_created_edited_spec.rb+++ b/plugins/automation/spec/triggers/post_created_edited_spec.rb@@ -74,6 +74,41 @@ describe "PostCreatedEdited" doendend+ 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" doit "fires the trigger" dopost = nil