FEATURE: adds support for a random assign automation (#162)

This commit is contained in:
Joffrey JAFFEUX 2021-06-24 16:51:49 +02:00 committed by GitHub
parent 7438b634e3
commit 954e908e24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 0 deletions

View File

@ -69,3 +69,11 @@ en:
bulk:
unassign: "Unassign Topics"
assign: "Assign Topics"
discourse_automation:
scriptables:
random_assign:
fields:
assignees_group:
label: Assignees Group
assigned_topic:
label: Assigned Topic ID

View File

@ -62,3 +62,7 @@ en:
%{topic_0}
%{topic_1}
%{topic_2}
discourse_automation:
scriptables:
random_assign:
title: Random assign

View File

@ -575,4 +575,28 @@ after_initialize do
end
end
end
if defined?(DiscourseAutomation)
add_automation_scriptable('random_assign') do
field :assignees_group, component: :group
field :assigned_topic, component: :text
version 1
triggerables %i[point_in_time recurring]
script do |context, fields|
next unless SiteSetting.assign_enabled?
next unless group_id = fields.dig('assignees_group', 'group_id')
next unless group = Group.find_by(id: group_id)
assign_to = group.group_users.order(Arel.sql('RANDOM()')).first.user
next unless topic_id = fields.dig('assigned_topic', 'text')
next unless topic = Topic.find_by(id: topic_id)
TopicAssigner.new(topic, Discourse.system_user).assign(assign_to)
end
end
end
end