A platform for community discussion. Free, open, simple.
FEATURE: Let reaction, solution and vote workflow triggers filter by topic
Régis Hanolf375bf87c9e8
diff --git a/plugins/discourse-reactions/lib/discourse_workflows/nodes/post_reaction_changed/v1.rb b/plugins/discourse-reactions/lib/discourse_workflows/nodes/post_reaction_changed/v1.rbindex 065f0d9d37c..e9b93d57433 100644--- a/plugins/discourse-reactions/lib/discourse_workflows/nodes/post_reaction_changed/v1.rb+++ b/plugins/discourse-reactions/lib/discourse_workflows/nodes/post_reaction_changed/v1.rb@@ -50,8 +50,7 @@ if defined?(DiscourseWorkflows)required: false,no_data_expression: true,},- **CATEGORY_FILTER_PROPERTIES,- **TAG_FILTER_PROPERTIES,+ **TOPIC_SCOPE_FILTER_PROPERTIES,},)@@ -84,9 +83,10 @@ if defined?(DiscourseWorkflows)def matches?(trigger_ctx)filter = trigger_ctx.get_node_parameter("reaction").to_s.delete(":").presence- matches_changes?(trigger_ctx, change) &&- (filter.nil? || [reaction, @previous_reaction].include?(filter)) &&- matches_topic_filters?(@post.topic, trigger_ctx)+ return false if !matches_changes?(trigger_ctx, change)+ return false if filter && [reaction, @previous_reaction].exclude?(filter)++ matches_topic_filters?(@post.topic, trigger_ctx)endprivatediff --git a/plugins/discourse-reactions/spec/lib/discourse_workflows/nodes/post_reaction_changed_spec.rb b/plugins/discourse-reactions/spec/lib/discourse_workflows/nodes/post_reaction_changed_spec.rbindex 46bb5002155..801cd950125 100644--- a/plugins/discourse-reactions/spec/lib/discourse_workflows/nodes/post_reaction_changed_spec.rb+++ b/plugins/discourse-reactions/spec/lib/discourse_workflows/nodes/post_reaction_changed_spec.rb@@ -19,7 +19,7 @@ RSpec.describe DiscourseWorkflows::Nodes::PostReactionChanged::V1, discourse_worenddescribe "#matches?" do- it "filters changes, reactions, categories, and tags" do+ it "filters changes, reactions, categories, tags, and topics" doSiteSetting.tagging_enabled = truetopic.tags << tagreact("hugs")@@ -30,10 +30,12 @@ RSpec.describe DiscourseWorkflows::Nodes::PostReactionChanged::V1, discourse_worexpect(trigger.matches?(trigger_context(reaction: "clap"))).to eq(false)expect(trigger.matches?(trigger_context(category_ids: [other_category.id]))).to eq(false)expect(trigger.matches?(trigger_context(tag_names: ["missing"]))).to eq(false)+ expect(trigger.matches?(trigger_context(topic_ids: [topic.id + 1]))).to eq(false)expect(trigger.matches?(trigger_context(changes: ["replaced"],+ topic_ids: [topic.id],reaction: ":laughing:",category_ids: [category.id],tag_names: [tag.name],diff --git a/plugins/discourse-solved/lib/discourse_workflows/nodes/solution_changed/v1.rb b/plugins/discourse-solved/lib/discourse_workflows/nodes/solution_changed/v1.rbindex 92f73063f07..7a8bd0684d0 100644--- a/plugins/discourse-solved/lib/discourse_workflows/nodes/solution_changed/v1.rb+++ b/plugins/discourse-solved/lib/discourse_workflows/nodes/solution_changed/v1.rb@@ -38,8 +38,7 @@ if defined?(DiscourseWorkflows)default: [],options: CHANGES.values,},- **CATEGORY_FILTER_PROPERTIES,- **TAG_FILTER_PROPERTIES,+ **TOPIC_SCOPE_FILTER_PROPERTIES,},)diff --git a/plugins/discourse-solved/spec/lib/discourse_workflows/nodes/solution_changed_spec.rb b/plugins/discourse-solved/spec/lib/discourse_workflows/nodes/solution_changed_spec.rbindex 8bc604a3198..e6f5a33634f 100644--- a/plugins/discourse-solved/spec/lib/discourse_workflows/nodes/solution_changed_spec.rb+++ b/plugins/discourse-solved/spec/lib/discourse_workflows/nodes/solution_changed_spec.rb@@ -15,7 +15,7 @@ RSpec.describe DiscourseWorkflows::Nodes::SolutionChanged::V1, discourse_workfloenddescribe "#matches?" do- it "filters changes, categories, and tags" do+ it "filters changes, categories, tags, and topics" dopost.topic.tags << tagtrigger = described_class.from_event(:accepted_solution, post)@@ -23,10 +23,12 @@ RSpec.describe DiscourseWorkflows::Nodes::SolutionChanged::V1, discourse_workfloexpect(trigger.matches?(trigger_context(changes: ["removed"]))).to eq(false)expect(trigger.matches?(trigger_context(category_ids: [other_category.id]))).to eq(false)expect(trigger.matches?(trigger_context(tag_names: ["missing"]))).to eq(false)+ expect(trigger.matches?(trigger_context(topic_ids: [topic.id + 1]))).to eq(false)expect(trigger.matches?(trigger_context(changes: ["accepted"],+ topic_ids: [topic.id],category_ids: [category.id],tag_names: [tag.name],),diff --git a/plugins/discourse-topic-voting/lib/discourse_workflows/nodes/topic_received_vote/v1.rb b/plugins/discourse-topic-voting/lib/discourse_workflows/nodes/topic_received_vote/v1.rbindex 27da3b8c4bd..ac92748eb39 100644--- a/plugins/discourse-topic-voting/lib/discourse_workflows/nodes/topic_received_vote/v1.rb+++ b/plugins/discourse-topic-voting/lib/discourse_workflows/nodes/topic_received_vote/v1.rb@@ -22,8 +22,7 @@ if defined?(DiscourseWorkflows)},],properties: {- **CATEGORY_FILTER_PROPERTIES,- **TAG_FILTER_PROPERTIES,+ **TOPIC_SCOPE_FILTER_PROPERTIES,},)@@ -49,12 +48,7 @@ if defined?(DiscourseWorkflows)enddef matches?(trigger_ctx)- matches_category_ids?(- topic.category_id,- category_ids_parameter(trigger_ctx),- include_subcategories: trigger_ctx.get_node_parameter("include_subcategories", true),- ) &&- matches_tags?(topic, normalize_tag_names(trigger_ctx.get_node_parameter("tag_names")))+ matches_topic_filters?(topic, trigger_ctx)endprivatediff --git a/plugins/discourse-topic-voting/spec/lib/discourse_workflows/nodes/topic_received_vote/v1_spec.rb b/plugins/discourse-topic-voting/spec/lib/discourse_workflows/nodes/topic_received_vote/v1_spec.rbindex 63d7052b7a3..a67d643e6dc 100644--- a/plugins/discourse-topic-voting/spec/lib/discourse_workflows/nodes/topic_received_vote/v1_spec.rb+++ b/plugins/discourse-topic-voting/spec/lib/discourse_workflows/nodes/topic_received_vote/v1_spec.rb@@ -45,6 +45,12 @@ RSpec.describe DiscourseWorkflows::Nodes::TopicReceivedVote::V1 doexpect(described_class.new(vote).matches?(trigger_context({}))).to eq(true)end+ it "matches only votes on the selected topics" do+ expect(+ described_class.new(vote).matches?(trigger_context("topic_ids" => [topic.id + 1])),+ ).to eq(false)+ end+it "matches only votes on topics in the selected categories" doother_category = Fabricate(:category)@@ -79,8 +85,4 @@ RSpec.describe DiscourseWorkflows::Nodes::TopicReceivedVote::V1 do)endend-- def trigger_context(parameters)- DiscourseWorkflows::TriggerNodeContext.new({ "parameters" => parameters })- endend