Don't recompute the world if enrollments aren't visible
Change-Id: I888e21e8b79c6e84e7ced06a887fe369817dfd7d Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/240301 Reviewed-by: Ethan Vizitei <evizitei@instructure.com> Reviewed-by: Charley Kline <ckline@instructure.com> QA-Review: Ethan Vizitei <evizitei@instructure.com> Product-Review: Ethan Vizitei <evizitei@instructure.com> Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
This commit is contained in:
parent
f09d77863f
commit
f0ebaedb0f
|
@ -1203,18 +1203,18 @@ class Course < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def recompute_student_scores_without_send_later(student_ids = nil, opts = {})
|
||||
if student_ids.present?
|
||||
visible_student_ids = if student_ids.present?
|
||||
# We were given student_ids. Let's see how many of those students can even see this assignment
|
||||
student_ids = admin_visible_student_enrollments.where(user_id: student_ids).pluck(:user_id)
|
||||
admin_visible_student_enrollments.where(user_id: student_ids).pluck(:user_id)
|
||||
else
|
||||
# We were not given any student_ids
|
||||
# Let's get them all!
|
||||
admin_visible_student_enrollments.pluck(:user_id)
|
||||
end
|
||||
|
||||
# We were either not given any student_ids or none of those students could see this assignment.
|
||||
# Let's get them all!
|
||||
student_ids = admin_visible_student_enrollments.pluck(:user_id) unless student_ids.present?
|
||||
|
||||
Rails.logger.debug "GRADES: recomputing scores in course=#{global_id} students=#{student_ids.inspect}"
|
||||
Rails.logger.debug "GRADES: recomputing scores in course=#{global_id} students=#{visible_student_ids.inspect}"
|
||||
Enrollment.recompute_final_score(
|
||||
student_ids,
|
||||
visible_student_ids,
|
||||
self.id,
|
||||
grading_period_id: opts[:grading_period_id],
|
||||
update_all_grading_period_scores: opts.fetch(:update_all_grading_period_scores, true)
|
||||
|
|
|
@ -333,10 +333,11 @@ describe Course do
|
|||
@course.recompute_student_scores
|
||||
end
|
||||
|
||||
it "should not use student ids for deleted enrollments, even if they are explicitly passed" do
|
||||
it "recomputes nothing if no students are visible" do
|
||||
@course.save!
|
||||
enrollment = course_with_student(course: @course, active_all: true)
|
||||
enrollment.destroy
|
||||
3.times{ enrollment_model(workflow_state: 'registered', course: @course, user: user_model) }
|
||||
expect(Enrollment).to receive(:recompute_final_score).with([], any_args)
|
||||
@course.recompute_student_scores([enrollment.user_id])
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue