fix enrollment access restriction recalculation

test plan:
* have a course with dates set in the future
 and enrollments restricted to the course dates
* have a student in the course
* they should be able to access
* set the course to restrict students from viewing
 before start date, while also changing one of the
 course dates (still keeping it in the future)
 in the same save action
* the student should not have access to the course
 anymore

closes #CNVS-36571

Change-Id: I8a58f028c7e205d0fa46dd7b977172c4d2be2823
Reviewed-on: https://gerrit.instructure.com/115047
Tested-by: Jenkins
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
QA-Review: David Mirabile <dmirabile-c@instructure.com>
Product-Review: James Williams  <jamesw@instructure.com>
This commit is contained in:
James Williams 2017-06-12 08:59:51 -06:00
parent bcb7ea7127
commit 65622ee488
2 changed files with 26 additions and 1 deletions

View File

@ -286,7 +286,8 @@ class Course < ActiveRecord::Base
EnrollmentState.send_later_if_production(:invalidate_states_for_course_or_section, self) if self.enrollments.exists?
# if the course date settings have been changed, we'll end up reprocessing all the access values anyway, so no need to queue below for other setting changes
elsif @changed_settings
end
if @changed_settings
changed_keys = (@changed_settings & [:restrict_student_future_view, :restrict_student_past_view])
if changed_keys.any?
EnrollmentState.send_later_if_production(:invalidate_access_for_course, self, changed_keys)

View File

@ -296,6 +296,30 @@ describe EnrollmentState do
enroll.reload
expect(enroll).to be_inactive
end
it "should invalidate access properly if dates and access settings are changed simultaneously" do
course_factory(active_all: true)
@course.start_at = 3.days.from_now
@course.conclude_at = 4.days.from_now
@course.restrict_enrollments_to_course_dates = true
@course.save!
enroll = student_in_course(:course => @course)
enroll_state = enroll.enrollment_state
expect(enroll_state.state).to eq 'pending_invited'
EnrollmentState.expects(:update_enrollment).at_least_once.with {|e| e.course == @course}
@course.start_at = 2.days.from_now
@course.restrict_student_future_view = true
@course.save!
enroll_state.reload
expect(enroll_state.access_is_current).to be_falsey
expect(enroll_state.state_is_current).to be_falsey
enroll_state.ensure_current_state
expect(enroll_state.restricted_access).to be_truthy
end
end
describe "#recalculate_expired_states" do