separate announcements from discussion topics in import/export
test plan: * create a course with announcements * for both: - exporting and re-importing, and - course copying with the "select content" box checked, confirm that: - the selective content form lists the announcements to import under "Announcements" and not "Discussion Topics" - the selected announcements are actually imported as expected fixes #CNVS-7242 Change-Id: I647544232dd1d88305db2bc558e20df0716d3c30 Reviewed-on: https://gerrit.instructure.com/22823 Reviewed-by: Bracken Mosbacker <bracken@instructure.com> Product-Review: Bracken Mosbacker <bracken@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Clare Strong <clare@instructure.com>
This commit is contained in:
parent
a91b982f18
commit
f81f5af171
|
@ -114,12 +114,12 @@ class ContentExport < ActiveRecord::Base
|
|||
# checked should be exported or not.
|
||||
#
|
||||
# Returns: bool
|
||||
def export_object?(obj)
|
||||
def export_object?(obj, asset_type=nil)
|
||||
return false unless obj
|
||||
return true if selected_content.empty?
|
||||
return true if is_set?(selected_content[:everything])
|
||||
|
||||
asset_type = obj.class.table_name
|
||||
asset_type ||= obj.class.table_name
|
||||
return true if is_set?(selected_content["all_#{asset_type}"])
|
||||
|
||||
return false unless selected_content[asset_type]
|
||||
|
|
|
@ -863,7 +863,8 @@ class DiscussionTopic < ActiveRecord::Base
|
|||
context = Group.find_by_context_id_and_context_type_and_migration_id(migration.context.id, migration.context.class.to_s, topic['group_id']) if topic['group_id']
|
||||
context ||= migration.context
|
||||
if context
|
||||
if migration.import_object?("discussion_topics", topic['migration_id']) || migration.import_object?("topics", topic['migration_id'])
|
||||
if migration.import_object?("discussion_topics", topic['migration_id']) || migration.import_object?("topics", topic['migration_id']) ||
|
||||
(topic['type'] == 'announcement' && migration.import_object?("announcements", topic['migration_id']))
|
||||
begin
|
||||
import_from_migration(topic.merge({:topic_entries_to_import => topic_entries_to_import}), context)
|
||||
rescue
|
||||
|
|
|
@ -42,6 +42,7 @@ module Canvas::Migration::Helpers
|
|||
course_data = Rails.cache.fetch(['migration_selective_cache', @migration.shard, @migration].cache_key, :expires_in => 5.minutes) do
|
||||
att = @migration.overview_attachment.open
|
||||
data = JSON.parse(att.read)
|
||||
data = separate_announcements(data)
|
||||
data['attachments'] ||= data['file_map'] ? data['file_map'].values : nil
|
||||
data['quizzes'] ||= data['assessments']
|
||||
data['context_modules'] ||= data['modules']
|
||||
|
@ -253,6 +254,17 @@ module Canvas::Migration::Helpers
|
|||
end
|
||||
end
|
||||
|
||||
def separate_announcements(course_data)
|
||||
return course_data unless course_data['discussion_topics']
|
||||
|
||||
announcements, topics = course_data['discussion_topics'].partition{|topic_hash| topic_hash['type'] == 'announcement'}
|
||||
|
||||
if announcements.any?
|
||||
course_data['announcements'] ||= []
|
||||
course_data['announcements'] += announcements
|
||||
course_data['discussion_topics'] = topics
|
||||
end
|
||||
course_data
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -334,11 +334,16 @@ module MigratorHelper
|
|||
end
|
||||
if @course[:discussion_topics]
|
||||
@overview[:discussion_topics] = []
|
||||
@overview[:announcements] = []
|
||||
@course[:discussion_topics].each do |t|
|
||||
topic = {}
|
||||
if t[:type] == 'announcement'
|
||||
@overview[:announcements] << topic
|
||||
else
|
||||
@overview[:discussion_topics] << topic
|
||||
end
|
||||
topic[:title] = t[:title]
|
||||
topic[:topic_type] = t[:topic_type]
|
||||
topic[:topic_type] = t[:type]
|
||||
topic[:migration_id] = t[:migration_id]
|
||||
topic[:error_message] = t[:error_message] if t[:error_message]
|
||||
end
|
||||
|
|
|
@ -98,8 +98,8 @@ module CC
|
|||
@content_export ? @content_export.id : nil
|
||||
end
|
||||
|
||||
def export_object?(obj)
|
||||
@content_export ? @content_export.export_object?(obj) : true
|
||||
def export_object?(obj, asset_type=nil)
|
||||
@content_export ? @content_export.export_object?(obj, asset_type) : true
|
||||
end
|
||||
|
||||
def export_symbol?(obj)
|
||||
|
|
|
@ -20,7 +20,7 @@ module CC
|
|||
|
||||
def add_topics
|
||||
@course.discussion_topics.active.each do |topic|
|
||||
next unless export_object?(topic) || export_object?(topic.assignment)
|
||||
next unless export_object?(topic) || export_object?(topic.assignment) || (topic.is_announcement && export_object?(topic, 'announcements'))
|
||||
|
||||
title = topic.title rescue I18n.t('course_exports.unknown_titles.topic', "Unknown topic")
|
||||
|
||||
|
|
|
@ -122,6 +122,18 @@ describe Canvas::Migration::Helpers::SelectiveContentFormatter do
|
|||
|
||||
end
|
||||
|
||||
it "should show announcements separate from discussion topics" do
|
||||
@migration.stubs(:read).returns({
|
||||
'discussion_topics' => [
|
||||
{'title' => 'a1', 'migration_id' => 'a1'},
|
||||
{'title' => 'a2', 'migration_id' => 'a1', 'type' => 'announcement'},
|
||||
]}.to_json)
|
||||
@formatter.get_content_list('discussion_topics').count.should == 1
|
||||
@formatter.get_content_list('discussion_topics').first[:title].should == 'a1'
|
||||
@formatter.get_content_list('announcements').count.should == 1
|
||||
@formatter.get_content_list('announcements').first[:title].should == 'a2'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "course copy" do
|
||||
|
|
|
@ -291,6 +291,19 @@ describe "Standard Common Cartridge importing" do
|
|||
|
||||
@course.attachments.count.should == 0
|
||||
end
|
||||
|
||||
it "should import discussion_topics with 'announcement' type if announcements are selected" do
|
||||
@course = course
|
||||
@migration = ContentMigration.create(:context => @course)
|
||||
@migration.migration_settings[:migration_ids_to_import] = {
|
||||
:copy => {"announcements" => {"I_00006_R" => true}, "everything" => "0"}}.with_indifferent_access
|
||||
|
||||
@course_data['discussion_topics'].find{|topic| topic['migration_id'] == 'I_00006_R'}['type'] = 'announcement'
|
||||
|
||||
@course.import_from_migration(@course_data, nil, @migration)
|
||||
|
||||
@course.announcements.count.should == 1
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -913,6 +913,19 @@ describe ContentMigration do
|
|||
@copy_to.discussion_topics.find_by_migration_id(mig_id(topic)).should_not be_nil
|
||||
end
|
||||
|
||||
it "should copy selected announcements" do
|
||||
ann = @copy_from.announcements.create!(:message => "howdy", :title => "announcement title")
|
||||
|
||||
@cm.copy_options = {
|
||||
:announcements => {mig_id(ann) => "1"},
|
||||
}
|
||||
@cm.save!
|
||||
|
||||
run_course_copy
|
||||
|
||||
@copy_to.announcements.find_by_migration_id(mig_id(ann)).should_not be_nil
|
||||
end
|
||||
|
||||
it "should not copy deleted assignment attached to topic" do
|
||||
topic = @copy_from.discussion_topics.build(:title => "topic")
|
||||
assignment = @copy_from.assignments.build(:submission_types => 'discussion_topic', :title => topic.title)
|
||||
|
|
Loading…
Reference in New Issue