Skip to content

A platform for community discussion. Free, open, simple.

DEV: Share the "changes" filter between workflow triggers

Régis Hanolc7d985f71bd5
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.rb
index 1128123f40c..92f73063f07 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
@@ -62,11 +62,7 @@ if defined?(DiscourseWorkflows)
end
def matches?(trigger_ctx)
- changes =
- Array.wrap(trigger_ctx.get_node_parameter("changes", [])).compact_blank.map(&:to_s)
- return false if changes.present? && changes.exclude?(@change)
-
- matches_topic_filters?(topic, trigger_ctx)
+ matches_changes?(trigger_ctx, @change) && matches_topic_filters?(topic, trigger_ctx)
end
private
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.rb
index 997e868dd74..8bc604a3198 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
@@ -76,8 +76,4 @@ RSpec.describe DiscourseWorkflows::Nodes::SolutionChanged::V1, discourse_workflo
expect(DiscourseWorkflows::Registry.find_node_type(described_class.identifier)).to be_nil
end
end
-
- def trigger_context(parameters)
- DiscourseWorkflows::TriggerNodeContext.new({ "parameters" => parameters.deep_stringify_keys })
- end
end
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/node_type.rb b/plugins/discourse-workflows/lib/discourse_workflows/node_type.rb
index 19d2c9ba11d..498caed42ff 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/node_type.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/node_type.rb
@@ -401,6 +401,11 @@ module DiscourseWorkflows
self.class.category_ids_parameter(trigger_ctx)
end
+ def matches_changes?(trigger_ctx, change)
+ changes = Array.wrap(trigger_ctx.get_node_parameter("changes", [])).compact_blank.map(&:to_s)
+ changes.empty? || changes.include?(change)
+ end
+
def matches_topic_filters?(topic, trigger_ctx)
matches_category_ids?(
topic.category_id,
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_timer_changed/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_timer_changed/v1.rb
index cce0e7c484e..27ab6d805d1 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_timer_changed/v1.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_timer_changed/v1.rb
@@ -101,8 +101,7 @@ module DiscourseWorkflows
end
def matches?(trigger_ctx)
- changes = Array.wrap(trigger_ctx.get_node_parameter("changes", []))
- return false if changes.present? && !changes.include?(@change)
+ return false if !matches_changes?(trigger_ctx, @change)
types = Array.wrap(trigger_ctx.get_node_parameter("timer_types", []))
timer_types =
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/user_moderation_changed/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/user_moderation_changed/v1.rb
index 9322d74dc19..bd51b2e2a01 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/user_moderation_changed/v1.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/user_moderation_changed/v1.rb
@@ -95,9 +95,7 @@ module DiscourseWorkflows
end
def matches?(trigger_ctx)
- changes =
- Array.wrap(trigger_ctx.get_node_parameter("changes", [])).compact_blank.map(&:to_s)
- changes.empty? || changes.include?(@change)
+ matches_changes?(trigger_ctx, @change)
end
end
end
diff --git a/plugins/discourse-workflows/spec/support/node_execution_helpers.rb b/plugins/discourse-workflows/spec/support/node_execution_helpers.rb
index 6129d4a0085..8ad711e9d5b 100644
--- a/plugins/discourse-workflows/spec/support/node_execution_helpers.rb
+++ b/plugins/discourse-workflows/spec/support/node_execution_helpers.rb
@@ -53,6 +53,10 @@ module NodeExecutionHelpers
result = execute_node_output(configuration: configuration, item: item, workflow: workflow)
result.first.first["json"]
end
+
+ def trigger_context(parameters)
+ DiscourseWorkflows::TriggerNodeContext.new({ "parameters" => parameters.deep_stringify_keys })
+ end
end
RSpec.configure { |config| config.include NodeExecutionHelpers }