diff --git a/app/models/discussion_topic.rb b/app/models/discussion_topic.rb index a47680dc974..c74fc244648 100644 --- a/app/models/discussion_topic.rb +++ b/app/models/discussion_topic.rb @@ -37,7 +37,7 @@ class DiscussionTopic < ActiveRecord::Base include LockedFor restrict_columns :content, [:title, :message] - restrict_columns :settings, [:delayed_post_at, :require_initial_post, :discussion_type, + restrict_columns :settings, [:delayed_post_at, :require_initial_post, :discussion_type, :assignment_id, :lock_at, :pinned, :locked, :allow_rating, :only_graders_can_rate, :sort_by_rating] restrict_columns :state, [:workflow_state] restrict_assignment_columns @@ -272,7 +272,15 @@ class DiscussionTopic < ActiveRecord::Base end if @old_assignment_id Assignment.where(:id => @old_assignment_id, :context_id => self.context_id, :context_type => self.context_type, :submission_types => 'discussion_topic').update_all(:workflow_state => 'deleted', :updated_at => Time.now.utc) - ContentTag.delete_for(Assignment.find(@old_assignment_id)) if @old_assignment_id + old_assignment = Assignment.find(@old_assignment_id) + ContentTag.delete_for(old_assignment) + # prevent future syncs from recreating the deleted assignment + if is_child_content? + old_assignment.submission_types = 'none' + context.master_course_subscriptions.each do |sub| + sub.create_content_tag_for!(old_assignment, :downstream_changes => ['workflow_state']) + end + end elsif self.assignment && @saved_by != :assignment && !self.root_topic_id deleted_assignment = self.assignment.deleted? self.sync_assignment diff --git a/spec/models/master_courses/master_migration_spec.rb b/spec/models/master_courses/master_migration_spec.rb index 84cd88182ae..d3cd7909132 100644 --- a/spec/models/master_courses/master_migration_spec.rb +++ b/spec/models/master_courses/master_migration_spec.rb @@ -1133,6 +1133,36 @@ describe MasterCourses::MasterMigration do expect(copied_topic_assmt.reload.due_at.to_i).to eq new_master_due_at.to_i end + it "allows a minion course's change of the graded status of a discussion topic to stick" do + @copy_to = course_factory + sub = @template.add_child_course!(@copy_to) + + topic = @copy_from.discussion_topics.new + topic.assignment = @copy_from.assignments.build(:due_at => 1.month.from_now) + topic.save! + run_master_migration + + topic_to = @copy_to.discussion_topics.where(:migration_id => mig_id(topic)).take + assignment_to = topic_to.assignment + topic_to.assignment = nil + topic_to.save! + + expect(assignment_to.reload).to be_deleted + topic_tag = MasterCourses::ChildContentTag.where(content_type: 'DiscussionTopic', content_id: topic_to.id).take + expect(topic_tag.downstream_changes).to include 'assignment_id' + assign_tag = MasterCourses::ChildContentTag.where(content_id: 'Assignment', content_id: assignment_to.id).take + expect(assign_tag.downstream_changes).to include 'workflow_state' + + Timecop.travel(1.hour.from_now) do + topic.message = 'content updated' + topic.save! + end + run_master_migration + + expect(topic_to.reload.assignment).to be_nil + expect(assignment_to.reload).to be_deleted + end + it "should ignore course settings on selective export unless requested" do @copy_to = course_factory @sub = @template.add_child_course!(@copy_to)