renaming last_course to nonxlist_course and changing crosslisting semantics
Change-Id: I0b017d4506c54151f34c50c28754b6e1c1a46691 Reviewed-on: https://gerrit.instructure.com/3171 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Whitmer <brian@instructure.com> Reviewed-by: Zach Wily <zach@instructure.com>
This commit is contained in:
parent
9038054100
commit
33854cbc4b
|
@ -130,7 +130,7 @@ class ContentImportsController < ApplicationController
|
|||
end
|
||||
else
|
||||
if request.format != :json
|
||||
@possible_courses = (@current_user.available_courses + @context.course_sections.active.map(&:last_course)).compact.select{|c| c.grants_right?(@current_user, session, :manage) }
|
||||
@possible_courses = (@current_user.available_courses + @context.course_sections.active.map(&:nonxlist_course)).compact.select{|c| c.grants_right?(@current_user, session, :manage) }
|
||||
@possible_courses += @domain_root_account.all_courses if @domain_root_account.grants_right?(@current_user, session, :manage)
|
||||
@possible_courses -= [@context]
|
||||
@possible_courses = @possible_courses.compact.uniq
|
||||
|
|
|
@ -23,7 +23,7 @@ class CourseSection < ActiveRecord::Base
|
|||
attr_protected :sis_source_id, :sis_batch_id, :course_id, :abstract_course_id,
|
||||
:root_account_id, :enrollment_term_id, :sis_cross_listed_section_id, :sis_cross_listed_section_sis_batch_id
|
||||
belongs_to :course
|
||||
belongs_to :last_course, :class_name => 'Course'
|
||||
belongs_to :nonxlist_course, :class_name => 'Course'
|
||||
belongs_to :root_account, :class_name => 'Account'
|
||||
belongs_to :sis_cross_listed_section
|
||||
belongs_to :abstract_course
|
||||
|
@ -95,18 +95,42 @@ class CourseSection < ActiveRecord::Base
|
|||
|
||||
def move_to_course(course)
|
||||
return self if self.course == course
|
||||
self.last_course = self.course unless self.last_course == self.course
|
||||
self.course = course
|
||||
root_account_change = (self.root_account != course.root_account)
|
||||
self.root_account = course.root_account if root_account_change
|
||||
self.save!
|
||||
user_ids = self.enrollments.map(&:user_id).uniq
|
||||
if root_account_change
|
||||
self.enrollments.update_all :root_account_id => self.root_account.id
|
||||
User.send_later_if_production(:update_account_associations, self.enrollments.map{|e|e.user.id})
|
||||
self.enrollments.update_all :course_id => course.id, :root_account_id => self.root_account.id
|
||||
User.send_later_if_production(:update_account_associations, user_ids)
|
||||
else
|
||||
self.enrollments.update_all :course_id => course.id
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
def crosslist_to_course(course)
|
||||
return self if self.course == course
|
||||
unless self.nonxlist_course
|
||||
self.nonxlist_course = self.course
|
||||
self.account = self.course.account
|
||||
self.save!
|
||||
end
|
||||
self.move_to_course(course)
|
||||
end
|
||||
|
||||
def uncrosslist
|
||||
return unless self.nonxlist_course
|
||||
self.move_to_course(self.nonxlist_course)
|
||||
self.nonxlist_course = nil
|
||||
self.account = nil
|
||||
self.save!
|
||||
end
|
||||
|
||||
def crosslisted?
|
||||
return !!self.nonxlist_course
|
||||
end
|
||||
|
||||
def destroy_course_if_no_more_sections
|
||||
if self.deleted? && self.course.course_sections.active.empty?
|
||||
self.course.destroy
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
class RenameLastCourseToNonxlistCourseInCourseSection < ActiveRecord::Migration
|
||||
def self.up
|
||||
rename_column :course_sections, :last_course_id, :nonxlist_course_id
|
||||
end
|
||||
|
||||
def self.down
|
||||
rename_column :course_sections, :nonxlist_course_id, :last_course_id
|
||||
end
|
||||
end
|
|
@ -55,18 +55,35 @@ module SIS
|
|||
end
|
||||
|
||||
name = row['name']
|
||||
section = course.course_sections.find_by_sis_source_id(row['section_id'])
|
||||
section = CourseSection.find_by_root_account_id_and_sis_source_id(@root_account.id, row['section_id'])
|
||||
section ||= course.course_sections.find_by_sis_source_id(row['section_id'])
|
||||
section ||= course.course_sections.find_by_name(name)
|
||||
section ||= course.course_sections.new
|
||||
section.root_account_id = @root_account.id
|
||||
|
||||
section.account = Account.find_by_root_account_id_and_sis_source_id(@root_account.id, row['account_id'])
|
||||
section.account ||= Account.find_by_root_account_id_and_sis_source_id(@root_account.id, row['account_id'])
|
||||
|
||||
# only update the name on new records, and ones that haven't been changed since the last sis import
|
||||
if section.new_record? || (section.sis_name && section.sis_name == section.name)
|
||||
section.name = section.sis_name = row['name']
|
||||
end
|
||||
|
||||
# update the course id if necessary
|
||||
if section.course != course
|
||||
if section.nonxlist_course
|
||||
# this section is crosslisted
|
||||
if section.nonxlist_course != course
|
||||
# but the course id we were given didn't match the crosslist info
|
||||
# we have, so, uncrosslist and move
|
||||
section.uncrosslist
|
||||
section.move_to_course course
|
||||
end
|
||||
else
|
||||
# this section isn't crosslisted and lives on the wrong course. move
|
||||
section.move_to_course course
|
||||
end
|
||||
end
|
||||
|
||||
section.sis_source_id = row['section_id']
|
||||
section.sis_batch_id = @batch.id if @batch
|
||||
if row['status'] =~ /active/i
|
||||
|
|
|
@ -71,11 +71,8 @@ module SIS
|
|||
next
|
||||
end
|
||||
|
||||
section.account ||= section.course.account
|
||||
section.save
|
||||
|
||||
begin
|
||||
section.move_to_course course
|
||||
section.crosslist_to_course course
|
||||
rescue => e
|
||||
add_warning(csv, "An active cross-listing failed: #{e}")
|
||||
next
|
||||
|
@ -87,13 +84,8 @@ module SIS
|
|||
next
|
||||
end
|
||||
|
||||
section.account = nil
|
||||
section.save
|
||||
|
||||
begin
|
||||
section.move_to_course section.last_course
|
||||
section.last_course = nil
|
||||
section.save
|
||||
section.uncrosslist
|
||||
rescue => e
|
||||
add_warning(csv, "A deleted cross-listing failed: #{e}")
|
||||
next
|
||||
|
|
|
@ -583,7 +583,7 @@ describe SIS::SisCsv do
|
|||
course = @account.courses.find_by_sis_source_id("C001")
|
||||
s1 = course.course_sections.find_by_sis_source_id("S001")
|
||||
s1.should_not be_nil
|
||||
s1.last_course.should be_nil
|
||||
s1.nonxlist_course.should be_nil
|
||||
s1.account.should be_nil
|
||||
course.course_sections.find_by_sis_source_id("S002").should_not be_nil
|
||||
@account.courses.find_by_sis_source_id("X001").should be_nil
|
||||
|
@ -600,7 +600,7 @@ describe SIS::SisCsv do
|
|||
course = @account.courses.find_by_sis_source_id("C001")
|
||||
s1 = xlist_course.course_sections.find_by_sis_source_id("S001")
|
||||
s1.should_not be_nil
|
||||
s1.last_course.should eql(course)
|
||||
s1.nonxlist_course.should eql(course)
|
||||
s1.account.should eql(course.account)
|
||||
course.course_sections.find_by_sis_source_id("S001").should be_nil
|
||||
course.course_sections.find_by_sis_source_id("S002").should_not be_nil
|
||||
|
@ -618,7 +618,7 @@ describe SIS::SisCsv do
|
|||
xlist_course.course_sections.find_by_sis_source_id("S001").should be_nil
|
||||
s1 = course.course_sections.find_by_sis_source_id("S001")
|
||||
s1.should_not be_nil
|
||||
s1.last_course.should be_nil
|
||||
s1.nonxlist_course.should be_nil
|
||||
s1.account.should be_nil
|
||||
course.course_sections.find_by_sis_source_id("S002").should_not be_nil
|
||||
|
||||
|
@ -647,7 +647,7 @@ describe SIS::SisCsv do
|
|||
course = @account.courses.find_by_sis_source_id("C001")
|
||||
s1 = course.course_sections.find_by_sis_source_id("S001")
|
||||
s1.should_not be_nil
|
||||
s1.last_course.should be_nil
|
||||
s1.nonxlist_course.should be_nil
|
||||
s1.account.should be_nil
|
||||
course.course_sections.find_by_sis_source_id("S002").should_not be_nil
|
||||
@account.courses.find_by_sis_source_id("X001").should_not be_nil
|
||||
|
@ -664,7 +664,7 @@ describe SIS::SisCsv do
|
|||
course = @account.courses.find_by_sis_source_id("C001")
|
||||
s1 = xlist_course.course_sections.find_by_sis_source_id("S001")
|
||||
s1.should_not be_nil
|
||||
s1.last_course.should eql(course)
|
||||
s1.nonxlist_course.should eql(course)
|
||||
s1.account.should eql(course.account)
|
||||
course.course_sections.find_by_sis_source_id("S001").should be_nil
|
||||
course.course_sections.find_by_sis_source_id("S002").should_not be_nil
|
||||
|
@ -682,7 +682,7 @@ describe SIS::SisCsv do
|
|||
xlist_course.course_sections.find_by_sis_source_id("S001").should be_nil
|
||||
s1 = course.course_sections.find_by_sis_source_id("S001")
|
||||
s1.should_not be_nil
|
||||
s1.last_course.should be_nil
|
||||
s1.nonxlist_course.should be_nil
|
||||
s1.account.should be_nil
|
||||
course.course_sections.find_by_sis_source_id("S002").should_not be_nil
|
||||
|
||||
|
@ -744,7 +744,7 @@ describe SIS::SisCsv do
|
|||
course = @account.courses.find_by_sis_source_id("C001")
|
||||
s1 = xlist_course.course_sections.find_by_sis_source_id("S001")
|
||||
s1.should_not be_nil
|
||||
s1.last_course.should eql(course)
|
||||
s1.nonxlist_course.should eql(course)
|
||||
s1.account.should eql(course.account)
|
||||
end
|
||||
end
|
||||
|
@ -769,7 +769,7 @@ describe SIS::SisCsv do
|
|||
course = @account.courses.find_by_sis_source_id("C001")
|
||||
s1 = xlist_course.course_sections.find_by_sis_source_id("S001")
|
||||
s1.should_not be_nil
|
||||
s1.last_course.should eql(course)
|
||||
s1.nonxlist_course.should eql(course)
|
||||
s1.account.should eql(course.account)
|
||||
|
||||
3.times do
|
||||
|
@ -783,11 +783,148 @@ describe SIS::SisCsv do
|
|||
course = @account.courses.find_by_sis_source_id("C001")
|
||||
s1 = course.course_sections.find_by_sis_source_id("S001")
|
||||
s1.should_not be_nil
|
||||
s1.last_course.should be_nil
|
||||
s1.nonxlist_course.should be_nil
|
||||
s1.account.should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
it 'should be able to move around a section and then uncrosslist back to the original' do
|
||||
process_csv_data(
|
||||
"course_id,short_name,long_name,account_id,term_id,status",
|
||||
"C001,TC 101,Test Course 101,,,active"
|
||||
)
|
||||
process_csv_data(
|
||||
"section_id,course_id,name,start_date,end_date,status",
|
||||
"S001,C001,Sec1,2011-1-05 00:00:00,2011-4-14 00:00:00,active"
|
||||
)
|
||||
3.times do |i|
|
||||
importer = process_csv_data(
|
||||
"xlist_course_id,section_id,status",
|
||||
"X00#{i},S001,active"
|
||||
)
|
||||
importer.warnings.should == []
|
||||
importer.errors.should == []
|
||||
|
||||
xlist_course = @account.courses.find_by_sis_source_id("X00#{i}")
|
||||
course = @account.courses.find_by_sis_source_id("C001")
|
||||
s1 = xlist_course.course_sections.find_by_sis_source_id("S001")
|
||||
s1.should_not be_nil
|
||||
s1.nonxlist_course.should eql(course)
|
||||
s1.course.should eql(xlist_course)
|
||||
s1.account.should eql(course.account)
|
||||
s1.crosslisted?.should be_true
|
||||
end
|
||||
importer = process_csv_data(
|
||||
"xlist_course_id,section_id,status",
|
||||
"X101,S001,deleted"
|
||||
)
|
||||
importer.warnings.should == []
|
||||
importer.errors.should == []
|
||||
|
||||
course = @account.courses.find_by_sis_source_id("C001")
|
||||
s1 = course.course_sections.find_by_sis_source_id("S001")
|
||||
s1.should_not be_nil
|
||||
s1.nonxlist_course.should be_nil
|
||||
s1.course.should eql(course)
|
||||
s1.account.should be_nil
|
||||
s1.crosslisted?.should be_false
|
||||
end
|
||||
|
||||
it 'should be able to handle additional section updates and not screw up the crosslisting' do
|
||||
process_csv_data(
|
||||
"course_id,short_name,long_name,account_id,term_id,status",
|
||||
"C001,TC 101,Test Course 101,,,active"
|
||||
)
|
||||
process_csv_data(
|
||||
"section_id,course_id,name,start_date,end_date,status",
|
||||
"S001,C001,Sec1,2011-1-05 00:00:00,2011-4-14 00:00:00,active"
|
||||
)
|
||||
process_csv_data(
|
||||
"xlist_course_id,section_id,status",
|
||||
"X001,S001,active"
|
||||
)
|
||||
xlist_course = @account.courses.find_by_sis_source_id("X001")
|
||||
course = @account.courses.find_by_sis_source_id("C001")
|
||||
s1 = xlist_course.course_sections.find_by_sis_source_id("S001")
|
||||
s1.should_not be_nil
|
||||
s1.nonxlist_course.should eql(course)
|
||||
s1.course.should eql(xlist_course)
|
||||
s1.account.should eql(course.account)
|
||||
s1.crosslisted?.should be_true
|
||||
s1.name.should == "Sec1"
|
||||
process_csv_data(
|
||||
"section_id,course_id,name,start_date,end_date,status",
|
||||
"S001,C001,Sec2,2011-1-05 00:00:00,2011-4-14 00:00:00,active"
|
||||
)
|
||||
xlist_course = @account.courses.find_by_sis_source_id("X001")
|
||||
course = @account.courses.find_by_sis_source_id("C001")
|
||||
s1 = xlist_course.course_sections.find_by_sis_source_id("S001")
|
||||
s1.should_not be_nil
|
||||
s1.nonxlist_course.should eql(course)
|
||||
s1.course.should eql(xlist_course)
|
||||
s1.account.should eql(course.account)
|
||||
s1.crosslisted?.should be_true
|
||||
s1.name.should == "Sec2"
|
||||
end
|
||||
|
||||
it 'should be able to move a non-crosslisted section between courses' do
|
||||
process_csv_data(
|
||||
"course_id,short_name,long_name,account_id,term_id,status",
|
||||
"C001,TC 101,Test Course 101,,,active",
|
||||
"C002,TC 102,Test Course 102,,,active"
|
||||
)
|
||||
process_csv_data(
|
||||
"section_id,course_id,name,start_date,end_date,status",
|
||||
"S001,C001,Sec1,2011-1-05 00:00:00,2011-4-14 00:00:00,active"
|
||||
)
|
||||
course1 = @account.courses.find_by_sis_source_id("C001")
|
||||
course2 = @account.courses.find_by_sis_source_id("C002")
|
||||
s1 = course1.course_sections.find_by_sis_source_id("S001")
|
||||
s1.course.should eql(course1)
|
||||
process_csv_data(
|
||||
"section_id,course_id,name,start_date,end_date,status",
|
||||
"S001,C002,Sec1,2011-1-05 00:00:00,2011-4-14 00:00:00,active"
|
||||
)
|
||||
course1.reload
|
||||
course2.reload
|
||||
s1.reload
|
||||
s1.course.should eql(course2)
|
||||
end
|
||||
|
||||
it 'should uncrosslist a section if it is getting moved from the original course' do
|
||||
process_csv_data(
|
||||
"course_id,short_name,long_name,account_id,term_id,status",
|
||||
"C001,TC 101,Test Course 101,,,active",
|
||||
"C002,TC 102,Test Course 102,,,active"
|
||||
)
|
||||
process_csv_data(
|
||||
"section_id,course_id,name,start_date,end_date,status",
|
||||
"S001,C001,Sec1,2011-1-05 00:00:00,2011-4-14 00:00:00,active"
|
||||
)
|
||||
process_csv_data(
|
||||
"xlist_course_id,section_id,status",
|
||||
"X001,S001,active"
|
||||
)
|
||||
xlist_course = @account.courses.find_by_sis_source_id("X001")
|
||||
course1 = @account.courses.find_by_sis_source_id("C001")
|
||||
course2 = @account.courses.find_by_sis_source_id("C002")
|
||||
s1 = xlist_course.course_sections.find_by_sis_source_id("S001")
|
||||
s1.should_not be_nil
|
||||
s1.nonxlist_course.should eql(course1)
|
||||
s1.course.should eql(xlist_course)
|
||||
s1.account.should eql(course1.account)
|
||||
s1.crosslisted?.should be_true
|
||||
process_csv_data(
|
||||
"section_id,course_id,name,start_date,end_date,status",
|
||||
"S001,C002,Sec1,2011-1-05 00:00:00,2011-4-14 00:00:00,active"
|
||||
)
|
||||
s1.reload
|
||||
s1.nonxlist_course.should be_nil
|
||||
s1.course.should eql(course2)
|
||||
s1.account.should be_nil
|
||||
s1.crosslisted?.should be_false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -25,6 +25,7 @@ describe CourseSection, "moving to new course" do
|
|||
account2 = Account.create!(:name => "2")
|
||||
course1 = account1.courses.create!
|
||||
course2 = account2.courses.create!
|
||||
course3 = account2.courses.create!
|
||||
cs = course1.course_sections.create!
|
||||
u = User.create!
|
||||
u.register!
|
||||
|
@ -35,8 +36,9 @@ describe CourseSection, "moving to new course" do
|
|||
|
||||
course1.course_sections.find_by_id(cs.id).should_not be_nil
|
||||
course2.course_sections.find_by_id(cs.id).should be_nil
|
||||
course3.course_sections.find_by_id(cs.id).should be_nil
|
||||
e.root_account.should eql(account1)
|
||||
cs.last_course.should be_nil
|
||||
e.course.should eql(course1)
|
||||
|
||||
cs.move_to_course(course2)
|
||||
course1.reload
|
||||
|
@ -46,8 +48,21 @@ describe CourseSection, "moving to new course" do
|
|||
|
||||
course1.course_sections.find_by_id(cs.id).should be_nil
|
||||
course2.course_sections.find_by_id(cs.id).should_not be_nil
|
||||
course3.course_sections.find_by_id(cs.id).should be_nil
|
||||
e.root_account.should eql(account2)
|
||||
cs.last_course.should eql(course1)
|
||||
e.course.should eql(course2)
|
||||
|
||||
cs.move_to_course(course3)
|
||||
course1.reload
|
||||
course2.reload
|
||||
cs.reload
|
||||
e.reload
|
||||
|
||||
course1.course_sections.find_by_id(cs.id).should be_nil
|
||||
course2.course_sections.find_by_id(cs.id).should be_nil
|
||||
course3.course_sections.find_by_id(cs.id).should_not be_nil
|
||||
e.root_account.should eql(account2)
|
||||
e.course.should eql(course3)
|
||||
|
||||
cs.move_to_course(course1)
|
||||
course1.reload
|
||||
|
@ -57,8 +72,9 @@ describe CourseSection, "moving to new course" do
|
|||
|
||||
course1.course_sections.find_by_id(cs.id).should_not be_nil
|
||||
course2.course_sections.find_by_id(cs.id).should be_nil
|
||||
course3.course_sections.find_by_id(cs.id).should be_nil
|
||||
e.root_account.should eql(account1)
|
||||
cs.last_course.should eql(course2)
|
||||
e.course.should eql(course1)
|
||||
|
||||
cs.move_to_course(course1)
|
||||
course1.reload
|
||||
|
@ -68,8 +84,77 @@ describe CourseSection, "moving to new course" do
|
|||
|
||||
course1.course_sections.find_by_id(cs.id).should_not be_nil
|
||||
course2.course_sections.find_by_id(cs.id).should be_nil
|
||||
course3.course_sections.find_by_id(cs.id).should be_nil
|
||||
e.root_account.should eql(account1)
|
||||
cs.last_course.should eql(course2)
|
||||
e.course.should eql(course1)
|
||||
end
|
||||
|
||||
it "should crosslist and uncrosslist" do
|
||||
account1 = Account.create!(:name => "1")
|
||||
account2 = Account.create!(:name => "2")
|
||||
account3 = Account.create!(:name => "3")
|
||||
course1 = account1.courses.create!
|
||||
course2 = account2.courses.create!
|
||||
course3 = account3.courses.create!
|
||||
cs = course1.course_sections.create!
|
||||
u = User.create!
|
||||
u.register!
|
||||
e = course1.enroll_user(u, 'StudentEnrollment', :section => cs)
|
||||
e.workflow_state = 'active'
|
||||
e.save!
|
||||
course1.reload
|
||||
|
||||
course1.course_sections.find_by_id(cs.id).should_not be_nil
|
||||
course2.course_sections.find_by_id(cs.id).should be_nil
|
||||
course3.course_sections.find_by_id(cs.id).should be_nil
|
||||
cs.account.should be_nil
|
||||
cs.nonxlist_course.should be_nil
|
||||
e.root_account.should eql(account1)
|
||||
cs.crosslisted?.should be_false
|
||||
|
||||
cs.crosslist_to_course(course2)
|
||||
course1.reload
|
||||
course2.reload
|
||||
cs.reload
|
||||
e.reload
|
||||
|
||||
course1.course_sections.find_by_id(cs.id).should be_nil
|
||||
course2.course_sections.find_by_id(cs.id).should_not be_nil
|
||||
course3.course_sections.find_by_id(cs.id).should be_nil
|
||||
cs.account.should eql(account1)
|
||||
cs.nonxlist_course.should eql(course1)
|
||||
e.root_account.should eql(account2)
|
||||
cs.crosslisted?.should be_true
|
||||
|
||||
cs.crosslist_to_course(course3)
|
||||
course1.reload
|
||||
course2.reload
|
||||
course3.reload
|
||||
cs.reload
|
||||
e.reload
|
||||
|
||||
course1.course_sections.find_by_id(cs.id).should be_nil
|
||||
course2.course_sections.find_by_id(cs.id).should be_nil
|
||||
course3.course_sections.find_by_id(cs.id).should_not be_nil
|
||||
cs.account.should eql(account1)
|
||||
cs.nonxlist_course.should eql(course1)
|
||||
e.root_account.should eql(account3)
|
||||
cs.crosslisted?.should be_true
|
||||
|
||||
cs.uncrosslist
|
||||
course1.reload
|
||||
course2.reload
|
||||
course3.reload
|
||||
cs.reload
|
||||
e.reload
|
||||
|
||||
course1.course_sections.find_by_id(cs.id).should_not be_nil
|
||||
course2.course_sections.find_by_id(cs.id).should be_nil
|
||||
course3.course_sections.find_by_id(cs.id).should be_nil
|
||||
cs.account.should be_nil
|
||||
cs.nonxlist_course.should be_nil
|
||||
e.root_account.should eql(account1)
|
||||
cs.crosslisted?.should be_false
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue