Skip to content

Commit 6a930f7

Browse files
committed
fix module item workflow state syncing issues with course copy
test plan: * create an assignment/wiki page/etc and publish it * copy it over to a new course * unpublish the copied content * in the original course, add the content as a module item * do another copy from the original course to the copied course, but use "select content" to only select the module for copy * the copied module item should be unpublished, like the content it refers to closes #CNVS-32532 Change-Id: Ic049b8212e8b97af80823e7f70851daf0e38e86a Reviewed-on: https://gerrit.instructure.com/93912 Reviewed-by: Dan Minkevitch <dan@instructure.com> Tested-by: Jenkins QA-Review: Deepeeca Soundarrajan <dsoundarrajan@instructure.com> Product-Review: James Williams <jamesw@instructure.com>
1 parent 5eca96b commit 6a930f7

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

app/models/importers/context_module_importer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def self.add_module_item_from_migration(context_module, hash, level, context, it
299299
item.migration_id = hash[:migration_id]
300300
item.new_tab = hash[:new_tab]
301301
item.position = (context_module.item_migration_position ||= context_module.content_tags.not_deleted.map(&:position).compact.max || 0)
302-
if hash[:workflow_state] && !['active', 'published'].include?(item.workflow_state)
302+
if hash[:workflow_state] && ContentTag::TABLELESS_CONTENT_TYPES.include?(item.content_type) && !['active', 'published'].include?(item.workflow_state)
303303
item.workflow_state = hash[:workflow_state]
304304
end
305305
context_module.item_migration_position += 1

app/models/importers/wiki_page_importer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def self.import_from_migration(hash, context, migration, item=nil)
6666
hide_from_students = hash[:hide_from_students] if !hash[:hide_from_students].nil?
6767
state = hash[:workflow_state]
6868
if state || !hide_from_students.nil?
69-
if state == 'active' && Canvas::Plugin.value_to_boolean(hide_from_students) == false
69+
if state == 'active' && !item.unpublished? && Canvas::Plugin.value_to_boolean(hide_from_students) == false
7070
item.workflow_state = 'active'
7171
else
7272
item.workflow_state = 'unpublished' if item.new_record? || item.deleted?

spec/models/content_migration/course_copy_spec.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,5 +591,46 @@
591591
new_topic = @copy_to.discussion_topics.where(:migration_id => mig_id(topic)).first
592592
expect(new_topic.message).to match(Regexp.new("/courses/#{@copy_to.id}/files/folder/#{folder.name}"))
593593
end
594+
595+
it "should not desync imported module item published status with existing content" do
596+
asmnt = @copy_from.assignments.create!(:title => "some assignment")
597+
page = @copy_from.wiki.wiki_pages.create!(:title => "some page")
598+
599+
run_course_copy
600+
601+
new_asmnt = @copy_to.assignments.where(:migration_id => mig_id(asmnt)).first
602+
new_asmnt.unpublish!
603+
604+
new_page = @copy_to.wiki.wiki_pages.where(:migration_id => mig_id(page)).first
605+
new_page.unpublish!
606+
607+
mod1 = @copy_from.context_modules.create!(:name => "some module")
608+
tag = mod1.add_item({:id => asmnt.id, :type => 'assignment', :indent => 1})
609+
tag2 = mod1.add_item({:id => page.id, :type => 'wiki_page', :indent => 1})
610+
611+
@cm.copy_options = {:all_context_modules => "1"}
612+
@cm.save!
613+
run_course_copy
614+
615+
new_tag = @copy_to.context_module_tags.where(:migration_id => mig_id(tag)).first
616+
expect(new_tag).to be_unpublished
617+
618+
new_tag2 = @copy_to.context_module_tags.where(:migration_id => mig_id(tag2)).first
619+
expect(new_tag2).to be_unpublished
620+
end
621+
622+
it "should copy over published tableless module items" do
623+
mod = @copy_from.context_modules.create!(:name => "some module")
624+
tag1 = mod.add_item({ :title => 'Example 1', :type => 'external_url', :url => 'http://derp.derp/something' })
625+
tag1.publish!
626+
tag2 = mod.add_item({ :title => 'Example 2', :type => 'external_url', :url => 'http://derp.derp/something2' })
627+
628+
run_course_copy
629+
630+
new_tag1 = @copy_to.context_module_tags.where(:migration_id => mig_id(tag1)).first
631+
new_tag2 = @copy_to.context_module_tags.where(:migration_id => mig_id(tag2)).first
632+
expect(new_tag1).to be_published
633+
expect(new_tag2).to be_unpublished
634+
end
594635
end
595636
end

0 commit comments

Comments
 (0)