fix sections_visible_to for array arguments
test plan: * create a course with at least 2 sections * enroll a teacher or ta both sections, checking "Can grade students in their section only" * as the teacher/ta, visit the inbox and start composing a message * select the course * use the address book button, click on "Course Sections", and then a specific section * should not recieve a 500 network error fixes #CNVS-16585 Change-Id: I99511bc46a67fd425c3eefde8cec2d9e275454d4 Reviewed-on: https://gerrit.instructure.com/44737 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> Product-Review: Jeremy Stanley <jeremy@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com>
This commit is contained in:
parent
7cb416f839
commit
75c7b96718
|
@ -2163,22 +2163,22 @@ class Course < ActiveRecord::Base
|
|||
else scope.none
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def sections_visible_to(user, sections = active_course_sections)
|
||||
visibilities = section_visibilities_for(user)
|
||||
visibility = enrollment_visibility_level_for(user, visibilities)
|
||||
section_ids = visibilities.map{ |s| s[:course_section_id] }
|
||||
case enrollment_visibility_level_for(user, visibilities)
|
||||
when :full, :limited
|
||||
if visibilities.all?{ |v| ['StudentEnrollment', 'StudentViewEnrollment', 'ObserverEnrollment'].include? v[:type] }
|
||||
sections.where(:id => section_ids)
|
||||
is_scope = sections.respond_to?(:where)
|
||||
|
||||
if [:full, :limited, :sections].include?(visibility)
|
||||
if visibility == :sections || visibilities.all?{ |v| ['StudentEnrollment', 'StudentViewEnrollment', 'ObserverEnrollment'].include? v[:type] }
|
||||
is_scope ? sections.where(:id => section_ids) : sections.select{|section| section_ids.include?(section.id)}
|
||||
else
|
||||
sections
|
||||
end
|
||||
when :sections
|
||||
sections.where(:id => section_ids)
|
||||
else
|
||||
# return an empty set, but keep it as a scope for downstream consistency
|
||||
sections.none
|
||||
is_scope ? sections.none : []
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -45,6 +45,15 @@ describe SearchHelper do
|
|||
expect(@contexts[:sections].count).to eq 1
|
||||
end
|
||||
|
||||
it "loads the section even with restricted privileges" do
|
||||
course_with_teacher(:active_all => true, :limit_privileges_to_course_section => true)
|
||||
@current_user = @teacher
|
||||
load_all_contexts(context: @course.default_section)
|
||||
|
||||
expect(@contexts[:courses].count).to eq 1
|
||||
expect(@contexts[:sections].count).to eq 1
|
||||
end
|
||||
|
||||
describe "sharding" do
|
||||
specs_require_sharding
|
||||
|
||||
|
|
Loading…
Reference in New Issue