From 8ac979fb3afce22399ff4b2a51f7f0e84e7ef72d Mon Sep 17 00:00:00 2001 From: Stuart Olivera Date: Mon, 13 May 2019 20:58:37 -0400 Subject: [PATCH] [fix] Include admins in everyone message recipient Fixes #145 --- app/workers/bulk_message_worker.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/workers/bulk_message_worker.rb b/app/workers/bulk_message_worker.rb index dfc2fcc07..f22c93333 100644 --- a/app/workers/bulk_message_worker.rb +++ b/app/workers/bulk_message_worker.rb @@ -4,6 +4,7 @@ class BulkMessageWorker def perform(message_id) message = Message.find(message_id) return unless message.present? && message.status == "queued" + message.update_attribute(:started_at, Time.now) recipients = self.class.build_recipients(message.recipients) @@ -27,8 +28,10 @@ def self.build_recipients(recipient_types) def self.user_ids(type) case type when "all" - User.non_admins.pluck(:id) + # Everyone, including admins that completed a questionnaire + User.non_admins.pluck(:id) + Questionnaire.pluck(:user_id) when "incomplete" + # Incomplete applications, excluding admins that don't have a questionnaire User.non_admins.pluck(:id) - Questionnaire.pluck(:user_id) when "complete" Questionnaire.pluck(:user_id) @@ -74,6 +77,7 @@ def self.user_ids_from_query(type) result = Blazer::RunStatement.new.perform(Blazer.data_sources[model.data_source], model.statement) user_id_column = result.columns.index("user_id") raise "Blazer query is missing required \"user_id\" column" unless user_id_column.present? + result.rows.map { |row| row[user_id_column] } else raise "Unknown recipient query type: #{recipient_query.type.inspect} (in message recipient query: #{type.inspect}"