move deleted enrollments when cross listing sections
fixes CNVS-13828 test plan - prior to checking out patch set - enroll a user in a section - delete the enrollment - cross list the section - attempt to add user to sections new course - it should fail - checkout patch set and run migration - attempt to add user to sections new course - it should succeed - enroll a user in a section - delete the enrollment - cross list the section - attempt to add user to sections new course - it should work (it will restore the old enrollment) - enroll a user in a cross listed section - delete the enrollment - uncross list the section - attempt to add the user to the sections current course - it should work (it will restore the old enrollment) Change-Id: Ib397f96b0761d87bf6f9fb11ffc978012f0f5b39 Reviewed-on: https://gerrit.instructure.com/37036 Reviewed-by: Cody Cutrer <cody@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Jeremy Putnam <jeremyp@instructure.com> Product-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
parent
1ec7783538
commit
fe8e121ee3
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 2013 Instructure, Inc.
|
||||
# Copyright (C) 2011 - 2014 Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
|
@ -180,15 +180,15 @@ class CourseSection < ActiveRecord::Base
|
|||
old_course.course_sections.reset
|
||||
course.course_sections.reset
|
||||
assignment_overrides.active.destroy_all
|
||||
user_ids = self.enrollments.map(&:user_id).uniq
|
||||
user_ids = self.all_enrollments.map(&:user_id).uniq
|
||||
|
||||
old_course_is_unrelated = old_course.id != self.course_id && old_course.id != self.nonxlist_course_id
|
||||
if self.root_account_id_changed?
|
||||
self.save!
|
||||
self.enrollments.update_all :course_id => course, :root_account_id => self.root_account_id
|
||||
self.all_enrollments.update_all :course_id => course, :root_account_id => self.root_account_id
|
||||
else
|
||||
self.save!
|
||||
self.enrollments.update_all :course_id => course
|
||||
self.all_enrollments.update_all :course_id => course
|
||||
end
|
||||
User.send_later_if_production(:update_account_associations, user_ids) if old_course.account_id != course.account_id && !User.skip_updating_account_associations?
|
||||
if old_course.id != self.course_id && old_course.id != self.nonxlist_course_id
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
class FixInvalidCourseIdsForEnrollments < ActiveRecord::Migration
|
||||
tag :postdeploy
|
||||
disable_ddl_transaction!
|
||||
|
||||
def self.up
|
||||
DataFixup::FixInvalidCourseIdsOnEnrollments.send_later_if_production(:run)
|
||||
end
|
||||
|
||||
def self.down
|
||||
end
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
module DataFixup::FixInvalidCourseIdsOnEnrollments
|
||||
def self.run
|
||||
Enrollment.joins(:course_section).
|
||||
where("course_sections.course_id<>enrollments.course_id").
|
||||
includes(:course_section).find_each do |e|
|
||||
Enrollment.where(id: e).update_all(course_id: e.course_section.course_id)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (C) 2011 - 2013 Instructure, Inc.
|
||||
# Copyright (C) 2011 - 2014 Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
|
@ -159,6 +159,8 @@ describe CourseSection, "moving to new course" do
|
|||
e = course1.enroll_user(u, 'StudentEnrollment', :section => cs)
|
||||
e.workflow_state = 'active'
|
||||
e.save!
|
||||
#should also move deleted enrollments
|
||||
e.destroy
|
||||
course1.reload
|
||||
course2.reload
|
||||
course3.workflow_state = 'active'
|
||||
|
|
Loading…
Reference in New Issue