fix selective content with numerical migration ids

test plan:
* import the package referenced in the ticket with
'select content' checked
* select particular modules to import
* should import as expected

fixes #CNVS-7631

Change-Id: Ic3865a4c499e30ad544b1bab7d17001444a2ea88
Reviewed-on: https://gerrit.instructure.com/23497
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
Product-Review: Bracken Mosbacker <bracken@instructure.com>
QA-Review: August Thornton <august@instructure.com>
This commit is contained in:
James Williams 2013-08-20 08:52:09 -06:00
parent 8b8c4bcb0a
commit 9703389fa3
7 changed files with 43 additions and 25 deletions

View File

@ -161,7 +161,7 @@ define [
linkedItem = @model.get('linked_resource')
checked = @$el.find("#checkbox-#{@cid}").is(':checked')
linkedProperty = "copy[#{linkedItem.type}][#{linkedItem.migration_id}]"
linkedProperty = "copy[#{linkedItem.type}][id_#{linkedItem.migration_id}]"
$collection_box = $("[name=\"copy[all_#{linkedItem.type}]\"]")
if !checked && $collection_box.is(':checked')

View File

@ -364,9 +364,10 @@ class ContentMigrationsController < ApplicationController
params[:do_not_run] = true
end
elsif params[:copy]
copy_options = ContentMigration.process_copy_params(params[:copy])
@content_migration.migration_settings[:migration_ids_to_import] ||= {}
@content_migration.migration_settings[:migration_ids_to_import][:copy] = params[:copy]
@content_migration.copy_options = params[:copy]
@content_migration.migration_settings[:migration_ids_to_import][:copy] = copy_options
@content_migration.copy_options = copy_options
else
@content_migration.migration_settings[:import_immediately] = true
@content_migration.copy_options = {:everything => true}

View File

@ -597,4 +597,21 @@ class ContentMigration < ActiveRecord::Base
self.save
end
end
# strips out the "id_" prepending the migration ids in the form
def self.process_copy_params(hash)
return {} if hash.blank? || !hash.is_a?(Hash)
hash.values.each do |sub_hash|
next unless sub_hash.is_a?(Hash) # e.g. second level in :copy => {:context_modules => {:id_100 => true, etc}}
clean_hash = {}
sub_hash.keys.each do |k|
if k.is_a?(String) && k.start_with?("id_")
clean_hash[k.sub("id_", "")] = sub_hash.delete(k)
end
end
sub_hash.merge!(clean_hash)
end
hash
end
end

View File

@ -114,7 +114,7 @@ module Canvas::Migration::Helpers
content_list << item_hash('attachments', atts[0])
else
mig_id = Digest::MD5.hexdigest(folder_name)
folder = {type: 'folders', property: "copy[folders][#{mig_id}]", title: folder_name, migration_id: mig_id, sub_items: []}
folder = {type: 'folders', property: "copy[folders][id_#{mig_id}]", title: folder_name, migration_id: mig_id, sub_items: []}
content_list << folder
atts.each {|att| folder[:sub_items] << item_hash('attachments', att)}
end
@ -124,7 +124,7 @@ module Canvas::Migration::Helpers
def item_hash(type, item)
hash = {
type: type,
property: "copy[#{type}][#{item['migration_id']}]",
property: "copy[#{type}][id_#{item['migration_id']}]",
title: item['title'],
migration_id: item['migration_id']
}
@ -245,7 +245,7 @@ module Canvas::Migration::Helpers
title ||= item.short_description if item.respond_to?(:short_description)
title ||= ''
hash = {type: type, property: "copy[#{type}][#{mig_id}]", title: title, migration_id: mig_id}
hash = {type: type, property: "copy[#{type}][id_#{mig_id}]", title: title, migration_id: mig_id}
hash = course_linked_resource(item, hash)
hash

View File

@ -300,14 +300,15 @@ describe ContentMigrationsController, :type => :integration do
@migration.workflow_state = 'exported'
@migration.migration_settings[:import_immediately] = false
@migration.save!
@post_params = {:copy => {:all_assignments => true}}
@post_params = {:copy => {:all_assignments => true, :context_modules => {'id_9000' => true}}}
end
it "should set the selective data" do
json = api_call(:put, @migration_url, @params, @post_params)
@migration.reload
@migration.migration_settings[:migration_ids_to_import].should == {'copy' => {'all_assignments' => 'true'}}
@migration.copy_options.should == {'all_assignments' => 'true'}
copy_options = {'all_assignments' => 'true', 'context_modules' => {'9000' => 'true'}}
@migration.migration_settings[:migration_ids_to_import].should == {'copy' => copy_options}
@migration.copy_options.should == copy_options
end
it "should queue a course copy after selecting content" do

View File

@ -31,25 +31,25 @@ define [
@serverResponse = -> [200, { "Content-Type": "application/json" }, JSON.stringify([
{
"type": "assignment_groups",
"property": "copy[assignment_groups][i6314c45816f1cc6d9519d88e4b7f64ab]",
"property": "copy[assignment_groups][id_i6314c45816f1cc6d9519d88e4b7f64ab]",
"title": "Assignments",
"migration_id": "i6314c45816f1cc6d9519d88e4b7f64ab",
"sub_items": [
{
"type": "assignments",
"property": "copy[assignments][i1a139fc4cbf94f961973c63bd90fc1c7]",
"property": "copy[assignments][id_i1a139fc4cbf94f961973c63bd90fc1c7]",
"title": "Assignment 1",
"migration_id": "i1a139fc4cbf94f961973c63bd90fc1c7"
},
{
"type": "assignments",
"property": "copy[assignments][i7af74171d7c7207f1578328d8bbf9dae]",
"property": "copy[assignments][id_i7af74171d7c7207f1578328d8bbf9dae]",
"title": "Unnamed Quiz",
"migration_id": "i7af74171d7c7207f1578328d8bbf9dae"
},
{
"type": "assignments",
"property": "copy[assignments][i4af043da2399a5ec221f666b38714fa8]",
"property": "copy[assignments][id_i4af043da2399a5ec221f666b38714fa8]",
"title": "Unnamed Quiz",
"migration_id": "i4af043da2399a5ec221f666b38714fa8",
"linked_resource": {
@ -120,7 +120,6 @@ define [
equal $subCheckboxes.length, 3
$subCheckboxes[2].click()
ok !$($subCheckboxes[1]).is(':checked'), "Unchecked linked resource"
$subCheckboxes[2].click()

View File

@ -63,10 +63,10 @@ describe Canvas::Migration::Helpers::SelectiveContentFormatter do
it "should group assignments into assignment groups" do
@formatter.get_content_list('assignments').should == [
{:type => "assignment_groups", :property => "copy[assignment_groups][a1]", :title => "a1", :migration_id => "a1",
"sub_items" => [{:type => "assignments", :property => "copy[assignments][a2]", :title => "a2", :migration_id => "a2"}]
{:type => "assignment_groups", :property => "copy[assignment_groups][id_a1]", :title => "a1", :migration_id => "a1",
"sub_items" => [{:type => "assignments", :property => "copy[assignments][id_a2]", :title => "a2", :migration_id => "a2"}]
},
{:type => "assignments", :property => "copy[assignments][a1]", :title => "a1", :migration_id => "a1"}
{:type => "assignments", :property => "copy[assignments][id_a1]", :title => "a1", :migration_id => "a1"}
]
end
@ -80,42 +80,42 @@ describe Canvas::Migration::Helpers::SelectiveContentFormatter do
'a5' => {'path_name' => 'a5.html', 'file_name' => 'a5.html', 'migration_id' => 'a5'},
}}.to_json)
@formatter.get_content_list('attachments').should == [{:type => "folders",
:property => "copy[folders][0cc175b9c0f1b6a831c399e269772661]",
:property => "copy[folders][id_0cc175b9c0f1b6a831c399e269772661]",
:title => "a",
:migration_id => "0cc175b9c0f1b6a831c399e269772661",
:sub_items =>
[{:type => "attachments",
:property => "copy[attachments][a1]",
:property => "copy[attachments][id_a1]",
:title => "a1.html",
:migration_id => "a1",
:path => "a"},
{:type => "attachments",
:property => "copy[attachments][a2]",
:property => "copy[attachments][id_a2]",
:title => "a2.html",
:migration_id => "a2",
:path => "a"}]},
{:type => "folders",
:property => "copy[folders][a7e86136543b019d72468ceebf71fb8e]",
:property => "copy[folders][id_a7e86136543b019d72468ceebf71fb8e]",
:title => "a/b",
:migration_id => "a7e86136543b019d72468ceebf71fb8e",
:sub_items =>
[{:type => "attachments",
:property => "copy[attachments][a3]",
:property => "copy[attachments][id_a3]",
:title => "a3.html",
:migration_id => "a3",
:path => "a/b"}]},
{:type => "folders",
:property => "copy[folders][cff49f359f080f71548fcee824af6ad3]",
:property => "copy[folders][id_cff49f359f080f71548fcee824af6ad3]",
:title => "a/b/c",
:migration_id => "cff49f359f080f71548fcee824af6ad3",
:sub_items =>
[{:type => "attachments",
:property => "copy[attachments][a4]",
:property => "copy[attachments][id_a4]",
:title => "a4.html",
:migration_id => "a4",
:path => "a/b/c"}]},
{:type => "attachments",
:property => "copy[attachments][a5]",
:property => "copy[attachments][id_a5]",
:title => "a5.html",
:migration_id => "a5",
:path => "a5.html"}]