diff --git a/app/models/course.rb b/app/models/course.rb index 6625615d4ba..562bf757d48 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -1957,6 +1957,7 @@ class Course < ActiveRecord::Base end new_file.folder_id = new_folder_id new_file.save_without_broadcasting! + cm.add_imported_item(new_file) map_merge(file, new_file) rescue cm.add_warning(t(:file_copy_error, "Couldn't copy file \"%{name}\"", :name => file.display_name || file.path_name), $!) diff --git a/app/models/importers/attachment_importer.rb b/app/models/importers/attachment_importer.rb index 88339e54e7a..9fee507fe00 100644 --- a/app/models/importers/attachment_importer.rb +++ b/app/models/importers/attachment_importer.rb @@ -68,6 +68,8 @@ module Importers item.context = context item.migration_id = hash[:migration_id] item.locked = true if hash[:locked] + item.lock_at = Canvas::Migration::MigratorHelper.get_utc_time_from_timestamp(hash[:lock_at]) if hash[:lock_at] + item.unlock_at = Canvas::Migration::MigratorHelper.get_utc_time_from_timestamp(hash[:unlock_at]) if hash[:unlock_at] item.file_state = 'hidden' if hash[:hidden] item.display_name = hash[:display_name] if hash[:display_name] item.usage_rights_id = find_or_create_usage_rights(context, hash[:usage_rights], created_usage_rights_map) if hash[:usage_rights] diff --git a/app/models/importers/course_content_importer.rb b/app/models/importers/course_content_importer.rb index e09fc288798..5a4b837936c 100644 --- a/app/models/importers/course_content_importer.rb +++ b/app/models/importers/course_content_importer.rb @@ -169,6 +169,12 @@ module Importers event.save_without_broadcasting end + migration.imported_migration_items_by_class(Attachment).each do |event| + event.lock_at = shift_date(event.lock_at, shift_options) + event.unlock_at = shift_date(event.unlock_at, shift_options) + event.save_without_broadcasting + end + migration.imported_migration_items_by_class(DiscussionTopic).each do |event| event.delayed_post_at = shift_date(event.delayed_post_at, shift_options) event.lock_at = shift_date(event.lock_at, shift_options) diff --git a/lib/cc/importer/canvas/webcontent_converter.rb b/lib/cc/importer/canvas/webcontent_converter.rb index a5852bf285b..12110a1bda0 100644 --- a/lib/cc/importer/canvas/webcontent_converter.rb +++ b/lib/cc/importer/canvas/webcontent_converter.rb @@ -36,7 +36,7 @@ module CC::Importer::Canvas file_map end - + def convert_file_metadata(file_map) path = File.join(@unzipped_file_path, COURSE_SETTINGS_DIR, FILES_META) return unless File.exist? path @@ -57,6 +57,14 @@ module CC::Importer::Canvas if file_map[id] file_map[id][:hidden] = true if get_bool_val(file, 'hidden', false) file_map[id][:locked] = true if get_bool_val(file, 'locked', false) + + if unlock_at = get_time_val(file, 'unlock_at') + file_map[id][:unlock_at] = unlock_at + end + if lock_at = get_time_val(file, 'lock_at') + file_map[id][:lock_at] = lock_at + end + if display_name = file.at_css("display_name") file_map[id][:display_name] = display_name.text end diff --git a/lib/cc/web_resources.rb b/lib/cc/web_resources.rb index 4d6608c9a8c..c95e492115c 100644 --- a/lib/cc/web_resources.rb +++ b/lib/cc/web_resources.rb @@ -19,6 +19,10 @@ require 'set' module CC module WebResources + def file_or_folder_restricted?(obj) + obj.hidden? || obj.locked || obj.unlock_at || obj.lock_at + end + def add_course_files return if for_course_copy @@ -36,14 +40,14 @@ module CC begin if file.is_a? Folder dir = File.join(folder_names[1..-1]) - files_with_metadata[:folders] << [file, dir] if file.hidden? || file.locked + files_with_metadata[:folders] << [file, dir] if file_or_folder_restricted?(file) next end @added_attachment_ids << file.id path = File.join(folder_names, file.display_name) migration_id = CCHelper.create_key(file) - if file.hidden? || file.locked || file.usage_rights + if file_or_folder_restricted?(file) || file.usage_rights || file.display_name != file.unencoded_filename files_with_metadata[:files] << [file, migration_id] end @resources.resource( @@ -110,6 +114,8 @@ module CC folders_node.folder(:path => path) do |folder_node| folder_node.locked "true" if folder.locked folder_node.hidden "true" if folder.hidden? + folder_node.lock_at CCHelper::ims_datetime(folder.lock_at) if folder.lock_at + folder_node.unlock_at CCHelper::ims_datetime(folder.unlock_at) if folder.unlock_at end end end @@ -121,6 +127,8 @@ module CC files_node.file(:identifier => migration_id) do |file_node| file_node.locked "true" if file.locked file_node.hidden "true" if file.hidden? + file_node.lock_at CCHelper::ims_datetime(file.lock_at) if file.lock_at + file_node.unlock_at CCHelper::ims_datetime(file.unlock_at) if file.unlock_at file_node.display_name file.display_name if file.display_name != file.unencoded_filename if file.usage_rights file_node.usage_rights(:use_justification => file.usage_rights.use_justification) do |node| diff --git a/lib/cc/xsd/cccv1p0.xsd b/lib/cc/xsd/cccv1p0.xsd index c9464c52d9f..6fbbaf1e22d 100644 --- a/lib/cc/xsd/cccv1p0.xsd +++ b/lib/cc/xsd/cccv1p0.xsd @@ -599,6 +599,8 @@ + + @@ -615,6 +617,8 @@ + + diff --git a/spec/models/content_migration/course_copy_attachments_spec.rb b/spec/models/content_migration/course_copy_attachments_spec.rb index 8825d8782b2..49d26ba208b 100644 --- a/spec/models/content_migration/course_copy_attachments_spec.rb +++ b/spec/models/content_migration/course_copy_attachments_spec.rb @@ -118,6 +118,19 @@ describe ContentMigration do expect(@copy_to.attachments.where(migration_id: mig_id(att1)).first.usage_rights).to eq(usage_rights) end + it "should preserve locked date restrictions on export/import" do + att = Attachment.create!(:filename => '1.txt', :uploaded_data => StringIO.new('1'), :folder => Folder.root_folders(@copy_from).first, :context => @copy_from) + att.unlock_at = 2.days.from_now + att.lock_at = 3.days.from_now + att.save! + + run_export_and_import + + copy = @copy_to.attachments.where(migration_id: mig_id(att)).first + expect(copy.unlock_at.to_i).to eq att.unlock_at.to_i + expect(copy.lock_at.to_i).to eq att.lock_at.to_i + end + it "should preserve usage rights on export/import" do att1 = Attachment.create!(:filename => '1.txt', :uploaded_data => StringIO.new('1'), :folder => Folder.root_folders(@copy_from).first, :context => @copy_from) att2 = Attachment.create!(:filename => '2.txt', :uploaded_data => StringIO.new('2'), :folder => Folder.root_folders(@copy_from).first, :context => @copy_from) diff --git a/spec/models/content_migration/course_copy_dates_spec.rb b/spec/models/content_migration/course_copy_dates_spec.rb index d7f1574d955..98bcc194657 100644 --- a/spec/models/content_migration/course_copy_dates_spec.rb +++ b/spec/models/content_migration/course_copy_dates_spec.rb @@ -15,6 +15,13 @@ describe ContentMigration do :lock_at => @old_start + 3.days, :peer_reviews_due_at => @old_start + 4.days ) + + att = Attachment.create!(:context => @copy_from, :filename => 'hi.txt', + :uploaded_data => StringIO.new("stuff"), :folder => Folder.unfiled_folder(@copy_from)) + att.unlock_at = @old_start + 2.days + att.lock_at = @old_start + 3.days + att.save! + @copy_from.quizzes.create!(:due_at => "05 Jul 2012 06:00:00 UTC +00:00", :unlock_at => @old_start + 1.days, :lock_at => @old_start + 5.days, @@ -63,6 +70,10 @@ describe ContentMigration do expect(new_asmnt.lock_at.to_i).to eq (@new_start + 3.day).to_i expect(new_asmnt.peer_reviews_due_at.to_i).to eq (@new_start + 4.day).to_i + new_att = @copy_to.attachments.first + expect(new_att.unlock_at.to_i).to eq (@new_start + 2.day).to_i + expect(new_att.lock_at.to_i).to eq (@new_start + 3.day).to_i + new_quiz = @copy_to.quizzes.first expect(new_quiz.due_at.to_i).to eq (@new_start + 4.day).to_i expect(new_quiz.unlock_at.to_i).to eq (@new_start + 1.day).to_i @@ -109,6 +120,10 @@ describe ContentMigration do expect(new_asmnt.lock_at).to be_nil expect(new_asmnt.peer_reviews_due_at).to be_nil + new_att = @copy_to.attachments.first + expect(new_att.unlock_at).to be_nil + expect(new_att.lock_at).to be_nil + new_quiz = @copy_to.quizzes.first expect(new_quiz.due_at).to be_nil expect(new_quiz.unlock_at).to be_nil