diff --git a/lib/queries.rb b/lib/queries.rb index e351e28..87c44a4 100644 --- a/lib/queries.rb +++ b/lib/queries.rb @@ -68,6 +68,11 @@ class Queries "id": -12, "name": "List of topics a user is watching/tracking/muted", "description": "The query requires a ‘notification_level’ parameter. Use 0 for muted, 1 for regular, 2 for tracked and 3 for watched topics." + }, + "assigned-topics-report": { + "id": -13, + "name": "List of assigned topics by user", + "description": "This report requires the assign plugin, it will find all assigned topics" } }.with_indifferent_access @@ -373,6 +378,16 @@ class Queries ORDER BY tu.last_visited_at DESC SQL + queries["assigned-topics-report"]["sql"] = <<~SQL + SELECT value::int user_id, topic_id + FROM topic_custom_fields tf + JOIN topics t on t.id = topic_id + JOIN users u on u.id = value::int + WHERE tf.name = 'assigned_to_id' + AND t.deleted_at IS NULL + ORDER BY username, topic_id + SQL + # convert query ids from "mostcommonlikers" to "-1", "mostmessages" to "-2" etc. queries.transform_keys!.with_index { |key, idx| "-#{idx + 1}" } queries