canvas-lms/lib/summary_message_consolidato...

66 lines
2.3 KiB
Ruby
Raw Normal View History

2011-02-01 09:57:29 +08:00
#
# Copyright (C) 2011 - present Instructure, Inc.
2011-02-01 09:57:29 +08:00
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
class SummaryMessageConsolidator
def self.process
SummaryMessageConsolidator.new.process
end
2011-02-01 09:57:29 +08:00
def initialize(n=nil)
@logger = Rails.logger
2011-02-01 09:57:29 +08:00
end
2011-02-01 09:57:29 +08:00
def process
Add API for admins to access user messages There are three parts to this: - API access for site admins and account admins. Account admins can only see messages for their account. - Includes start and end time parameters for basic searching - Summary notification are gathered up per account now, so account admins will not see a summary notification from multiple accounts. fixes CNVS-3695 test plan: - Verify Admin Access: - Have a user enrolled in two courses in separate root accounts. - Send the user ASAP notification from each account. - Go to /users/:id/messages (the old interface) and verify the messages appear there. - As a site admin, get /api/v1/comm_messages for the user (see documentation for the api). - Verify that data for both messages are returned. - Use the console to give an account admin on one of the accounts :read_messages permissions. - As the account admin, get /api/v1/comm_messages for the user. - Verify that only the message for the admin's account is returned. - Verify start_time and end_time parameters - Use the console to modify the created_at field for the user's messages - As a site admin, get /api/v1/comm_messages for the user, specifying various combinations of start_time and end_time, and make sure the appropriate messages are returned. - Verify account based summaries - Set the notification policies for the user to a summary setting (daily or weekly) - Send multiple notifications to the user from each account. - Use the console to run the SummaryMessageConsolidator::process function. - View /messages for the user and verify that separate summaries are sent for each account. Change-Id: Ie33ec02cc2033a1cc2f1fcbe538b76792aab0e6c Reviewed-on: https://gerrit.instructure.com/18586 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Mark Ericksen <marke@instructure.com> QA-Review: Marc LeGendre <marc@instructure.com> Product-Review: Marc LeGendre <marc@instructure.com>
2013-03-13 23:11:14 +08:00
batch_ids = delayed_message_batch_ids
dm_id_batches = batch_ids.map do |batch_id|
dm_ids = delayed_message_ids_for_batch(batch_id)
@logger.info("Scheduled summary with #{dm_ids.length} messages for communication channel id #{batch_id['communication_channel_id']} and root account id #{batch_id['root_account_id'] || 'null'}")
dm_ids
2011-02-01 09:57:29 +08:00
end
dm_id_batches.in_groups_of(Setting.get('summary_message_consolidator_batch_size', '500').to_i, false) do |batches|
DelayedMessage.where(:id => batches.flatten).
update_all(:batched_at => Time.now.utc, :workflow_state => 'sent', :updated_at => Time.now.utc)
Delayed::Batch.serial_batch do
batches.each do |dm_ids|
DelayedMessage.send_later_enqueue_args(:summarize, { :priority => Delayed::LOWER_PRIORITY }, dm_ids)
end
end
end
dm_id_batches.size
2011-02-01 09:57:29 +08:00
end
Add API for admins to access user messages There are three parts to this: - API access for site admins and account admins. Account admins can only see messages for their account. - Includes start and end time parameters for basic searching - Summary notification are gathered up per account now, so account admins will not see a summary notification from multiple accounts. fixes CNVS-3695 test plan: - Verify Admin Access: - Have a user enrolled in two courses in separate root accounts. - Send the user ASAP notification from each account. - Go to /users/:id/messages (the old interface) and verify the messages appear there. - As a site admin, get /api/v1/comm_messages for the user (see documentation for the api). - Verify that data for both messages are returned. - Use the console to give an account admin on one of the accounts :read_messages permissions. - As the account admin, get /api/v1/comm_messages for the user. - Verify that only the message for the admin's account is returned. - Verify start_time and end_time parameters - Use the console to modify the created_at field for the user's messages - As a site admin, get /api/v1/comm_messages for the user, specifying various combinations of start_time and end_time, and make sure the appropriate messages are returned. - Verify account based summaries - Set the notification policies for the user to a summary setting (daily or weekly) - Send multiple notifications to the user from each account. - Use the console to run the SummaryMessageConsolidator::process function. - View /messages for the user and verify that separate summaries are sent for each account. Change-Id: Ie33ec02cc2033a1cc2f1fcbe538b76792aab0e6c Reviewed-on: https://gerrit.instructure.com/18586 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Mark Ericksen <marke@instructure.com> QA-Review: Marc LeGendre <marc@instructure.com> Product-Review: Marc LeGendre <marc@instructure.com>
2013-03-13 23:11:14 +08:00
def delayed_message_batch_ids
Shackles.activate(:slave) do
Add API for admins to access user messages There are three parts to this: - API access for site admins and account admins. Account admins can only see messages for their account. - Includes start and end time parameters for basic searching - Summary notification are gathered up per account now, so account admins will not see a summary notification from multiple accounts. fixes CNVS-3695 test plan: - Verify Admin Access: - Have a user enrolled in two courses in separate root accounts. - Send the user ASAP notification from each account. - Go to /users/:id/messages (the old interface) and verify the messages appear there. - As a site admin, get /api/v1/comm_messages for the user (see documentation for the api). - Verify that data for both messages are returned. - Use the console to give an account admin on one of the accounts :read_messages permissions. - As the account admin, get /api/v1/comm_messages for the user. - Verify that only the message for the admin's account is returned. - Verify start_time and end_time parameters - Use the console to modify the created_at field for the user's messages - As a site admin, get /api/v1/comm_messages for the user, specifying various combinations of start_time and end_time, and make sure the appropriate messages are returned. - Verify account based summaries - Set the notification policies for the user to a summary setting (daily or weekly) - Send multiple notifications to the user from each account. - Use the console to run the SummaryMessageConsolidator::process function. - View /messages for the user and verify that separate summaries are sent for each account. Change-Id: Ie33ec02cc2033a1cc2f1fcbe538b76792aab0e6c Reviewed-on: https://gerrit.instructure.com/18586 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Mark Ericksen <marke@instructure.com> QA-Review: Marc LeGendre <marc@instructure.com> Product-Review: Marc LeGendre <marc@instructure.com>
2013-03-13 23:11:14 +08:00
DelayedMessage.connection.select_all(
DelayedMessage.select('communication_channel_id').select('root_account_id').distinct.
Add API for admins to access user messages There are three parts to this: - API access for site admins and account admins. Account admins can only see messages for their account. - Includes start and end time parameters for basic searching - Summary notification are gathered up per account now, so account admins will not see a summary notification from multiple accounts. fixes CNVS-3695 test plan: - Verify Admin Access: - Have a user enrolled in two courses in separate root accounts. - Send the user ASAP notification from each account. - Go to /users/:id/messages (the old interface) and verify the messages appear there. - As a site admin, get /api/v1/comm_messages for the user (see documentation for the api). - Verify that data for both messages are returned. - Use the console to give an account admin on one of the accounts :read_messages permissions. - As the account admin, get /api/v1/comm_messages for the user. - Verify that only the message for the admin's account is returned. - Verify start_time and end_time parameters - Use the console to modify the created_at field for the user's messages - As a site admin, get /api/v1/comm_messages for the user, specifying various combinations of start_time and end_time, and make sure the appropriate messages are returned. - Verify account based summaries - Set the notification policies for the user to a summary setting (daily or weekly) - Send multiple notifications to the user from each account. - Use the console to run the SummaryMessageConsolidator::process function. - View /messages for the user and verify that separate summaries are sent for each account. Change-Id: Ie33ec02cc2033a1cc2f1fcbe538b76792aab0e6c Reviewed-on: https://gerrit.instructure.com/18586 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Mark Ericksen <marke@instructure.com> QA-Review: Marc LeGendre <marc@instructure.com> Product-Review: Marc LeGendre <marc@instructure.com>
2013-03-13 23:11:14 +08:00
where("workflow_state = ? AND send_at <= ?", 'pending', Time.now.to_s(:db)).
to_sql)
end
end
def delayed_message_ids_for_batch(batch)
DelayedMessage.
where("workflow_state = ? AND send_at <= ?", 'pending', Time.now.to_s(:db)).
where(batch). # hash condition will properly handle the case where root_account_id is null
pluck(:id)
Add API for admins to access user messages There are three parts to this: - API access for site admins and account admins. Account admins can only see messages for their account. - Includes start and end time parameters for basic searching - Summary notification are gathered up per account now, so account admins will not see a summary notification from multiple accounts. fixes CNVS-3695 test plan: - Verify Admin Access: - Have a user enrolled in two courses in separate root accounts. - Send the user ASAP notification from each account. - Go to /users/:id/messages (the old interface) and verify the messages appear there. - As a site admin, get /api/v1/comm_messages for the user (see documentation for the api). - Verify that data for both messages are returned. - Use the console to give an account admin on one of the accounts :read_messages permissions. - As the account admin, get /api/v1/comm_messages for the user. - Verify that only the message for the admin's account is returned. - Verify start_time and end_time parameters - Use the console to modify the created_at field for the user's messages - As a site admin, get /api/v1/comm_messages for the user, specifying various combinations of start_time and end_time, and make sure the appropriate messages are returned. - Verify account based summaries - Set the notification policies for the user to a summary setting (daily or weekly) - Send multiple notifications to the user from each account. - Use the console to run the SummaryMessageConsolidator::process function. - View /messages for the user and verify that separate summaries are sent for each account. Change-Id: Ie33ec02cc2033a1cc2f1fcbe538b76792aab0e6c Reviewed-on: https://gerrit.instructure.com/18586 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Mark Ericksen <marke@instructure.com> QA-Review: Marc LeGendre <marc@instructure.com> Product-Review: Marc LeGendre <marc@instructure.com>
2013-03-13 23:11:14 +08:00
end
2011-02-01 09:57:29 +08:00
end