Skip to content

Commit

Permalink
Fix peer review course instance problem (#1307)
Browse files Browse the repository at this point in the history
  • Loading branch information
nygrenh authored Sep 5, 2024
1 parent ec7a5be commit 9fb5f89
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,11 @@ async fn try_to_select_peer_review_candidate_from_queue(
.await
.optional()?;
if let Some(ess) = ess {
// Peer reviewing only works if there is a course_id and a course instance id in it.
if ess.course_id.is_none() || ess.course_instance_id.is_none() {
warn!(exercise_slide_submission_id = %ess_id, "Selected exercise slide submission that doesn't have a course_id or course_instance_id. Skipping it.");
continue;
};
if ess.deleted_at.is_none() {
return Ok(Some(ess));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,20 +317,47 @@ async fn submit_peer_or_self_review(
payload.exercise_slide_submission_id,
)
.await?;
let receiver_user_exercise_state = user_exercise_states::get_users_current_by_exercise(
&mut conn,
exercise_slide_submission.user_id,
&exercise,
)
.await?;
models::library::peer_or_self_reviewing::create_peer_or_self_review_submission_for_user(
&mut conn,
&exercise,
giver_user_exercise_state,
receiver_user_exercise_state,
payload.0,
)
.await?;

if let Some(receiver_course_instance_id) = exercise_slide_submission.course_instance_id {
let receiver_user_exercise_state = user_exercise_states::get_user_exercise_state_if_exists(
&mut conn,
exercise_slide_submission.user_id,
exercise.id,
user_exercise_states::CourseInstanceOrExamId::Instance(receiver_course_instance_id),
)
.await?;
if let Some(receiver_user_exercise_state) = receiver_user_exercise_state {
models::library::peer_or_self_reviewing::create_peer_or_self_review_submission_for_user(
&mut conn,
&exercise,
giver_user_exercise_state,
receiver_user_exercise_state,
payload.0,
)
.await?;
} else {
warn!(
"No user exercise state found for receiver's exercise slide submission id: {}",
exercise_slide_submission.id
);
return Err(ControllerError::new(
ControllerErrorType::BadRequest,
"No user exercise state found for receiver's exercise slide submission."
.to_string(),
None,
));
}
} else {
warn!(
"No course instance id found for receiver's exercise slide submission id: {}",
exercise_slide_submission.id
);
return Err(ControllerError::new(
ControllerErrorType::BadRequest,
"No course instance id found for receiver's exercise slide submission.".to_string(),
None,
));
}
let token = skip_authorize();
token.authorized_ok(web::Json(true))
}
Expand Down

0 comments on commit 9fb5f89

Please sign in to comment.