copy file/folder lock status on export/import

closes #4345

Change-Id: I564d7b3be40789a9178a0ac0f192d528c2655f3e
Reviewed-on: https://gerrit.instructure.com/3259
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Zach Wily <zach@instructure.com>
This commit is contained in:
Bracken Mosbacker 2011-04-25 18:27:03 -06:00 committed by Zach Wily
parent 3beb896b50
commit 894f6c4aa5
7 changed files with 178 additions and 7 deletions

View File

@ -107,6 +107,23 @@ class Attachment < ActiveRecord::Base
import_from_migration(att, migration.context)
end
end
if data[:locked_folders]
data[:locked_folders].each do |path|
if f = migration.context.active_folders.find_by_full_name("course files/#{path}")
f.locked = true
f.save
end
end
end
if data[:hidden_folders]
data[:hidden_folders].each do |path|
if f = migration.context.active_folders.find_by_full_name("course files/#{path}")
f.workflow_state = 'hidden'
f.save
end
end
end
end
def self.import_from_migration(hash, context, item=nil)
@ -120,6 +137,8 @@ class Attachment < ActiveRecord::Base
item.context = context
context.imported_migration_items << item if context.imported_migration_items && item.migration_id != hash[:migration_id]
item.migration_id = hash[:migration_id]
item.locked = true if hash[:locked]
item.file_state = 'hidden' if hash[:hidden]
item.save_without_broadcasting!
end
item

View File

@ -41,11 +41,13 @@ module CC
resources << create_learning_outcomes
resources << create_rubrics
resources << create_external_tools
resources << files_meta_path
@resources.resource(
:identifier => migration_id,
"type" => Manifest::LOR,
:href => syl_rel_path
:href => syl_rel_path,
:intendeduse => "syllabus"
) do |res|
res.file(:href=>syl_rel_path)
resources.each do |resource|

View File

@ -53,6 +53,7 @@ module CCHelper
MODULE_META = "module_meta.xml"
RUBRICS = "rubrics.xml"
EXTERNAL_TOOLS = "external_tools.xml"
FILES_META = "files_meta.xml"
SYLLABUS = "syllabus.html"
WEB_RESOURCES_FOLDER = 'web_resources'
WIKI_FOLDER = 'wiki_content'

View File

@ -31,9 +31,45 @@ module CC::Importer
file_map[file['migration_id']] = file
end
convert_locked_hidden_files(file_map)
file_map
end
def convert_locked_hidden_files(file_map)
doc = open_file_xml File.join(@unzipped_file_path, COURSE_SETTINGS_DIR, FILES_META)
if hidden_folders = doc.at_css('hidden_folders')
@course[:hidden_folders] = []
hidden_folders.css('folder').each do |folder|
@course[:hidden_folders] << folder.text
end
end
if locked_folders = doc.at_css('locked_folders')
@course[:locked_folders] = []
locked_folders.css('folder').each do |folder|
@course[:locked_folders] << folder.text
end
end
if hidden_files = doc.at_css('hidden_files')
hidden_files.css('attachment_identifierref').each do |id|
id = id.text
if file_map[id]
file_map[id][:hidden] = true
end
end
end
if hidden_files = doc.at_css('locked_files')
hidden_files.css('attachment_identifierref').each do |id|
id = id.text
if file_map[id]
file_map[id][:locked] = true
end
end
end
end
def package_course_files
zip_file = File.join(@base_export_dir, 'all_files.zip')

View File

@ -19,19 +19,94 @@ module CC
module WebResources
def add_course_files
course_folder = Folder.root_folders(@course).first
hidden_locked_files = {:hidden_folders=>[], :locked_folders=>[], :hidden_files=>[], :locked_files=>[]}
zipper = ContentZipper.new
zipper.process_folder(course_folder, @zip_file, [CCHelper::WEB_RESOURCES_FOLDER]) do |attachment, folder_names|
path = File.join(folder_names, attachment.display_name)
migration_id = CCHelper.create_key(attachment)
zipper.process_folder(course_folder, @zip_file, [CCHelper::WEB_RESOURCES_FOLDER]) do |file, folder_names|
if file.is_a? Folder
dir = File.join(folder_names[1..-1])
hidden_locked_files[:hidden_folders] << dir if file.hidden?
hidden_locked_files[:locked_folders] << dir if file.locked
next
end
path = File.join(folder_names, file.display_name)
migration_id = CCHelper.create_key(file)
hidden_locked_files[:hidden_files] << migration_id if file.hidden?
@resources.resource(
"type" => CCHelper::WEBCONTENT,
:identifier => migration_id,
:href => path
) do |res|
if file.locked
hidden_locked_files[:locked_files] << migration_id
res.metadata do |meta_node|
meta_node.lom :lom do |lom_node|
lom_node.lom :educational do |edu_node|
edu_node.lom :intendedEndUserRole do |role_node|
role_node.lom :source, "IMSGLC_CC_Rolesv1p1"
role_node.lom :value, "Instructor"
end
end
end
end
end
res.file(:href=>path)
end
end
add_meta_info_for_files(hidden_locked_files)
end
def files_meta_path
File.join(CCHelper::COURSE_SETTINGS_DIR, CCHelper::FILES_META)
end
def add_meta_info_for_files(files)
files_file = File.new(File.join(@canvas_resource_dir, CCHelper::FILES_META), 'w')
rel_path = files_meta_path
document = Builder::XmlMarkup.new(:target=>files_file, :indent=>2)
document.instruct!
document.fileMeta(
"xmlns" => CCHelper::CANVAS_NAMESPACE,
"xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance",
"xsi:schemaLocation"=> "#{CCHelper::CANVAS_NAMESPACE} #{CCHelper::XSD_URI}"
) do |root_node|
if !files[:hidden_folders].empty?
root_node.hidden_folders do |folders_node|
files[:hidden_folders].each do |folder|
folders_node.folder folder
end
end
end
if !files[:locked_folders].empty?
root_node.locked_folders do |folders_node|
files[:locked_folders].each do |folder|
folders_node.folder folder
end
end
end
if !files[:hidden_files].empty?
root_node.hidden_files do |folders_node|
files[:hidden_files].each do |file|
folders_node.attachment_identifierref file
end
end
end
if !files[:locked_files].empty?
root_node.locked_files do |folders_node|
files[:locked_files].each do |file|
folders_node.attachment_identifierref file
end
end
end
end
files_file.close if files_file
rel_path
end
def add_media_objects

View File

@ -460,5 +460,40 @@
<xs:attribute name="identifier" type="xs:ID" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="fileMeta">
<xs:complexType>
<xs:all minOccurs="0" maxOccurs="1">
<xs:element name="hidden_folders" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="folder" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="locked_folders" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="folder" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="hidden_files" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="attachment_identifierref" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="locked_files" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="attachment_identifierref" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>

View File

@ -274,9 +274,12 @@ class ContentZipper
end
end
# The callback should accept two arguments, the attachment and the folder names
# The callback should accept two arguments, the attachment/folder and the folder names
def zip_folder(folder, zipfile, folder_names, &callback)
folder.active_file_attachments.select{|a| !@user || a.grants_right?(@user, nil, :download)}.each do |attachment|
if callback && (folder.hidden? || folder.locked)
callback.call(folder, folder_names)
end
folder.file_attachments.scoped(:conditions => "file_state IN ('available', 'hidden')").select{|a| !@user || a.grants_right?(@user, nil, :download)}.each do |attachment|
callback.call(attachment, folder_names) if callback
@context = folder.context
@logger.debug(" found attachment: #{attachment.display_name}")