Skip to content

Commit

Permalink
Fix for starting test exam (#1261)
Browse files Browse the repository at this point in the history
Co-authored-by: Maija Y <[email protected]>
  • Loading branch information
Maijjay and Maija Y authored Apr 11, 2024
1 parent a07715e commit 2577127
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { css } from "@emotion/css"
import { useQuery, useQueryClient } from "@tanstack/react-query"
import { addMinutes, differenceInSeconds, isPast, min, parseISO } from "date-fns"
import { addMinutes, differenceInSeconds, min, parseISO } from "date-fns"
import React, { useCallback, useContext, useEffect, useReducer, useState } from "react"
import { useTranslation } from "react-i18next"

Expand Down Expand Up @@ -237,6 +237,9 @@ const Exam: React.FC<React.PropsWithChildren<ExamProps>> = ({ query }) => {
exam.data.enrollment_data.tag === "NotEnrolled" ||
exam.data.enrollment_data.tag === "NotYetStarted"
) {
if (exam.data.enrollment_data.tag === "NotEnrolled") {
exam.data.enrollment_data.can_enroll = true
}
return (
<>
{examInfo}
Expand All @@ -248,7 +251,7 @@ const Exam: React.FC<React.PropsWithChildren<ExamProps>> = ({ query }) => {
}}
examEnrollmentData={exam.data.enrollment_data}
examHasStarted={true}
examHasEnded={exam.data.ends_at ? isPast(exam.data.ends_at) : false}
examHasEnded={false}
timeMinutes={exam.data.time_minutes}
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ pub async fn enroll(
let mut conn = pool.acquire().await?;
let exam = exams::get(&mut conn, *exam_id).await?;

// enroll if teacher is testing regardless of exams starting time
if payload.is_teacher_testing {
exams::enroll(&mut conn, *exam_id, user.id, payload.is_teacher_testing).await?;
let token = authorize(&mut conn, Act::Edit, Some(user.id), Res::Exam(*exam_id)).await?;
return token.authorized_ok(web::Json(()));
}

// check that the exam is not over
let now = Utc::now();
if exam.ended_at_or(now, false) {
Expand All @@ -49,12 +56,6 @@ pub async fn enroll(
));
}

// enroll if teacher is testing regardless of exams starting time
if payload.is_teacher_testing {
exams::enroll(&mut conn, *exam_id, user.id, payload.is_teacher_testing).await?;
let token = authorize(&mut conn, Act::Edit, Some(user.id), Res::Exam(*exam_id)).await?;
return token.authorized_ok(web::Json(()));
}
if exam.started_at_or(now, false) {
// This check should probably be handled in the authorize function but I'm not sure of
// the proper action type.
Expand Down

0 comments on commit 2577127

Please sign in to comment.