add api flag to not send notifications for content exports

Test Plan:
 * Create a ContentExport through the api setting the skip_notifications to false
 * When it finishes you shouldn't get an email

closes PLAT-591

Change-Id: I036c65012bec6fe7cb57f6b79b3684c3b9eadf3f
Reviewed-on: https://gerrit.instructure.com/39015
QA-Review: Clare Strong <clare@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
Product-Review: Bracken Mosbacker <bracken@instructure.com>
This commit is contained in:
Bracken Mosbacker 2014-08-10 18:44:10 -06:00
parent 468faa4553
commit 31d5b36837
3 changed files with 20 additions and 2 deletions

View File

@ -126,6 +126,9 @@ class ContentExportsApiController < ApplicationController
# "qti":: Export quizzes from a course in the QTI format
# "zip":: Export files from a course, group, or user in a zip file
#
# @argument skip_notifications [Optional, Boolean]
# Don't send the notifications about the export to the user. Default: false
#
# @returns ContentExport
def create
if authorized_action(@context, @current_user, :read)
@ -135,6 +138,7 @@ class ContentExportsApiController < ApplicationController
export = @context.content_exports.build
export.user = @current_user
export.workflow_state = 'created'
export.settings[:skip_notifications] = true if value_to_boolean(params[:skip_notifications])
# ZipExporter accepts unhashed asset strings, to avoid having to instantiate all the files and folders
selected_content = ContentMigration.process_copy_params(params[:select], true, params[:export_type] == ContentExport::ZIP) if params[:select]

View File

@ -48,17 +48,24 @@ class ContentExport < ActiveRecord::Base
state :deleted
end
def send_notification?
context_type == 'Course' &&
export_type != ZIP &&
content_migration.blank? &&
!settings[:skip_notifications]
end
set_broadcast_policy do |p|
p.dispatch :content_export_finished
p.to { [user] }
p.whenever {|record|
record.context_type == 'Course' && record.export_type != ZIP && record.changed_state(:exported) && self.content_migration.blank?
record.changed_state(:exported) && record.send_notification?
}
p.dispatch :content_export_failed
p.to { [user] }
p.whenever {|record|
record.context_type == 'Course' && record.export_type != ZIP && record.changed_state(:failed) && self.content_migration.blank?
record.changed_state(:failed) && record.send_notification?
}
end

View File

@ -173,6 +173,13 @@ describe ContentExportsApiController, type: :request do
{}, {}, { expected_status: 400 })
end
it "should set skip notifications flag" do
json = api_call_as_user(t_teacher, :post, "/api/v1/courses/#{t_course.id}/content_exports",
{ controller: 'content_exports_api', action: 'create', format: 'json', course_id: t_course.to_param, export_type: 'common_cartridge', skip_notifications: true })
export = t_course.content_exports.find_by_id(json['id'])
export.send_notification?.should be_false
end
it "should create a qti export" do
json = api_call_as_user(t_teacher, :post, "/api/v1/courses/#{t_course.id}/content_exports?export_type=qti",
{ controller: 'content_exports_api', action: 'create', format: 'json', course_id: t_course.to_param, export_type: 'qti' })