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 instructuregh-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 15, 2023
1 parent 03fc042 commit 18ce4b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2935,6 +2935,7 @@ def section_visibilities_for(user, opts = {})
end

def visibility_limited_to_course_sections?(user, visibilities = section_visibilities_for(user))
visibilities = visibilities.select { |v| v[:type] != "ObserverEnrollment"}
visibilities.all? { |s| s[:limit_privileges_to_course_section] }
end

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)
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 18ce4b4

Please sign in to comment.