mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 19:02:40 +08:00
FEATURE: Added trigger for topic tags changed (#28176)
* FEATURE: Added trigger for topic tags changed * DEV: register new file in plugin.rb * DEV: update to use already existing `:topic_tags_changed` event * DEV: Add tests to topic_tags_changed trigger remove `watching_user` field * DEV: add more tests to topic_tags_changed_spec.rb * DEV: update tests and implementation for topic tags changed automation trigger * DEV: update checking for tags changed automation * DEV: Update argument application for `handle_topic_tags_changed`
This commit is contained in:
@ -195,6 +195,36 @@ module DiscourseAutomation
|
||||
end
|
||||
end
|
||||
|
||||
def self.handle_topic_tags_changed(topic, old_tag_names, new_tag_names)
|
||||
name = DiscourseAutomation::Triggers::TOPIC_TAGS_CHANGED
|
||||
|
||||
DiscourseAutomation::Automation
|
||||
.where(trigger: name, enabled: true)
|
||||
.find_each do |automation|
|
||||
watching_categories = automation.trigger_field("watching_categories")
|
||||
if watching_categories["value"]
|
||||
next if !watching_categories["value"].include?(topic.category_id)
|
||||
end
|
||||
|
||||
watching_tags = automation.trigger_field("watching_tags")
|
||||
if watching_tags["value"]
|
||||
should_skip = false
|
||||
watching_tags["value"].each do |tag|
|
||||
should_skip = true if !old_tag_names.empty? && !old_tag_names.include?(tag)
|
||||
should_skip = true if !new_tag_names.empty? && !new_tag_names.include?(tag)
|
||||
end
|
||||
next if should_skip
|
||||
end
|
||||
|
||||
automation.trigger!(
|
||||
"kind" => name,
|
||||
"topic" => topic,
|
||||
"removed_tags" => old_tag_names,
|
||||
"added_tags" => new_tag_names,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def self.handle_after_post_cook(post, cooked)
|
||||
return cooked if post.post_type != Post.types[:regular] || post.post_number > 1
|
||||
|
||||
|
@ -6,6 +6,7 @@ module DiscourseAutomation
|
||||
API_CALL = "api_call"
|
||||
CATEGORY_CREATED_EDITED = "category_created_edited"
|
||||
PM_CREATED = "pm_created"
|
||||
TOPIC_TAGS_CHANGED = "topic_tags_changed"
|
||||
POINT_IN_TIME = "point_in_time"
|
||||
POST_CREATED_EDITED = "post_created_edited"
|
||||
RECURRING = "recurring"
|
||||
|
@ -0,0 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
DiscourseAutomation::Triggerable.add(DiscourseAutomation::Triggers::TOPIC_TAGS_CHANGED) do
|
||||
field :watching_categories, component: :categories
|
||||
field :watching_tags, component: :tags
|
||||
end
|
Reference in New Issue
Block a user