fix importing active enrollments in courses with date restrictions

Previously we were allowing 'active' to override any term date restrictions.
Now we interpret 'active' to mean 'active excluding any other date-based
restrictions'.

Also fixed a bug that was causing inactive to be treated as active.

Change-Id: Idf435e7b5c129c410f828b6393d7d50fc366fbde
Reviewed-on: https://gerrit.instructure.com/5119
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Zach Wily 2011-08-17 11:58:17 -06:00
parent 4923464480
commit 8d01083315
2 changed files with 28 additions and 8 deletions

View File

@ -127,24 +127,23 @@ module SIS
enrollment.type = 'DesignerEnrollment'
end
# special-case status that bases the enrollment state
# off of availability dates instead of explicitly setting it.
if row['status']=~ /active_if_available/i
# "active" really means "active if otherwise available"
if row['status']=~ /\Aactive/i
row['status'] = course.enrollment_state_based_on_date(enrollment)
end
if row['status']=~ /active/i
if row['status']=~ /\Aactive/i
if user.workflow_state != 'deleted'
enrollment.workflow_state = 'active'
else
enrollment.workflow_state = 'deleted'
add_warning csv, "Attempted enrolling of deleted user #{row['user_id']} in course #{row['course_id']}"
end
elsif row['status']=~ /deleted/i
elsif row['status']=~ /\Adeleted/i
enrollment.workflow_state = 'deleted'
elsif row['status']=~ /completed/i
elsif row['status']=~ /\Acompleted/i
enrollment.workflow_state = 'completed'
elsif row['status']=~ /inactive/i
elsif row['status']=~ /\Ainactive/i
enrollment.workflow_state = 'inactive'
end

View File

@ -1902,7 +1902,28 @@ describe SIS::SisCsv do
Course.find_by_sis_source_id("C001").associated_accounts.map(&:id).sort.should == [Account.find_by_sis_source_id('A001').id, @account.id].sort
Course.find_by_sis_source_id("X001").associated_accounts.map(&:id).sort.should == [Account.find_by_sis_source_id('A001').id, @account.id].sort
end
it 'should import active enrollments with states based on enrollment date restrictions' do
process_csv_data(
"term_id,name,status,start_date,end_date",
"T001,Winter13,active,#{2.days.from_now.strftime("%Y-%m-%d 00:00:00")},#{4.days.from_now.strftime("%Y-%m-%d 00:00:00")}"
)
process_csv_data(
"course_id,short_name,long_name,account_id,term_id,status",
"C001,TC 101,Test Course 101,,T001,active"
)
process_csv_data(
"user_id,login_id,first_name,last_name,email,status",
"user_1,user1,User,Uno,user@example.com,active"
)
process_csv_data(
"course_id,user_id,role,section_id,status,associated_user_id",
"C001,user_1,student,,active,"
)
course = Course.find_by_sis_source_id("C001")
course.enrollments.length.should == 1
course.enrollments.first.workflow_state.should == 'inactive'
end
end
end