Skip to content

Commit

Permalink
Fix observer enrollment impacting section privileges of teacher
Browse files Browse the repository at this point in the history
visibility_limited_to_course_sections? should return true if all of the enrollments have limited_section_privileges ignoring observer enrollments

 closes gh-2245

 Test Plan:
   - Enroll a teacher in a section of course with limit section privileges set to true
   - Enroll a student in a different section of the same course with limit section privileges set to true
   - Set up the teacher as an observer of the student (for example the teacher teaches a section of a course but has a son or daughter taking a different section of the same course)
   Confirm the teacher cannot view all sections and can only see the two sections.
  • Loading branch information
cgravatt committed Aug 16, 2023
1 parent 03fc042 commit b10e898
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/enrollment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ def update_from(other, skip_broadcasts = false)
self.root_account_id = other.root_account_id
self.sis_batch_id = other.sis_batch_id unless sis_batch_id.nil?
self.skip_touch_user = other.skip_touch_user
self.limit_privileges_to_course_section = other.limit_privileges_to_course_section
if skip_broadcasts
save_without_broadcasting!
else
Expand Down
11 changes: 11 additions & 0 deletions spec/models/course_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,17 @@ def make_date_completed
expect(@course.course_section_visibility(limited_teacher)).to eq [@section2.id]
end

it "correctly limits visibilities for a limited teacher observing a student in different section" do
limited_teacher = user_with_pseudonym(name: "Limited Teacher")
@course.enroll_teacher(limited_teacher,
limit_privileges_to_course_section: true,
section: @section2)
student = user_with_pseudonym
@course.enroll_student(student, enrollment_state: "active", section: @section1, limit_privileges_to_course_section: true)
add_linked_observer(student, limited_teacher)
expect(@course.course_section_visibility(limited_teacher)).to eq [@section1.id, @section2.id]
end

it "unlimited teachers can see everything" do
unlimited_teacher = User.create(name: "Unlimited Teacher")
@course.enroll_teacher(unlimited_teacher, section: @section2)
Expand Down

0 comments on commit b10e898

Please sign in to comment.