FEATURE: adds support for a random assign automation (#162)
This commit is contained in:
parent
7438b634e3
commit
954e908e24
|
@ -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
|
||||
|
|
|
@ -62,3 +62,7 @@ en:
|
|||
%{topic_0}
|
||||
%{topic_1}
|
||||
%{topic_2}
|
||||
discourse_automation:
|
||||
scriptables:
|
||||
random_assign:
|
||||
title: Random assign
|
||||
|
|
24
plugin.rb
24
plugin.rb
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue