mirror of
https://github.com/discourse/discourse.git
synced 2025-06-22 11:21:54 +08:00
FEATURE: improve post_created_edited automation triggers (#31694)
- Allow deciding if we include or exclude sub categories - Allow filtering to only look at PMs or Topics - Allow selection of multiple categories - Migrations to carry all data into new structure --------- Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
This commit is contained in:
@ -12,6 +12,12 @@ module DiscourseAutomation
|
||||
DiscourseAutomation::Automation
|
||||
.where(trigger: name, enabled: true)
|
||||
.find_each do |automation|
|
||||
restricted_archetype = automation.trigger_field("restricted_archetype")["value"]
|
||||
if restricted_archetype.present?
|
||||
topic_archetype = topic.archetype
|
||||
next if restricted_archetype != topic_archetype
|
||||
end
|
||||
|
||||
original_post_only = automation.trigger_field("original_post_only")
|
||||
if original_post_only["value"]
|
||||
next if topic.posts_count > 1
|
||||
@ -38,15 +44,21 @@ module DiscourseAutomation
|
||||
next if valid_trust_levels["value"].exclude?(post.user.trust_level)
|
||||
end
|
||||
|
||||
restricted_category = automation.trigger_field("restricted_category")
|
||||
if restricted_category["value"]
|
||||
category_ids =
|
||||
if topic.category_id.blank?
|
||||
[]
|
||||
else
|
||||
[topic.category_id, topic.category.parent_category_id]
|
||||
end
|
||||
next if !category_ids.include?(restricted_category["value"])
|
||||
restricted_categories = automation.trigger_field("restricted_categories").dup
|
||||
if restricted_category_ids = restricted_categories["value"]
|
||||
exclude_subcategories = automation.trigger_field("exclude_subcategories")["value"]
|
||||
|
||||
if !exclude_subcategories
|
||||
# core api is odd, we only support nesting of 3 anyway, this is efficient
|
||||
restricted_category_ids = restricted_category_ids.to_set
|
||||
# for nesting of 3
|
||||
restricted_category_ids +=
|
||||
Category.where(parent_category_id: restricted_category_ids).pluck(:id)
|
||||
restricted_category_ids +=
|
||||
Category.where(parent_category_id: restricted_category_ids).pluck(:id)
|
||||
end
|
||||
|
||||
next if !restricted_category_ids.include?(topic.category_id)
|
||||
end
|
||||
|
||||
restricted_tags = automation.trigger_field("restricted_tags")
|
||||
|
@ -12,7 +12,19 @@ DiscourseAutomation::Triggerable.add(DiscourseAutomation::Triggers::POST_CREATED
|
||||
{ id: "edited", name: "discourse_automation.triggerables.post_created_edited.edited" },
|
||||
],
|
||||
}
|
||||
field :restricted_category, component: :category
|
||||
field :restricted_archetype,
|
||||
component: :choices,
|
||||
extra: {
|
||||
content: [
|
||||
{ id: "regular", name: "discourse_automation.triggerables.post_created_edited.topics" },
|
||||
{
|
||||
id: "private_message",
|
||||
name: "discourse_automation.triggerables.post_created_edited.personal_messages",
|
||||
},
|
||||
],
|
||||
}
|
||||
field :restricted_categories, component: :categories
|
||||
field :exclude_subcategories, component: :boolean
|
||||
field :restricted_tags, component: :tags
|
||||
field :restricted_groups, component: :groups
|
||||
field :restricted_user_group, component: :group
|
||||
|
Reference in New Issue
Block a user