fix: end grading when a question stops being open
WR-06: a Question save hook clears grading_status on the answers of a question that changed type away from open, in the save's transaction, so they leave the review queue and needs_review. GradeAnswer ignores a question that is no longer open, and a choice or self-check re-answer clears the text, grade and review columns of its row.
This commit is contained in:
@@ -538,9 +538,17 @@ func (s *Service) Answer(ctx context.Context, userID, attemptID uint, in AnswerI
|
||||
row.IsCorrect, row.Points = res.IsCorrect, res.Points
|
||||
now := s.now().UTC()
|
||||
row.CreatedAt, row.UpdatedAt = now, now
|
||||
// A row left by the question's open past loses its text, grade
|
||||
// and review: a choice or self-check answer has none (its
|
||||
// grading_status NULL keeps a queued grading job from acting).
|
||||
if err := tx.WithContext(ctx).Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "attempt_id"}, {Name: "question_id"}},
|
||||
DoUpdates: clause.AssignmentColumns([]string{"answer_ids", "self_check_known", "is_correct", "points", "updated_at"}),
|
||||
Columns: []clause.Column{{Name: "attempt_id"}, {Name: "question_id"}},
|
||||
DoUpdates: clause.AssignmentColumns([]string{
|
||||
"answer_ids", "self_check_known", "is_correct", "points", "updated_at",
|
||||
"text_answer", "grading_status", "grading_attempts", "grader", "grader_points",
|
||||
"grader_feedback", "grading_error", "graded_at", "review_comment", "reviewed_at",
|
||||
"reviewed_by_user_id", "reviewed_by_admin_id",
|
||||
}),
|
||||
}).Create(&row).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user