import html files in cc packages as assignments if configured

test plan:
* import the package referenced in the ticket
* it should have assignments instead of plain html files

closes #CNVS-29203

Change-Id: Ibf77b940d4c0d1fc1a6bd6a8bb2a7d9187eb1590
Reviewed-on: https://gerrit.instructure.com/78996
Tested-by: Jenkins
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
QA-Review: Deepeeca Soundarrajan <dsoundarrajan@instructure.com>
Product-Review: James Williams  <jamesw@instructure.com>
This commit is contained in:
James Williams 2016-05-06 13:33:29 -06:00
parent 2169217dbf
commit 5a57f1923e
4 changed files with 39 additions and 8 deletions

View File

@ -44,6 +44,8 @@ module CC::Importer::Standard
# exports the package into the intermediary json
def convert(to_export = nil)
@course[:assignments] ||= []
@archive.prepare_cartridge_file(MANIFEST_FILE)
@manifest = open_file_xml(File.join(@unzipped_file_path, MANIFEST_FILE))
@manifest.remove_namespaces!
@ -55,7 +57,7 @@ module CC::Importer::Standard
@course[:discussion_topics] = convert_discussions
lti_converter = CC::Importer::BLTIConverter.new
@course[:external_tools] = convert_blti_links_with_flat(lti_converter)
@course[:assignments] = lti_converter.create_assignments_from_lti_links(@course[:external_tools])
@course[:assignments] += lti_converter.create_assignments_from_lti_links(@course[:external_tools])
convert_cc_assignments(@course[:assignments])
@course[:assessment_questions], @course[:assessments] = convert_quizzes if Qti.qti_enabled?
@course[:modules] = convert_organizations(@manifest)

View File

@ -122,11 +122,21 @@ module CC::Importer::Standard
:linked_resource_title => get_node_val(item_node, 'title')
}
when /webcontent|learning-application-resource\z/
# todo check intended use
item = {:indent => indent, :linked_resource_type => 'FILE_TYPE'}
item = {:indent => indent}
item[:linked_resource_id] = item_node['identifierref']
item[:linked_resource_title] = get_node_val(item_node, 'title')
end
if resource[:intended_use] == "assignment" &&
(assignments = @course[:assignments].select{|a| a[:migration_id] == item[:linked_resource_id]}.presence)
assignments.each do |a|
# because of course the title isn't anywhere else
a[:title] ||= item[:linked_resource_title]
end
item[:linked_resource_type] = "ASSIGNMENT"
else
item[:linked_resource_type] = "FILE_TYPE"
end
end
if item && resource[:intended_user_role] == 'Instructor'
item[:workflow_state] = 'unpublished'

View File

@ -20,7 +20,15 @@ module CC::Importer::Standard
include CC::Importer
def create_file_map
new_assignments = []
resources_by_type(WEBCONTENT, "associatedcontent").each do |res|
if res[:intended_use] == "assignment"
path = get_full_path(res[:href])
if path && File.exists?(path) && Attachment.mimetype(path) =~ /html/
new_assignments << {:migration_id => res[:migration_id], :description => File.read(path)}
end
end
main_file = {}
main_file[:migration_id] = res[:migration_id]
main_file[:path_name] = res[:href]
@ -52,6 +60,11 @@ module CC::Importer::Standard
add_course_file(main_file, true)
end
end
new_assignments.each do |a|
a[:description] = replace_urls(a[:description])
@course[:assignments] << a
end
end
def package_course_files(file_map)
@ -78,6 +91,5 @@ module CC::Importer::Standard
File.expand_path(zip_file)
end
end
end

View File

@ -34,6 +34,13 @@ describe "Standard Common Cartridge importing" do
end
end
it "should import files as assignments with intended_use set" do
assignment = @course.assignments.where(:migration_id => "f5").first
att = @course.attachments.where(:migration_id => "8612e3db71e452d5d2952ff64647c0d8").first
expect(assignment.description).to match_ignoring_whitespace(%{<img src="/courses/#{@course.id}/files/#{att.id}/preview">})
expect(assignment.title).to eq "Assignment 2"
end
it "should import discussion topics" do
expect(@course.discussion_topics.count).to eq 2
file1_id = @course.attachments.where(migration_id: "I_media_R").first.id
@ -98,8 +105,8 @@ describe "Standard Common Cartridge importing" do
expect(tag.title).to eq "Sub-Folder 2"
expect(tag.indent).to eq 1
tag = mod1.content_tags[4]
expect(tag.content_type).to eq 'Attachment'
expect(tag.content_id).to eq @course.attachments.where(migration_id: "f5").first.id
expect(tag.content_type).to eq 'Assignment'
expect(tag.content_id).to eq @course.assignments.where(migration_id: "f5").first.id
expect(tag.indent).to eq 2
mod1 = @course.context_modules.where(migration_id: "m3").first
@ -215,7 +222,7 @@ describe "Standard Common Cartridge importing" do
it "should import webcontent" do
expect(@course.attachments.count).to eq 20
expect(@course.attachments.active.count).to eq 10
mig_ids = %w{I_00001_R I_00006_Media I_media_R f3 f4 f5 8612e3db71e452d5d2952ff64647c0d8 I_00003_R_IMAGERESOURCE 7acb90d1653008e73753aa2cafb16298 6a35b0974f59819404dc86d48fe39fc3}
mig_ids = %w{I_00001_R I_00006_Media I_media_R f3 f4 I_00003_R_IMAGERESOURCE 7acb90d1653008e73753aa2cafb16298 6a35b0974f59819404dc86d48fe39fc3}
mig_ids.each do |mig_id|
atts = @course.attachments.where(migration_id: mig_id).to_a
expect(atts.length).to eq 2