add option to only un_conclude from sis import
Change-Id: Id248fd99fc377cd658275dcf3662c2f95850cd6d Reviewed-on: https://gerrit.instructure.com/160872 Reviewed-by: James Williams <jamesw@instructure.com> Reviewed-by: Cody Cutrer <cody@instructure.com> Tested-by: Jenkins Product-Review: Rob Orton <rob@instructure.com> QA-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
parent
b5e465ccd6
commit
685dfb287f
|
@ -536,6 +536,10 @@ class SisImportsApiController < ApplicationController
|
|||
# If set, will only restore items that were deleted. This will ignore any
|
||||
# items that were created or modified.
|
||||
#
|
||||
# @argument unconclude_only [Boolean]
|
||||
# If set, will only restore enrollments that were concluded. This will
|
||||
# ignore any items that were created or deleted.
|
||||
#
|
||||
# @example_request
|
||||
# curl https://<canvas>/api/v1/accounts/<account_id>/sis_imports/<sis_import_id>/restore_states \
|
||||
# -H 'Authorization: Bearer <token>'
|
||||
|
@ -546,7 +550,11 @@ class SisImportsApiController < ApplicationController
|
|||
@batch = @account.sis_batches.find(params[:id])
|
||||
batch_mode = value_to_boolean(params[:batch_mode])
|
||||
undelete_only = value_to_boolean(params[:undelete_only])
|
||||
progress = @batch.restore_states_later(batch_mode: batch_mode, undelete_only: undelete_only)
|
||||
unconclude_only = value_to_boolean(params[:unconclude_only])
|
||||
if undelete_only && unconclude_only
|
||||
return render json: 'cannot set both undelete_only and unconclude_only', status: :bad_request
|
||||
end
|
||||
progress = @batch.restore_states_later(batch_mode: batch_mode, undelete_only: undelete_only, unconclude_only: unconclude_only)
|
||||
render json: progress_json(progress, @current_user, session)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -738,18 +738,19 @@ class SisBatch < ActiveRecord::Base
|
|||
count
|
||||
end
|
||||
|
||||
def restore_states_later(batch_mode: nil, undelete_only: false)
|
||||
def restore_states_later(batch_mode: nil, undelete_only: false, unconclude_only: false)
|
||||
progress = account.progresses.create! tag: "sis_batch_state_restore", completion: 0.0
|
||||
progress.process_job(self, :restore_states_for_batch,
|
||||
{singleton: "restore_states_for_batch:#{account.global_id}}"},
|
||||
{batch_mode: batch_mode, undelete_only: undelete_only})
|
||||
{batch_mode: batch_mode, undelete_only: undelete_only, unconclude_only: unconclude_only})
|
||||
progress
|
||||
end
|
||||
|
||||
def restore_states_for_batch(progress=nil, batch_mode: nil, undelete_only: false)
|
||||
def restore_states_for_batch(progress=nil, batch_mode: nil, undelete_only: false, unconclude_only: false)
|
||||
self.update_attribute(:workflow_state, 'restoring')
|
||||
roll_back = self.roll_back_data
|
||||
roll_back = roll_back.where(updated_workflow_state: %w(retired deleted)) if undelete_only
|
||||
roll_back = roll_back.where(updated_workflow_state: %w(completed)) if unconclude_only
|
||||
roll_back = roll_back.where(batch_mode_delete: batch_mode) if batch_mode
|
||||
types = roll_back.active.distinct.order(:context_type).pluck(:context_type)
|
||||
total = roll_back.active.count if progress
|
||||
|
@ -760,7 +761,7 @@ class SisBatch < ActiveRecord::Base
|
|||
count = restore_states_for_type(type, scope, progress, count, total)
|
||||
end
|
||||
progress&.update_completion!(100)
|
||||
self.workflow_state = (undelete_only || batch_mode) ? 'partially_restored' : 'restored'
|
||||
self.workflow_state = (undelete_only || unconclude_only || batch_mode) ? 'partially_restored' : 'restored'
|
||||
self.save!
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue