From ad1326c28b7ec3e367a551e760c1a9df5a3fc74b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 11 Sep 2026 09:14:10 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20chore:=20re-point=20C1=20cross-l?= =?UTF-8?q?ane=20call=20sites=20after=20exam=5Fattempt/course=20merges?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/exam_attempt.rs | 4 ++-- src/service/course.rs | 2 +- src/service/exam_attempt.rs | 12 ++++++------ src/web/exam_ws.rs | 4 ++-- src/web/exams/mod.rs | 8 ++++---- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/db/exam_attempt.rs b/src/db/exam_attempt.rs index 54245dc..0c938d2 100644 --- a/src/db/exam_attempt.rs +++ b/src/db/exam_attempt.rs @@ -305,7 +305,7 @@ mod tests { /// rows to exercise the attempt lifecycle without the HTTP layer. async fn open_exam_with_question(db: &Database, max_attempts: i64) -> (Exam, ExamQuestion) { let creator = UserId::from_key("01TESTTEACHERAAAAAAAAAAAAA"); - let course = crate::domain::course::a_test_course(db).await; + let course = crate::db::course::a_test_course(db).await; let kinds = Settings::defaults().get_exam_kinds().to_vec(); let exam = Exam::create( &creator, @@ -342,7 +342,7 @@ mod tests { // A real subject row, not a minted id: a question claims a reference on // its subject and is refused if that subject does not exist. let subject = crate::domain::subject::Subject::create( - &crate::domain::course::a_test_course(db).await, + &crate::db::course::a_test_course(db).await, crate::domain::subject::SubjectName::try_new("topic").unwrap(), crate::domain::subject::SubjectDescription::try_new("").unwrap(), db, diff --git a/src/service/course.rs b/src/service/course.rs index b11b863..31018fe 100644 --- a/src/service/course.rs +++ b/src/service/course.rs @@ -164,7 +164,7 @@ pub struct DeleteOutcome { /// blob. pub async fn delete(db: &Database, course: &Course) -> Result { require_open(db, course).await?; - let _guard = crate::web::exams::EXAM_LOCK.write().await; + let _guard = crate::service::exam_attempt::EXAM_LOCK.write().await; let _homework_guard = crate::web::homework::HOMEWORK_LOCK.write().await; let image_files = QuestionImage::file_keys_for_course(course.get_id(), db).await?; let answer_image_files = AnswerImage::file_keys_for_course(course.get_id(), db).await?; diff --git a/src/service/exam_attempt.rs b/src/service/exam_attempt.rs index 15b9a55..70c965d 100644 --- a/src/service/exam_attempt.rs +++ b/src/service/exam_attempt.rs @@ -143,7 +143,7 @@ pub async fn writable_attempt( /// The course an exam belongs to. A dangling reference means the course-delete /// cascade was violated — surface it loudly as a 500, not a user-facing 404. pub async fn course_of(exam: &Exam, db: &Database) -> Result { - crate::domain::course::Course::read(exam.get_course(), db) + crate::db::course::read(db, exam.get_course()) .await? .ok_or_else(|| AppError::Internal("exam references a missing course".into())) } @@ -305,7 +305,7 @@ pub async fn start_attempt( ensure_sittable(&exam)?; ensure_student(user)?; ensure_enrolled(&exam, user.get_id(), db).await?; - course_of(&exam, db).await?.require_open(db).await?; + crate::service::course::require_open(db, &course_of(&exam, db).await?).await?; let now = Timestamp::now(); if let Some(starts_at) = exam.get_starts_at() && now < starts_at @@ -345,7 +345,7 @@ pub async fn finish_attempt( { return Err(AppError::Conflict("time is up — the attempt has expired")); } - course_of(exam, db).await?.require_open(db).await?; + crate::service::course::require_open(db, &course_of(exam, db).await?).await?; crate::db::exam_attempt::finish(db, attempt).await } @@ -399,7 +399,7 @@ pub async fn save_answer_in( ensure_student_now(attempt.get_user(), db).await?; ensure_enrolled(exam, attempt.get_user(), db).await?; check_rejoin(exam, attempt)?; - course_of(exam, db).await?.require_open(db).await?; + crate::service::course::require_open(db, &course_of(exam, db).await?).await?; let question = question_of_exam(exam.get_id(), question_id, db).await?; crate::domain::exam_answer::ExamAnswer::save( &question, @@ -503,7 +503,7 @@ mod tests { /// rows to exercise the attempt lifecycle without the HTTP layer. async fn open_exam_with_question(db: &Database, max_attempts: i64) -> (Exam, ExamQuestion) { let creator = UserId::from_key("01TESTTEACHERAAAAAAAAAAAAA"); - let course = crate::domain::course::a_test_course(db).await; + let course = crate::db::course::a_test_course(db).await; let kinds = Settings::defaults().get_exam_kinds().to_vec(); let exam = Exam::create( &creator, @@ -540,7 +540,7 @@ mod tests { // A real subject row, not a minted id: a question claims a reference on // its subject and is refused if that subject does not exist. let subject = crate::domain::subject::Subject::create( - &crate::domain::course::a_test_course(db).await, + &crate::db::course::a_test_course(db).await, crate::domain::subject::SubjectName::try_new("topic").unwrap(), crate::domain::subject::SubjectDescription::try_new("").unwrap(), db, diff --git a/src/web/exam_ws.rs b/src/web/exam_ws.rs index 5b29fbd..2a0c68e 100644 --- a/src/web/exam_ws.rs +++ b/src/web/exam_ws.rs @@ -152,7 +152,7 @@ pub async fn attempt_ws( ensure_enrolled(&exam, user.get_id(), &st.db).await?; let attempt = writable_attempt(&exam, user.get_id(), &st.db).await?; check_rejoin(&exam, &attempt)?; - course_of(&exam, &st.db).await?.require_open(&st.db).await?; + crate::service::course::require_open(&st.db, &course_of(&exam, &st.db).await?).await?; let user_id = user.get_id().clone(); Ok(ws.on_upgrade(move |socket| room(socket, st, slug, exam, attempt, user_id))) @@ -461,7 +461,7 @@ async fn handle_message( // same error frame as every other conflict. async { let attempt = writable_room_attempt(&exam, attempt_id, user, db).await?; - course_of(&exam, db).await?.require_open(db).await?; + crate::service::course::require_open(db, &course_of(&exam, db).await?).await?; finish(db, attempt).await } .await diff --git a/src/web/exams/mod.rs b/src/web/exams/mod.rs index a3244b5..0011dff 100644 --- a/src/web/exams/mod.rs +++ b/src/web/exams/mod.rs @@ -394,7 +394,7 @@ async fn update_exam( "only the course creator, an assigned teacher, or a manager/admin can edit this exam", )); } - course.require_open(&st.db).await?; + crate::service::course::require_open(&st.db, &course).await?; let title = match req.title { Some(ref title) => ExamTitle::try_new(title)?, @@ -552,7 +552,7 @@ async fn delete_exam( "only the course creator, an assigned teacher, or a manager/admin can delete this exam", )); } - course.require_open(&st.db).await?; + crate::service::course::require_open(&st.db, &course).await?; // *Writer* lease of [`EXAM_LOCK`] across the whole cascade, blob names // included — the lease `delete_homework` has always held, and its absence // here is what made a sitting able to start inside this delete. Every other @@ -637,7 +637,7 @@ async fn grade( "only the course creator, an assigned teacher, or a manager/admin can grade this exam", )); } - course.require_open(&st.db).await?; + crate::service::course::require_open(&st.db, &course).await?; // Pre-flight: `ExamResult::grade` re-makes this check inside the mark's own // transaction, so a re-draft landing after this read cannot leave a mark on // a hidden exam. @@ -844,7 +844,7 @@ async fn remove_result( "only the course creator, an assigned teacher, or a manager/admin can remove results", )); } - course.require_open(&st.db).await?; + crate::service::course::require_open(&st.db, &course).await?; let removed = ExamResult::remove( exam.get_id(), &UserId::from_key(&target),