forge
Explore
Log in

Don't you dare go Hollow

Cargo fmt the answer-image and submission leftovers

Browse files at this commit

330819f13492dda0afd0db0c073fa05947d840bfAhmet Kaan GümüşParent: 8131a5a
  • style
    • cargo fmt the answer-image and submission leftovers
Show full message
🎨 style: cargo fmt the answer-image and submission leftovers
src/domain/answer_image.rsmodified+4 -1
@@ -229,7 +229,10 @@ mod tests {
229 .upsert(&db)229 .upsert(&db)
230 .await230 .await
231 .unwrap();231 .unwrap();
232- assert_eq!(AnswerImage::list_for_exam(&exam, &db).await.unwrap().len(), 2);232+ assert_eq!(
233+ AnswerImage::list_for_exam(&exam, &db).await.unwrap().len(),
234+ 2
235+ );
233 assert!(236 assert!(
234 AnswerImage::read(&question, &user, &db)237 AnswerImage::read(&question, &user, &db)
235 .await238 .await
src/domain/homework_submission.rsmodified+4 -2
@@ -206,8 +206,10 @@ impl HomeworkSubmission {
206 .await?206 .await?
207 .check()?;207 .check()?;
208 // BEGIN is slot 0, the file wipe slot 1; the submission's DELETE is slot 2.208 // BEGIN is slot 0, the file wipe slot 1; the submission's DELETE is slot 2.
209- let deleted: Option<HomeworkSubmission> =209+ let deleted: Option<HomeworkSubmission> = result
210- result.take::<Vec<HomeworkSubmission>>(2)?.into_iter().next();210+ .take::<Vec<HomeworkSubmission>>(2)?
211+ .into_iter()
212+ .next();
211 deleted.ok_or(AppError::NotFound)213 deleted.ok_or(AppError::NotFound)
212 }214 }
213 }215 }
src/web/exams.rsmodified+16 -6
@@ -2570,9 +2570,9 @@ async fn store_answer_image(
2570 data.len() as i64,2570 data.len() as i64,
2571 );2571 );
2572 let path = blob_path(&st.files_path, image.get_file());2572 let path = blob_path(&st.files_path, image.get_file());
2573- tokio::fs::write(&path, data)2573+ tokio::fs::write(&path, data).await.map_err(|err| {
2574- .await2574+ AppError::Internal(format!("failed to store the answer image blob: {err}"))
2575- .map_err(|err| AppError::Internal(format!("failed to store the answer image blob: {err}")))?;2575+ })?;
2576 match image.upsert(&st.db).await {2576 match image.upsert(&st.db).await {
2577 Ok(stored) => {2577 Ok(stored) => {
2578 if let Some(replaced) = replaced {2578 if let Some(replaced) = replaced {
@@ -2639,8 +2639,15 @@ async fn upload_answer_image(
2639 ensure_enrolled(&exam, attempt.get_user(), &st.db).await?;2639 ensure_enrolled(&exam, attempt.get_user(), &st.db).await?;
2640 check_rejoin(&exam, &attempt)?;2640 check_rejoin(&exam, &attempt)?;
2641 let question = question_of_exam(exam.get_id(), &qid, &st.db).await?;2641 let question = question_of_exam(exam.get_id(), &qid, &st.db).await?;
2642- let stored =2642+ let stored = store_answer_image(
2643- store_answer_image(&st, &exam, &question, user.get_id(), content_type, &upload.data).await?;2643+ &st,
2644+ &exam,
2645+ &question,
2646+ user.get_id(),
2647+ content_type,
2648+ &upload.data,
2649+ )
2650+ .await?;
2644 // A drawing-only answer (drew, typed nothing) still needs an ExamAnswer row,2651 // A drawing-only answer (drew, typed nothing) still needs an ExamAnswer row,
2645 // or the drawing never surfaces in the sitting/grading views — answer_image2652 // or the drawing never surfaces in the sitting/grading views — answer_image
2646 // rides the answer payload. Create a blank text answer when absent, without2653 // rides the answer payload. Create a blank text answer when absent, without
@@ -2654,7 +2661,10 @@ async fn upload_answer_image(
2654 {2661 {
2655 ExamAnswer::save(&question, user.get_id(), None, Some(String::new()), &st.db).await?;2662 ExamAnswer::save(&question, user.get_id(), None, Some(String::new()), &st.db).await?;
2656 }2663 }
2657- Ok((StatusCode::CREATED, Json(ImageMetaResponse::from_answer(&stored))))2664+ Ok((
2665+ StatusCode::CREATED,
2666+ Json(ImageMetaResponse::from_answer(&stored)),
2667+ ))
2658 }2668 }
2659 2669
2660 /// Clear the caller's drawn answer to a question. Same writable-attempt gate2670 /// Clear the caller's drawn answer to a question. Same writable-attempt gate
tests/integration.rsmodified+71 -15
@@ -10887,8 +10887,13 @@ async fn student_answer_images_serve_and_cascade() {
10887 // peek: the write path 404s (no attempt), the own-read 404s too.10887 // peek: the write path 404s (no attempt), the own-read 404s too.
10888 let (status, _) = post_image(&app, &student, &own, "image/png", png).await;10888 let (status, _) = post_image(&app, &student, &own, "image/png", png).await;
10889 assert_eq!(status, StatusCode::NOT_FOUND, "no attempt yet");10889 assert_eq!(status, StatusCode::NOT_FOUND, "no attempt yet");
10890- let (status, _, _) = common::send_raw(&app, "GET", &own, Some(&student), None, Vec::new()).await;10890+ let (status, _, _) =
10891- assert_eq!(status, StatusCode::NOT_FOUND, "no early peek before the attempt");10891+ common::send_raw(&app, "GET", &own, Some(&student), None, Vec::new()).await;
10892+ assert_eq!(
10893+ status,
10894+ StatusCode::NOT_FOUND,
10895+ "no early peek before the attempt"
10896+ );
10892 10897
10893 // The student sits the exam.10898 // The student sits the exam.
10894 let res = send(10899 let res = send(
@@ -10954,7 +10959,10 @@ async fn student_answer_images_serve_and_cascade() {
10954 )10959 )
10955 .await;10960 .await;
10956 assert_eq!(res.status, StatusCode::OK);10961 assert_eq!(res.status, StatusCode::OK);
10957- assert_eq!(res.body[0]["answer"]["answer_image"]["content_type"], "image/webp");10962+ assert_eq!(
10963+ res.body[0]["answer"]["answer_image"]["content_type"],
10964+ "image/webp"
10965+ );
10958 10966
10959 // The teacher grading sheet carries the drawing meta and serves the bytes10967 // The teacher grading sheet carries the drawing meta and serves the bytes
10960 // via the teacher route; the sheet row also exposes the flag.10968 // via the teacher route; the sheet row also exposes the flag.
@@ -10968,14 +10976,31 @@ async fn student_answer_images_serve_and_cascade() {
10968 )10976 )
10969 .await;10977 .await;
10970 assert_eq!(res.status, StatusCode::OK, "{}", res.body);10978 assert_eq!(res.status, StatusCode::OK, "{}", res.body);
10971- assert_eq!(res.body["answers"][0]["answer_image"]["content_type"], "image/webp");10979+ assert_eq!(
10972- let (status, _, bytes) =10980+ res.body["answers"][0]["answer_image"]["content_type"],
10973- common::send_raw(&app, "GET", &teacher_bytes, Some(&teacher), None, Vec::new()).await;10981+ "image/webp"
10982+ );
10983+ let (status, _, bytes) = common::send_raw(
10984+ &app,
10985+ "GET",
10986+ &teacher_bytes,
10987+ Some(&teacher),
10988+ None,
10989+ Vec::new(),
10990+ )
10991+ .await;
10974 assert_eq!(status, StatusCode::OK);10992 assert_eq!(status, StatusCode::OK);
10975 assert_eq!(bytes, png);10993 assert_eq!(bytes, png);
10976 // An outsider student can't read the teacher grading route (not a teacher).10994 // An outsider student can't read the teacher grading route (not a teacher).
10977- let (status, _, _) =10995+ let (status, _, _) = common::send_raw(
10978- common::send_raw(&app, "GET", &teacher_bytes, Some(&outsider), None, Vec::new()).await;10996+ &app,
10997+ "GET",
10998+ &teacher_bytes,
10999+ Some(&outsider),
11000+ None,
11001+ Vec::new(),
11002+ )
11003+ .await;
10979 assert_eq!(status, StatusCode::FORBIDDEN);11004 assert_eq!(status, StatusCode::FORBIDDEN);
10980 11005
10981 // A retake wipes the student's sheet — the answer-image row *and* its11006 // A retake wipes the student's sheet — the answer-image row *and* its
@@ -11068,16 +11093,33 @@ async fn answer_image_surfaces_for_a_drawing_only_answer() {
11068 .await;11093 .await;
11069 11094
11070 // Sit, then upload a drawing WITHOUT ever saving a text answer.11095 // Sit, then upload a drawing WITHOUT ever saving a text answer.
11071- let res = send(&app, "POST", &format!("/exams/{exam}/attempt"), Some(&student), None).await;11096+ let res = send(
11097+ &app,
11098+ "POST",
11099+ &format!("/exams/{exam}/attempt"),
11100+ Some(&student),
11101+ None,
11102+ )
11103+ .await;
11072 assert_eq!(res.status, StatusCode::CREATED, "{}", res.body);11104 assert_eq!(res.status, StatusCode::CREATED, "{}", res.body);
11073 let own = format!("/exams/{exam}/attempt/answers/{question}/image");11105 let own = format!("/exams/{exam}/attempt/answers/{question}/image");
11074 let (status, body) = post_image(&app, &student, &own, "image/png", b"tri").await;11106 let (status, body) = post_image(&app, &student, &own, "image/png", b"tri").await;
11075 assert_eq!(status, StatusCode::CREATED, "{body}");11107 assert_eq!(status, StatusCode::CREATED, "{body}");
11076 11108
11077 // The sitting view carries the drawing meta with an empty typed answer.11109 // The sitting view carries the drawing meta with an empty typed answer.
11078- let res = send(&app, "GET", &format!("/exams/{exam}/attempt/questions"), Some(&student), None).await;11110+ let res = send(
11111+ &app,
11112+ "GET",
11113+ &format!("/exams/{exam}/attempt/questions"),
11114+ Some(&student),
11115+ None,
11116+ )
11117+ .await;
11079 assert_eq!(res.status, StatusCode::OK);11118 assert_eq!(res.status, StatusCode::OK);
11080- assert_eq!(res.body[0]["answer"]["answer_image"]["content_type"], "image/png");11119+ assert_eq!(
11120+ res.body[0]["answer"]["answer_image"]["content_type"],
11121+ "image/png"
11122+ );
11081 assert_eq!(res.body[0]["answer"]["text"], "");11123 assert_eq!(res.body[0]["answer"]["text"], "");
11082 11124
11083 // The teacher grading sheet shows it too.11125 // The teacher grading sheet shows it too.
@@ -11090,15 +11132,29 @@ async fn answer_image_surfaces_for_a_drawing_only_answer() {
11090 )11132 )
11091 .await;11133 .await;
11092 assert_eq!(res.status, StatusCode::OK, "{}", res.body);11134 assert_eq!(res.status, StatusCode::OK, "{}", res.body);
11093- assert_eq!(res.body["answers"][0]["answer_image"]["content_type"], "image/png");11135+ assert_eq!(
11136+ res.body["answers"][0]["answer_image"]["content_type"],
11137+ "image/png"
11138+ );
11094 11139
11095 // Removing the drawing drops the blank answer row it created — the question11140 // Removing the drawing drops the blank answer row it created — the question
11096 // stops showing as answered rather than lingering as an empty text answer.11141 // stops showing as answered rather than lingering as an empty text answer.
11097- let (status, _, _) = common::send_raw(&app, "DELETE", &own, Some(&student), None, Vec::new()).await;11142+ let (status, _, _) =
11143+ common::send_raw(&app, "DELETE", &own, Some(&student), None, Vec::new()).await;
11098 assert_eq!(status, StatusCode::NO_CONTENT);11144 assert_eq!(status, StatusCode::NO_CONTENT);
11099- let res = send(&app, "GET", &format!("/exams/{exam}/attempt/questions"), Some(&student), None).await;11145+ let res = send(
11146+ &app,
11147+ "GET",
11148+ &format!("/exams/{exam}/attempt/questions"),
11149+ Some(&student),
11150+ None,
11151+ )
11152+ .await;
11100 assert_eq!(res.status, StatusCode::OK);11153 assert_eq!(res.status, StatusCode::OK);
11101- assert!(res.body[0]["answer"].is_null(), "blank answer row dropped with its drawing");11154+ assert!(
11155+ res.body[0]["answer"].is_null(),
11156+ "blank answer row dropped with its drawing"
11157+ );
11102 }11158 }
11103 11159
11104 /// The authoring edits that reshape a question also groom its images: a11160 /// The authoring edits that reshape a question also groom its images: a