diff --git a/lib/sis/enrollment_importer.rb b/lib/sis/enrollment_importer.rb index 0878b52546c..9a357db0e3a 100644 --- a/lib/sis/enrollment_importer.rb +++ b/lib/sis/enrollment_importer.rb @@ -27,7 +27,7 @@ module SIS FasterCSV.foreach(csv[:fullpath], :headers => :first_row, :skip_blanks => true, :header_converters => :downcase) do |row| add_error(csv, "No course_id given for an enrollment") if row['course_id'].blank? add_error(csv, "No user_id given for an enrollment") if row['user_id'].blank? - add_error(csv, "Improper role \"#{row['role']}\" for an enrollment") unless row['role'] =~ /\Astudent|\Ateacher|\Ata/i + add_error(csv, "Improper role \"#{row['role']}\" for an enrollment") unless row['role'] =~ /\Astudent|\Ateacher|\Ata|\Aobserver/i add_error(csv, "Improper status \"#{row['status']}\" for an enrollment") unless row['status'] =~ /\Aactive|\Adeleted|\Acompleted/i end end @@ -72,6 +72,13 @@ module SIS enrollment.type = 'StudentEnrollment' elsif row['role'] =~ /\Ata\z|assistant/i enrollment.type = 'TaEnrollment' + elsif row['role'] =~ /\Aobserver\z/i + enrollment.type = 'ObserverEnrollment' + if row['associated_user_id'] + pseudo = Pseudonym.find_by_account_id_and_sis_user_id(@root_account.id, row['associated_user_id']) + associated_enrollment = pseudo && course.student_enrollments.find_by_user_id(pseudo.user_id) + enrollment.associated_user_id = associated_enrollment && associated_enrollment.user_id + end end if row['status']=~ /active/i diff --git a/spec/lib/sis_csv_importer_spec.rb b/spec/lib/sis_csv_importer_spec.rb index 83b4863fd56..84e82fe949d 100644 --- a/spec/lib/sis_csv_importer_spec.rb +++ b/spec/lib/sis_csv_importer_spec.rb @@ -314,7 +314,8 @@ describe SIS::SisCsv do "user_id,login_id,first_name,last_name,email,status", "user_1,user1,User,Uno,user@example.com,active", "user_2,user2,User,Dos,user2@example.com,active", - "user_3,user4,User,Tres,user3@example.com,active" + "user_3,user4,User,Tres,user3@example.com,active", + "user_5,user5,User,Quatro,user5@example.com,active" ) process_csv_data( "section_id,course_id,name,status,start_date,end_date", @@ -322,15 +323,18 @@ describe SIS::SisCsv do ) # the enrollments process_csv_data( - "course_id,user_id,role,section_name,status", - "test_1,user_1,teacher,S001,active", - "test_1,user_2,student,S001,active", - "test_1,user_3,ta,S001,active" + "course_id,user_id,role,section_name,status,associated_user_id", + "test_1,user_1,teacher,S001,active,", + "test_1,user_2,student,S001,active,", + "test_1,user_3,ta,S001,active,", + "test_1,user_5,observer,S001,active,user_2" ) course = @account.courses.find_by_sis_source_id("test_1") course.teachers.first.name.should == "User Uno" course.students.first.name.should == "User Dos" course.tas.first.name.should == "User Tres" + course.observers.first.name.should == "User Quatro" + course.observer_enrollments.first.associated_user_id.should == course.students.first.id end end