Skip to content

Commit

Permalink
Handles section end_at extensions in Quizzes
Browse files Browse the repository at this point in the history
Closes CNVS-21521

Test Plan:
  - Regression test that due_dates, closing "end_at" dates and all
    things quiz time limits/moderation are all good.
    - Good luck!

Change-Id: Id5ad6c0028e06e67caea28fce514190730a02e44
Reviewed-on: https://gerrit.instructure.com/59020
Tested-by: Jenkins
Reviewed-by: Cameron Sutter <csutter@instructure.com>
Product-Review: Pedro Fajardo <pfajardo@instructure.com>
QA-Review: Deepeeca Soundarrajan <dsoundarrajan@instructure.com>
  • Loading branch information
ryanmt authored and roor0 committed Aug 26, 2015
1 parent 44ef2d5 commit 5261651
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
8 changes: 8 additions & 0 deletions app/models/quizzes/quiz.rb
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ def build_submission_end_at(submission)
# Admins can take the full quiz whenever they want
return end_at if user.is_a?(::User) && self.grants_right?(user, :grade)

can_take = Quizzes::QuizEligibility.new(course: self.context, quiz: self, user: submission.user)
# set to lock date
if lock_at && !submission.manually_unlocked
if !end_at || lock_at < end_at
Expand All @@ -626,12 +627,19 @@ def build_submission_end_at(submission)
if !end_at || course.end_at < end_at
end_at = course.end_at
end
# Section dates overrule
if can_take.section_dates_apply? && can_take.course_section.end_at > end_at
end_at = can_take.course_section.end_at
end

# set to enrollment term end
elsif course.enrollment_term.end_at
if !end_at || course.enrollment_term.end_at < end_at
end_at = course.enrollment_term.end_at
end
if can_take.section_dates_apply? && can_take.course_section.end_at > end_at
end_at = can_take.course_section.end_at
end
end

end_at
Expand Down
12 changes: 8 additions & 4 deletions app/models/quizzes/quiz_eligibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ def locked?
!quiz.grants_right?(user, session, :update)
end

def section_dates_apply?
section_restricted_by_date? && section_is_ongoing?
end

def course_section
@course_section ||= (assignment_overrides && student_sections).first || CourseSection.new
end

private

attr_reader :course, :quiz, :user, :session, :remote_ip
Expand Down Expand Up @@ -144,10 +152,6 @@ def restricted_course_has_ended?
course.restrict_enrollments_to_course_dates ? course_has_ended? : false
end

def course_section
@course_section ||= (assignment_overrides & student_sections).first || CourseSection.new
end

def inactive_non_admin?
return false if user.new_record?
inactive_enrollment? && user_cannot_not_read_as_admin?
Expand Down
21 changes: 21 additions & 0 deletions spec/models/quizzes/quiz_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,27 @@
expect(sub2.end_at).to eq deadline
end

it "should set end_at to section end dates" do
# when course.end_at or term.end_at doesn't exist
deadline = 2.days.from_now
@course.restrict_enrollments_to_course_dates = true
@course.save!
@course.enrollment_term.end_at = 1.day.from_now
@course.enrollment_term.save!

# Create a special time extension section
section = @course.course_sections.create!(restrict_enrollments_to_section_dates: true, end_at: deadline)

# Create user and enroll them in our section
user = User.create!(:name => "Fred Colon")
enrollment = section.enroll_user(user, "StudentEnrollment")
enrollment.accept(:force)

q = @course.quizzes.create!(:title => "locked tomorrow")
sub2 = q.generate_submission(user)
expect(sub2.end_at).to eq deadline
end

it "should shuffle submission questions" do
u1 = User.create!(:name => "user 1")
u2 = User.create!(:name => "user 2")
Expand Down

0 comments on commit 5261651

Please sign in to comment.