look at role name when reusing enrollments; fixes #CNVS-2431
test plan: * enroll a user as a plain Student * enroll the same user in a custom student role * the plain Student enrollment should not disappear Change-Id: I7f7a1ce96a1a5f971a7226756d25b063d6f88a87 Reviewed-on: https://gerrit.instructure.com/16363 Reviewed-by: Bracken Mosbacker <bracken@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Adam Phillipps <adam@instructure.com>
This commit is contained in:
parent
8d29f27762
commit
af737b8672
|
@ -1474,6 +1474,7 @@ class Course < ActiveRecord::Base
|
|||
section = opts[:section]
|
||||
limit_privileges_to_course_section = opts[:limit_privileges_to_course_section]
|
||||
associated_user_id = opts[:associated_user_id]
|
||||
role_name = opts[:role_name]
|
||||
section ||= self.default_section
|
||||
enrollment_state ||= self.available? ? "invited" : "creation_pending"
|
||||
if type == 'TeacherEnrollment' || type == 'TaEnrollment' || type == 'DesignerEnrollment'
|
||||
|
@ -1482,11 +1483,11 @@ class Course < ActiveRecord::Base
|
|||
enrollment_state = 'creation_pending' if enrollment_state == 'invited' && !self.available?
|
||||
end
|
||||
if opts[:allow_multiple_enrollments] && associated_user_id
|
||||
e = self.enrollments.find_by_user_id_and_type_and_course_section_id_and_associated_user_id(user.id, type, section.id, associated_user_id)
|
||||
e = self.enrollments.find_by_user_id_and_type_and_role_name_and_course_section_id_and_associated_user_id(user.id, type, role_name, section.id, associated_user_id)
|
||||
elsif opts[:allow_multiple_enrollments]
|
||||
e = self.enrollments.find_by_user_id_and_type_and_course_section_id(user.id, type, section.id)
|
||||
e = self.enrollments.find_by_user_id_and_type_and_role_name_and_course_section_id(user.id, type, role_name, section.id)
|
||||
else
|
||||
e = self.enrollments.find_by_user_id_and_type(user.id, type)
|
||||
e = self.enrollments.find_by_user_id_and_type_and_role_name(user.id, type, role_name)
|
||||
end
|
||||
e.attributes = {
|
||||
:course_section => section,
|
||||
|
@ -1505,7 +1506,7 @@ class Course < ActiveRecord::Base
|
|||
:limit_privileges_to_course_section => limit_privileges_to_course_section)
|
||||
end
|
||||
e.associated_user_id = associated_user_id
|
||||
e.role_name = opts[:role_name] if opts[:role_name].present?
|
||||
e.role_name = role_name
|
||||
if e.changed?
|
||||
if opts[:no_notify]
|
||||
e.save_without_broadcasting
|
||||
|
|
|
@ -3303,5 +3303,43 @@ describe Course do
|
|||
|
||||
@course.enrollments.count.should == enrollment_count
|
||||
end
|
||||
|
||||
context "custom roles" do
|
||||
before do
|
||||
@account = Account.default
|
||||
course
|
||||
user
|
||||
custom_student_role('LazyStudent')
|
||||
custom_student_role('HonorStudent')
|
||||
end
|
||||
|
||||
it "should re-use an enrollment with the same role" do
|
||||
enrollment1 = @course.enroll_user(@user, 'StudentEnrollment', :role_name => 'HonorStudent')
|
||||
enrollment2 = @course.enroll_user(@user, 'StudentEnrollment', :role_name => 'HonorStudent')
|
||||
@user.enrollments.count.should eql 1
|
||||
enrollment1.should eql enrollment2
|
||||
end
|
||||
|
||||
it "should not re-use an enrollment with a different role" do
|
||||
enrollment1 = @course.enroll_user(@user, 'StudentEnrollment', :role_name => 'LazyStudent')
|
||||
enrollment2 = @course.enroll_user(@user, 'StudentEnrollment', :role_name => 'HonorStudent')
|
||||
@user.enrollments.count.should eql 2
|
||||
enrollment1.should_not eql enrollment2
|
||||
end
|
||||
|
||||
it "should not re-use an enrollment with no role when enrolling with a role" do
|
||||
enrollment1 = @course.enroll_user(@user, 'StudentEnrollment')
|
||||
enrollment2 = @course.enroll_user(@user, 'StudentEnrollment', :role_name => 'HonorStudent')
|
||||
@user.enrollments.count.should eql 2
|
||||
enrollment1.should_not eql enrollment2
|
||||
end
|
||||
|
||||
it "should not re-use an enrollment with a role when enrolling with no role" do
|
||||
enrollment1 = @course.enroll_user(@user, 'StudentEnrollment', :role_name => 'LazyStudent')
|
||||
enrollment2 = @course.enroll_user(@user, 'StudentEnrollment')
|
||||
@user.enrollments.count.should eql 2
|
||||
enrollment1.should_not eql enrollment2
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue