Re-point C1 cross-lane call sites after exam_attempt/course merges
Browse files at this commitad1326c28b7ec3e367a551e760c1a9df5a3fc74bParent: 7267caa- chore
- re-point C1 cross-lane call sites after exam_attempt/course merges
5 changed files +15 -15
- src/db/exam_attempt.rs +2 -2
- src/service/course.rs +1 -1
- src/service/exam_attempt.rs +6 -6
- src/web/exam_ws.rs +2 -2
- src/web/exams/mod.rs +4 -4
src/db/exam_attempt.rsmodified+2 -2
| @@ -305,7 +305,7 @@ mod tests { | |||
| 305 | /// rows to exercise the attempt lifecycle without the HTTP layer. | 305 | /// rows to exercise the attempt lifecycle without the HTTP layer. |
| 306 | async fn open_exam_with_question(db: &Database, max_attempts: i64) -> (Exam, ExamQuestion) { | 306 | async fn open_exam_with_question(db: &Database, max_attempts: i64) -> (Exam, ExamQuestion) { |
| 307 | let creator = UserId::from_key("01TESTTEACHERAAAAAAAAAAAAA"); | 307 | let creator = UserId::from_key("01TESTTEACHERAAAAAAAAAAAAA"); |
| 308 | - let course = crate::domain::course::a_test_course(db).await; | 308 | + let course = crate::db::course::a_test_course(db).await; |
| 309 | let kinds = Settings::defaults().get_exam_kinds().to_vec(); | 309 | let kinds = Settings::defaults().get_exam_kinds().to_vec(); |
| 310 | let exam = Exam::create( | 310 | let exam = Exam::create( |
| 311 | &creator, | 311 | &creator, |
| @@ -342,7 +342,7 @@ mod tests { | |||
| 342 | // A real subject row, not a minted id: a question claims a reference on | 342 | // A real subject row, not a minted id: a question claims a reference on |
| 343 | // its subject and is refused if that subject does not exist. | 343 | // its subject and is refused if that subject does not exist. |
| 344 | let subject = crate::domain::subject::Subject::create( | 344 | let subject = crate::domain::subject::Subject::create( |
| 345 | - &crate::domain::course::a_test_course(db).await, | 345 | + &crate::db::course::a_test_course(db).await, |
| 346 | crate::domain::subject::SubjectName::try_new("topic").unwrap(), | 346 | crate::domain::subject::SubjectName::try_new("topic").unwrap(), |
| 347 | crate::domain::subject::SubjectDescription::try_new("").unwrap(), | 347 | crate::domain::subject::SubjectDescription::try_new("").unwrap(), |
| 348 | db, | 348 | db, |
src/service/course.rsmodified+1 -1
| @@ -164,7 +164,7 @@ pub struct DeleteOutcome { | |||
| 164 | /// blob. | 164 | /// blob. |
| 165 | pub async fn delete(db: &Database, course: &Course) -> Result<DeleteOutcome, AppError> { | 165 | pub async fn delete(db: &Database, course: &Course) -> Result<DeleteOutcome, AppError> { |
| 166 | require_open(db, course).await?; | 166 | require_open(db, course).await?; |
| 167 | - let _guard = crate::web::exams::EXAM_LOCK.write().await; | 167 | + let _guard = crate::service::exam_attempt::EXAM_LOCK.write().await; |
| 168 | let _homework_guard = crate::web::homework::HOMEWORK_LOCK.write().await; | 168 | let _homework_guard = crate::web::homework::HOMEWORK_LOCK.write().await; |
| 169 | let image_files = QuestionImage::file_keys_for_course(course.get_id(), db).await?; | 169 | let image_files = QuestionImage::file_keys_for_course(course.get_id(), db).await?; |
| 170 | let answer_image_files = AnswerImage::file_keys_for_course(course.get_id(), db).await?; | 170 | let answer_image_files = AnswerImage::file_keys_for_course(course.get_id(), db).await?; |
src/service/exam_attempt.rsmodified+6 -6
| @@ -143,7 +143,7 @@ pub async fn writable_attempt( | |||
| 143 | /// The course an exam belongs to. A dangling reference means the course-delete | 143 | /// The course an exam belongs to. A dangling reference means the course-delete |
| 144 | /// cascade was violated — surface it loudly as a 500, not a user-facing 404. | 144 | /// cascade was violated — surface it loudly as a 500, not a user-facing 404. |
| 145 | pub async fn course_of(exam: &Exam, db: &Database) -> Result<Course, AppError> { | 145 | pub async fn course_of(exam: &Exam, db: &Database) -> Result<Course, AppError> { |
| 146 | - crate::domain::course::Course::read(exam.get_course(), db) | 146 | + crate::db::course::read(db, exam.get_course()) |
| 147 | .await? | 147 | .await? |
| 148 | .ok_or_else(|| AppError::Internal("exam references a missing course".into())) | 148 | .ok_or_else(|| AppError::Internal("exam references a missing course".into())) |
| 149 | } | 149 | } |
| @@ -305,7 +305,7 @@ pub async fn start_attempt( | |||
| 305 | ensure_sittable(&exam)?; | 305 | ensure_sittable(&exam)?; |
| 306 | ensure_student(user)?; | 306 | ensure_student(user)?; |
| 307 | ensure_enrolled(&exam, user.get_id(), db).await?; | 307 | ensure_enrolled(&exam, user.get_id(), db).await?; |
| 308 | - course_of(&exam, db).await?.require_open(db).await?; | 308 | + crate::service::course::require_open(db, &course_of(&exam, db).await?).await?; |
| 309 | let now = Timestamp::now(); | 309 | let now = Timestamp::now(); |
| 310 | if let Some(starts_at) = exam.get_starts_at() | 310 | if let Some(starts_at) = exam.get_starts_at() |
| 311 | && now < starts_at | 311 | && now < starts_at |
| @@ -345,7 +345,7 @@ pub async fn finish_attempt( | |||
| 345 | { | 345 | { |
| 346 | return Err(AppError::Conflict("time is up — the attempt has expired")); | 346 | return Err(AppError::Conflict("time is up — the attempt has expired")); |
| 347 | } | 347 | } |
| 348 | - course_of(exam, db).await?.require_open(db).await?; | 348 | + crate::service::course::require_open(db, &course_of(exam, db).await?).await?; |
| 349 | crate::db::exam_attempt::finish(db, attempt).await | 349 | crate::db::exam_attempt::finish(db, attempt).await |
| 350 | } | 350 | } |
| 351 | 351 | ||
| @@ -399,7 +399,7 @@ pub async fn save_answer_in( | |||
| 399 | ensure_student_now(attempt.get_user(), db).await?; | 399 | ensure_student_now(attempt.get_user(), db).await?; |
| 400 | ensure_enrolled(exam, attempt.get_user(), db).await?; | 400 | ensure_enrolled(exam, attempt.get_user(), db).await?; |
| 401 | check_rejoin(exam, attempt)?; | 401 | check_rejoin(exam, attempt)?; |
| 402 | - course_of(exam, db).await?.require_open(db).await?; | 402 | + crate::service::course::require_open(db, &course_of(exam, db).await?).await?; |
| 403 | let question = question_of_exam(exam.get_id(), question_id, db).await?; | 403 | let question = question_of_exam(exam.get_id(), question_id, db).await?; |
| 404 | crate::domain::exam_answer::ExamAnswer::save( | 404 | crate::domain::exam_answer::ExamAnswer::save( |
| 405 | &question, | 405 | &question, |
| @@ -503,7 +503,7 @@ mod tests { | |||
| 503 | /// rows to exercise the attempt lifecycle without the HTTP layer. | 503 | /// rows to exercise the attempt lifecycle without the HTTP layer. |
| 504 | async fn open_exam_with_question(db: &Database, max_attempts: i64) -> (Exam, ExamQuestion) { | 504 | async fn open_exam_with_question(db: &Database, max_attempts: i64) -> (Exam, ExamQuestion) { |
| 505 | let creator = UserId::from_key("01TESTTEACHERAAAAAAAAAAAAA"); | 505 | let creator = UserId::from_key("01TESTTEACHERAAAAAAAAAAAAA"); |
| 506 | - let course = crate::domain::course::a_test_course(db).await; | 506 | + let course = crate::db::course::a_test_course(db).await; |
| 507 | let kinds = Settings::defaults().get_exam_kinds().to_vec(); | 507 | let kinds = Settings::defaults().get_exam_kinds().to_vec(); |
| 508 | let exam = Exam::create( | 508 | let exam = Exam::create( |
| 509 | &creator, | 509 | &creator, |
| @@ -540,7 +540,7 @@ mod tests { | |||
| 540 | // A real subject row, not a minted id: a question claims a reference on | 540 | // A real subject row, not a minted id: a question claims a reference on |
| 541 | // its subject and is refused if that subject does not exist. | 541 | // its subject and is refused if that subject does not exist. |
| 542 | let subject = crate::domain::subject::Subject::create( | 542 | let subject = crate::domain::subject::Subject::create( |
| 543 | - &crate::domain::course::a_test_course(db).await, | 543 | + &crate::db::course::a_test_course(db).await, |
| 544 | crate::domain::subject::SubjectName::try_new("topic").unwrap(), | 544 | crate::domain::subject::SubjectName::try_new("topic").unwrap(), |
| 545 | crate::domain::subject::SubjectDescription::try_new("").unwrap(), | 545 | crate::domain::subject::SubjectDescription::try_new("").unwrap(), |
| 546 | db, | 546 | db, |
src/web/exam_ws.rsmodified+2 -2
| @@ -152,7 +152,7 @@ pub async fn attempt_ws( | |||
| 152 | ensure_enrolled(&exam, user.get_id(), &st.db).await?; | 152 | ensure_enrolled(&exam, user.get_id(), &st.db).await?; |
| 153 | let attempt = writable_attempt(&exam, user.get_id(), &st.db).await?; | 153 | let attempt = writable_attempt(&exam, user.get_id(), &st.db).await?; |
| 154 | check_rejoin(&exam, &attempt)?; | 154 | check_rejoin(&exam, &attempt)?; |
| 155 | - course_of(&exam, &st.db).await?.require_open(&st.db).await?; | 155 | + crate::service::course::require_open(&st.db, &course_of(&exam, &st.db).await?).await?; |
| 156 | 156 | ||
| 157 | let user_id = user.get_id().clone(); | 157 | let user_id = user.get_id().clone(); |
| 158 | Ok(ws.on_upgrade(move |socket| room(socket, st, slug, exam, attempt, user_id))) | 158 | Ok(ws.on_upgrade(move |socket| room(socket, st, slug, exam, attempt, user_id))) |
| @@ -461,7 +461,7 @@ async fn handle_message( | |||
| 461 | // same error frame as every other conflict. | 461 | // same error frame as every other conflict. |
| 462 | async { | 462 | async { |
| 463 | let attempt = writable_room_attempt(&exam, attempt_id, user, db).await?; | 463 | let attempt = writable_room_attempt(&exam, attempt_id, user, db).await?; |
| 464 | - course_of(&exam, db).await?.require_open(db).await?; | 464 | + crate::service::course::require_open(db, &course_of(&exam, db).await?).await?; |
| 465 | finish(db, attempt).await | 465 | finish(db, attempt).await |
| 466 | } | 466 | } |
| 467 | .await | 467 | .await |
src/web/exams/mod.rsmodified+4 -4
| @@ -394,7 +394,7 @@ async fn update_exam( | |||
| 394 | "only the course creator, an assigned teacher, or a manager/admin can edit this exam", | 394 | "only the course creator, an assigned teacher, or a manager/admin can edit this exam", |
| 395 | )); | 395 | )); |
| 396 | } | 396 | } |
| 397 | - course.require_open(&st.db).await?; | 397 | + crate::service::course::require_open(&st.db, &course).await?; |
| 398 | 398 | ||
| 399 | let title = match req.title { | 399 | let title = match req.title { |
| 400 | Some(ref title) => ExamTitle::try_new(title)?, | 400 | Some(ref title) => ExamTitle::try_new(title)?, |
| @@ -552,7 +552,7 @@ async fn delete_exam( | |||
| 552 | "only the course creator, an assigned teacher, or a manager/admin can delete this exam", | 552 | "only the course creator, an assigned teacher, or a manager/admin can delete this exam", |
| 553 | )); | 553 | )); |
| 554 | } | 554 | } |
| 555 | - course.require_open(&st.db).await?; | 555 | + crate::service::course::require_open(&st.db, &course).await?; |
| 556 | // *Writer* lease of [`EXAM_LOCK`] across the whole cascade, blob names | 556 | // *Writer* lease of [`EXAM_LOCK`] across the whole cascade, blob names |
| 557 | // included — the lease `delete_homework` has always held, and its absence | 557 | // included — the lease `delete_homework` has always held, and its absence |
| 558 | // here is what made a sitting able to start inside this delete. Every other | 558 | // here is what made a sitting able to start inside this delete. Every other |
| @@ -637,7 +637,7 @@ async fn grade( | |||
| 637 | "only the course creator, an assigned teacher, or a manager/admin can grade this exam", | 637 | "only the course creator, an assigned teacher, or a manager/admin can grade this exam", |
| 638 | )); | 638 | )); |
| 639 | } | 639 | } |
| 640 | - course.require_open(&st.db).await?; | 640 | + crate::service::course::require_open(&st.db, &course).await?; |
| 641 | // Pre-flight: `ExamResult::grade` re-makes this check inside the mark's own | 641 | // Pre-flight: `ExamResult::grade` re-makes this check inside the mark's own |
| 642 | // transaction, so a re-draft landing after this read cannot leave a mark on | 642 | // transaction, so a re-draft landing after this read cannot leave a mark on |
| 643 | // a hidden exam. | 643 | // a hidden exam. |
| @@ -844,7 +844,7 @@ async fn remove_result( | |||
| 844 | "only the course creator, an assigned teacher, or a manager/admin can remove results", | 844 | "only the course creator, an assigned teacher, or a manager/admin can remove results", |
| 845 | )); | 845 | )); |
| 846 | } | 846 | } |
| 847 | - course.require_open(&st.db).await?; | 847 | + crate::service::course::require_open(&st.db, &course).await?; |
| 848 | let removed = ExamResult::remove( | 848 | let removed = ExamResult::remove( |
| 849 | exam.get_id(), | 849 | exam.get_id(), |
| 850 | &UserId::from_key(&target), | 850 | &UserId::from_key(&target), |