Skip to content

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

DEV: Share the category and tag filter properties between workflow nodes

Régis Hanol844a65548585
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.rb
index 640706b625a..27da3b8c4bd 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,34 +22,8 @@ if defined?(DiscourseWorkflows)
},
],
properties: {
- category_ids: {
- type: :array,
- required: false,
- ui: {
- control: :category,
- multiple: true,
- },
- },
- include_subcategories: {
- type: :boolean,
- required: false,
- default: true,
- ui: {
- control: :checkbox,
- },
- display_options: {
- show: {
- category_ids: [{ condition: { exists: true } }],
- },
- },
- },
- tag_names: {
- type: :string,
- required: false,
- ui: {
- control: :tags,
- },
- },
+ **CATEGORY_FILTER_PROPERTIES,
+ **TAG_FILTER_PROPERTIES,
},
)
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/node_type.rb b/plugins/discourse-workflows/lib/discourse_workflows/node_type.rb
index ef634019b90..b622f4051b8 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/node_type.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/node_type.rb
@@ -7,6 +7,49 @@ module DiscourseWorkflows
TOPIC_TYPE_OPTIONS = %w[all topics personal_messages].freeze
+ TOPIC_TYPE_FILTER_PROPERTIES = {
+ topic_type: {
+ type: :options,
+ required: true,
+ default: "topics",
+ options: TOPIC_TYPE_OPTIONS,
+ },
+ }.freeze
+
+ CATEGORY_FILTER_PROPERTIES = {
+ category_ids: {
+ type: :array,
+ required: false,
+ ui: {
+ control: :category,
+ multiple: true,
+ },
+ },
+ include_subcategories: {
+ type: :boolean,
+ required: false,
+ default: true,
+ ui: {
+ control: :checkbox,
+ },
+ display_options: {
+ show: {
+ category_ids: [{ condition: { exists: true } }],
+ },
+ },
+ },
+ }.freeze
+
+ TAG_FILTER_PROPERTIES = {
+ tag_names: {
+ type: :string,
+ required: false,
+ ui: {
+ control: :tags,
+ },
+ },
+ }.freeze
+
DESCRIPTION_DEFAULTS = {
version: "1.0",
defaults: {
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_created/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_created/v1.rb
index 79462c15f15..6532e551d8e 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_created/v1.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_created/v1.rb
@@ -24,12 +24,7 @@ module DiscourseWorkflows
},
],
properties: {
- topic_type: {
- type: :options,
- required: true,
- default: "topics",
- options: TOPIC_TYPE_OPTIONS,
- },
+ **TOPIC_TYPE_FILTER_PROPERTIES,
group_inbox_id: {
type: :integer,
required: false,
@@ -51,34 +46,8 @@ module DiscourseWorkflows
none: "discourse_workflows.post_created.group_inbox_id_placeholder",
},
},
- category_ids: {
- type: :array,
- required: false,
- ui: {
- control: :category,
- multiple: true,
- },
- },
- include_subcategories: {
- type: :boolean,
- required: false,
- default: true,
- ui: {
- control: :checkbox,
- },
- display_options: {
- show: {
- category_ids: [{ condition: { exists: true } }],
- },
- },
- },
- tag_names: {
- type: :string,
- required: false,
- ui: {
- control: :tags,
- },
- },
+ **CATEGORY_FILTER_PROPERTIES,
+ **TAG_FILTER_PROPERTIES,
},
)
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_edited/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_edited/v1.rb
index ea82baab94e..5b00ca7281d 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_edited/v1.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_edited/v1.rb
@@ -32,34 +32,8 @@ module DiscourseWorkflows
default: "first_post",
options: POST_SCOPE_OPTIONS,
},
- category_ids: {
- type: :array,
- required: false,
- ui: {
- control: :category,
- multiple: true,
- },
- },
- include_subcategories: {
- type: :boolean,
- required: false,
- default: true,
- ui: {
- control: :checkbox,
- },
- display_options: {
- show: {
- category_ids: [{ condition: { exists: true } }],
- },
- },
- },
- tag_names: {
- type: :string,
- required: false,
- ui: {
- control: :tags,
- },
- },
+ **CATEGORY_FILTER_PROPERTIES,
+ **TAG_FILTER_PROPERTIES,
trust_levels: {
type: :multi_options,
required: false,
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_lifecycle.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_lifecycle.rb
index 12492458b36..74845167e3f 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_lifecycle.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_lifecycle.rb
@@ -5,40 +5,9 @@ module DiscourseWorkflows
module PostLifecycle
I18N_SCOPE = "post_lifecycle"
PROPERTIES = {
- topic_type: {
- type: :options,
- required: true,
- default: "topics",
- options: NodeType::TOPIC_TYPE_OPTIONS,
- },
- category_ids: {
- type: :array,
- required: false,
- ui: {
- control: :category,
- multiple: true,
- },
- },
- include_subcategories: {
- type: :boolean,
- required: false,
- default: true,
- ui: {
- control: :checkbox,
- },
- display_options: {
- show: {
- category_ids: [{ condition: { exists: true } }],
- },
- },
- },
- tag_names: {
- type: :string,
- required: false,
- ui: {
- control: :tags,
- },
- },
+ **NodeType::TOPIC_TYPE_FILTER_PROPERTIES,
+ **NodeType::CATEGORY_FILTER_PROPERTIES,
+ **NodeType::TAG_FILTER_PROPERTIES,
}.freeze
OUTPUT_CONTRACTS = [
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_moved/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_moved/v1.rb
index b8ac4bac9e0..0f4d94180cf 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_moved/v1.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_moved/v1.rb
@@ -29,34 +29,8 @@ module DiscourseWorkflows
event: :post_moved,
output_contracts: [{ schema: OUTPUT_SCHEMA }],
properties: {
- category_ids: {
- type: :array,
- required: false,
- ui: {
- control: :category,
- multiple: true,
- },
- },
- include_subcategories: {
- type: :boolean,
- required: false,
- default: true,
- ui: {
- control: :checkbox,
- },
- display_options: {
- show: {
- category_ids: [{ condition: { exists: true } }],
- },
- },
- },
- tag_names: {
- type: :string,
- required: false,
- ui: {
- control: :tags,
- },
- },
+ **CATEGORY_FILTER_PROPERTIES,
+ **TAG_FILTER_PROPERTIES,
},
)
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/stale_topic/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/stale_topic/v1.rb
index 4ac7042a95e..e35e0485af2 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/stale_topic/v1.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/stale_topic/v1.rb
@@ -20,34 +20,8 @@ module DiscourseWorkflows
default: 24,
min: 1,
},
- category_ids: {
- type: :array,
- required: false,
- ui: {
- control: :category,
- multiple: true,
- },
- },
- include_subcategories: {
- type: :boolean,
- required: false,
- default: true,
- ui: {
- control: :checkbox,
- },
- display_options: {
- show: {
- category_ids: [{ condition: { exists: true } }],
- },
- },
- },
- tag_names: {
- type: :string,
- required: false,
- ui: {
- control: :tags,
- },
- },
+ **CATEGORY_FILTER_PROPERTIES,
+ **TAG_FILTER_PROPERTIES,
},
capabilities: {
manually_triggerable: true,
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_closed/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_closed/v1.rb
index c31452a3794..7da1d81401c 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_closed/v1.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_closed/v1.rb
@@ -15,34 +15,8 @@ module DiscourseWorkflows
event: :topic_status_updated,
output_contracts: [{ schema: Schema::TOPIC_LIST_ITEM_SCHEMA }],
properties: {
- category_ids: {
- type: :array,
- required: false,
- ui: {
- control: :category,
- multiple: true,
- },
- },
- include_subcategories: {
- type: :boolean,
- required: false,
- default: true,
- ui: {
- control: :checkbox,
- },
- display_options: {
- show: {
- category_ids: [{ condition: { exists: true } }],
- },
- },
- },
- tag_names: {
- type: :string,
- required: false,
- ui: {
- control: :tags,
- },
- },
+ **CATEGORY_FILTER_PROPERTIES,
+ **TAG_FILTER_PROPERTIES,
},
)
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_created/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_created/v1.rb
index e307c47662d..8b6fda94693 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_created/v1.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_created/v1.rb
@@ -17,12 +17,7 @@ module DiscourseWorkflows
{ schema: Schema.merge(Schema::TOPIC_LIST_ITEM_SCHEMA, Schema::POST_SCHEMA) },
],
properties: {
- topic_type: {
- type: :options,
- required: true,
- default: "topics",
- options: TOPIC_TYPE_OPTIONS,
- },
+ **TOPIC_TYPE_FILTER_PROPERTIES,
group_inbox_id: {
type: :integer,
required: false,
@@ -44,34 +39,8 @@ module DiscourseWorkflows
none: "discourse_workflows.topic_created.group_inbox_id_placeholder",
},
},
- category_ids: {
- type: :array,
- required: false,
- ui: {
- control: :category,
- multiple: true,
- },
- },
- include_subcategories: {
- type: :boolean,
- required: false,
- default: true,
- ui: {
- control: :checkbox,
- },
- display_options: {
- show: {
- category_ids: [{ condition: { exists: true } }],
- },
- },
- },
- tag_names: {
- type: :string,
- required: false,
- ui: {
- control: :tags,
- },
- },
+ **CATEGORY_FILTER_PROPERTIES,
+ **TAG_FILTER_PROPERTIES,
},
)
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_tag_changed/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_tag_changed/v1.rb
index 61414e3abd3..322834a7b4b 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_tag_changed/v1.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_tag_changed/v1.rb
@@ -27,27 +27,7 @@ module DiscourseWorkflows
event: :topic_tags_changed,
output_contracts: [{ schema: OUTPUT_SCHEMA }],
properties: {
- category_ids: {
- type: :array,
- required: false,
- ui: {
- control: :category,
- multiple: true,
- },
- },
- include_subcategories: {
- type: :boolean,
- required: false,
- default: true,
- ui: {
- control: :checkbox,
- },
- display_options: {
- show: {
- category_ids: [{ condition: { exists: true } }],
- },
- },
- },
+ **CATEGORY_FILTER_PROPERTIES,
},
)