Add new planner fields for course copy

Closes FALCOR-241

Test Plan:
* As an admin
* In a course with the "Student Planner" feature
  flag enabled
* With discussion topics and wiki pages that have
  been marked as "Add to student to-do" and have
  corresponding todo dates
* Run a course copy for the discussion topics and
  wiki pages
* The newly copied topics and pages should have
  the todo date set the same as the original

Change-Id: Ib1ceb3ed87351b2fac5b68c31b4d3d6066cf6688
Reviewed-on: https://gerrit.instructure.com/114827
Tested-by: Jenkins
Reviewed-by: Mysti Sadler <mysti@instructure.com>
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
QA-Review: Dan Sasaki <dsasaki@instructure.com>
Product-Review: Dan Minkevitch <dan@instructure.com>
This commit is contained in:
Dan Minkevitch 2017-06-08 16:28:35 -07:00
parent 7f37e999ff
commit 1218033b3e
10 changed files with 31 additions and 1 deletions

View File

@ -200,6 +200,7 @@ module Importers
event.saved_by = :after_migration
event.delayed_post_at = shift_date(event.delayed_post_at, shift_options)
event.lock_at = shift_date(event.lock_at, shift_options)
event.todo_date = shift_date(event.todo_date, shift_options)
event.save_without_broadcasting
end
@ -236,6 +237,12 @@ module Importers
event.save
end
migration.imported_migration_items_by_class(WikiPage).each do |event|
event.reload
event.todo_date = shift_date(event.todo_date, shift_options)
event.save_without_broadcasting
end
course.set_course_dates_if_blank(shift_options)
else
(migration.imported_migration_items_by_class(Announcement) +

View File

@ -92,7 +92,8 @@ module Importers
def run
return unless options.importable?
[:migration_id, :title, :discussion_type, :position, :pinned,
:require_initial_post, :allow_rating, :only_graders_can_rate, :sort_by_rating].each do |attr|
:require_initial_post, :allow_rating, :only_graders_can_rate,
:sort_by_rating].each do |attr|
next if options[attr].nil? && item.class.columns_hash[attr.to_s].type == :boolean
item.send("#{attr}=", options[attr])
end
@ -106,6 +107,7 @@ module Importers
item.delayed_post_at = Canvas::Migration::MigratorHelper.get_utc_time_from_timestamp(options.delayed_post_at)
item.lock_at = Canvas::Migration::MigratorHelper.get_utc_time_from_timestamp(options[:lock_at])
item.todo_date = Canvas::Migration::MigratorHelper.get_utc_time_from_timestamp(options[:todo_date])
item.last_reply_at = nil if item.new_record?
if options[:workflow_state].present?

View File

@ -96,6 +96,7 @@ module Importers
item.set_as_front_page! if !!hash[:front_page] && context.wiki.has_no_front_page
item.migration_id = hash[:migration_id]
item.todo_date = Canvas::Migration::MigratorHelper.get_utc_time_from_timestamp(hash[:todo_date])
migration.add_imported_item(item)

View File

@ -67,6 +67,7 @@ module CC::Importer::Canvas
wf_state = get_node_val(meta_doc, 'workflow_state')
topic['workflow_state'] = wf_state if wf_state.present?
topic['group_category'] = get_node_val(meta_doc, 'group_category')
topic['todo_date'] = get_time_val(meta_doc, 'todo_date')
%w(has_group_category allow_rating only_graders_can_rate sort_by_rating).each do |setting|
get_bool_val(meta_doc, setting).tap { |val| topic[setting] = val unless val.nil? }
end

View File

@ -47,6 +47,7 @@ module CC::Importer::Canvas
wiki[:text] = body
wiki[:url_name] = wiki_name
wiki[:assignment] = nil
wiki[:todo_date] = meta['todo_date']
if asg_id = meta['assignment_identifier']
wiki[:assignment] = { migration_id: asg_id }
end

View File

@ -128,6 +128,7 @@ module CC
doc.allow_rating topic.allow_rating
doc.only_graders_can_rate topic.only_graders_can_rate
doc.sort_by_rating topic.sort_by_rating
doc.todo_date topic.todo_date
if topic.assignment && !topic.assignment.deleted?
assignment_migration_id = create_key(topic.assignment)
doc.assignment(:identifier=>assignment_migration_id) do |a|

View File

@ -42,6 +42,7 @@ module CC
meta_fields[:module_locked] = page.locked_by_module_item?(@user, deep_check_if_needed: true).present?
meta_fields[:assignment_identifier] =
page.for_assignment? ? create_key(page.assignment) : nil
meta_fields[:todo_date] = page.todo_date
File.open(path, 'w') do |file|
file << @html_exporter.html_page(page.body, page.title, meta_fields)

View File

@ -178,6 +178,7 @@
<xs:element name="allow_rating" type="xs:boolean" minOccurs="0"/>
<xs:element name="only_graders_can_rate" type="xs:boolean" minOccurs="0"/>
<xs:element name="sort_by_rating" type="xs:boolean" minOccurs="0"/>
<xs:element name="todo_date" type="xs:dateTime" minOccurs="0"/>
<xs:element name="discussion_type" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">

View File

@ -34,6 +34,8 @@ describe ContentMigration do
topic = @copy_from.discussion_topics.create!(:title => "topic", :message => "<p>bloop</p>",
:pinned => true, :discussion_type => "threaded",
:require_initial_post => true)
todo_date = 1.day.from_now
topic.todo_date = todo_date
topic.posted_at = 2.days.ago
topic.position = 2
topic.save!
@ -49,6 +51,7 @@ describe ContentMigration do
expect(new_topic.last_reply_at).to be_nil
expect(new_topic.allow_rating).to eq false
expect(new_topic.posted_at).to be_nil
expect(new_topic.todo_date.to_i).to eq todo_date.to_i
end
it "copies rating settings" do

View File

@ -21,6 +21,18 @@ describe ContentMigration do
context "course copy wiki" do
include_examples "course copy"
it "should copy wiki page attributes" do
page = @copy_from.wiki.wiki_pages.create!(:title => "title", :body => "<p>butter</p>",
:editing_roles => "teachers", :todo_date => Time.zone.now)
run_course_copy
page_to = @copy_to.wiki.wiki_pages.where(migration_id: mig_id(page)).first
attrs = [:title, :body, :editing_roles, :todo_date]
expect(page.attributes.slice(*attrs)).to eq page_to.attributes.slice(*attrs)
end
it "should reset user on re-import" do
page = @copy_from.wiki.wiki_pages.create!(:title => "reset me", :body => "<p>blah</p>")