include dashboard card image settings with course copy

test plan:
* enable the dashboard course card image feature
* set a image for a course
* copy the course
* the new course should have the same image

closes #CNVS-33042

Change-Id: Iacf183fd854d63cfa790521feba34efd0c7ab8d9
Reviewed-on: https://gerrit.instructure.com/94233
Tested-by: Jenkins
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
QA-Review: Heath Hales <hhales@instructure.com>
Product-Review: James Williams  <jamesw@instructure.com>
This commit is contained in:
James Williams 2016-11-02 10:30:40 -06:00
parent 70ad7bdd5e
commit 1b97dcb77a
6 changed files with 44 additions and 2 deletions

View File

@ -292,6 +292,15 @@ module Importers
end
end
end
if image_url = settings[:image_url]
course.image_url = image_url
course.image_id = nil
elsif image_ref = settings[:image_identifier_ref]
if image_att = course.attachments.where(:migration_id => image_ref).first
course.image_id = image_att.id
course.image_url = nil
end
end
if settings[:lock_all_announcements]
Announcement.lock_from_course(course)
end

View File

@ -146,6 +146,15 @@ JOKE
atts -= Canvas::Migration::MigratorHelper::COURSE_NO_COPY_ATTS
atts << :grading_standard_enabled
atts << :storage_quota
if @course.image_url.present?
atts << :image_url
elsif @course.image_id.present?
if image_att = @course.attachments.active.where(id: @course.image_id).first
c.image_identifier_ref(create_key(image_att))
end
end
@course.disable_setting_defaults do # so that we don't copy defaulted settings
atts.each do |att|
c.tag!(att, @course.send(att)) unless @course.send(att).nil? || @course.send(att) == ''

View File

@ -55,7 +55,7 @@ module CC::Importer::Canvas
['title', 'course_code', 'default_wiki_editing_roles',
'turnitin_comments', 'default_view', 'license', 'locale',
'group_weighting_scheme', 'storage_quota', 'grading_standard_identifier_ref',
'root_account_uuid'].each do |string_type|
'root_account_uuid', 'image_url', 'image_identifier_ref'].each do |string_type|
val = get_node_val(doc, string_type)
course[string_type] = val unless val.nil?
end

View File

@ -37,6 +37,8 @@
<xs:element name="hide_distribution_graphs" type="xs:boolean" minOccurs="0"/>
<xs:element name="allow_student_discussion_topics" type="xs:boolean" minOccurs="0"/>
<xs:element name="allow_student_discussion_editing" type="xs:boolean" minOccurs="0"/>
<xs:element name="image_url" type="xs:string" minOccurs="0"/>
<xs:element name="image_identifier_ref" type="xs:string" minOccurs="0"/>
<xs:element name="default_view" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">

View File

@ -417,6 +417,28 @@ describe ContentMigration do
expect(@copy_to.tab_configuration).to eq @copy_from.tab_configuration
end
it "should copy dashboard images" do
att = attachment_model(:context => @copy_from, :uploaded_data => stub_png_data, :filename => "homework.png")
@copy_from.image_id = att.id
@copy_from.save!
run_course_copy
@copy_to.reload
new_att = @copy_to.attachments.where(:migration_id => mig_id(att)).first
expect(@copy_to.image_id.to_i).to eq new_att.id
example_url = "example.com"
@copy_from.image_url = example_url
@copy_from.image_id = nil
@copy_from.save!
run_course_copy
@copy_to.reload
expect(@copy_to.image_url).to eq example_url
end
it "should convert domains in imported urls if specified in account settings" do
account = @copy_to.root_account
account.settings[:default_migration_settings] = {:domain_substitution_map => {"http://derp.derp" => "https://derp.derp"}}