diff --git a/src/Handler/Corrections.hs b/src/Handler/Corrections.hs index 73f0df665..67bba1394 100644 --- a/src/Handler/Corrections.hs +++ b/src/Handler/Corrections.hs @@ -517,31 +517,32 @@ postCorrectionR tid ssh csh shn cid = do case corrResult of FormMissing -> return () FormFailure errs -> mapM_ (addMessage Error . toHtml) errs - FormSuccess (rated, ratingPoints', ratingComment') - | errs <- validateRating sheetType Rating' - { ratingPoints=ratingPoints' - , ratingComment=ratingComment' - , ratingTime=Nothing - } - -> mapM_ (addMessageI Error) errs - | otherwise -> do - runDBJobs $ do - uid <- liftHandlerT requireAuthId - now <- liftIO getCurrentTime + FormSuccess (rated, ratingPoints', ratingComment') -> do + uid <- liftHandlerT requireAuthId + now <- liftIO getCurrentTime - update sub [ SubmissionRatingBy =. Just uid - , SubmissionRatingTime =. (now <$ guard rated) - , SubmissionRatingPoints =. ratingPoints' - , SubmissionRatingComment =. ratingComment' - ] + if + | errs <- validateRating sheetType Rating' + { ratingPoints = ratingPoints' + , ratingComment = ratingComment' + , ratingTime = (now <$ guard rated) + } + , not $ null errs + -> mapM_ (addMessageI Error) errs + | otherwise -> runDBJobs $ do + update sub [ SubmissionRatingBy =. Just uid + , SubmissionRatingTime =. (now <$ guard rated) + , SubmissionRatingPoints =. ratingPoints' + , SubmissionRatingComment =. ratingComment' + ] - addMessageI Success $ bool MsgRatingDeleted MsgRatingUpdated rated + addMessageI Success $ bool MsgRatingDeleted MsgRatingUpdated rated - when (rated && isNothing submissionRatingTime) $ do - $logDebugS "CorrectionR" [st|Rated #{tshow sub}|] - queueDBJob . JobQueueNotification $ NotificationSubmissionRated sub + when (rated && isNothing submissionRatingTime) $ do + $logDebugS "CorrectionR" [st|Rated #{tshow sub}|] + queueDBJob . JobQueueNotification $ NotificationSubmissionRated sub - redirect $ CSubmissionR tid ssh csh shn cid CorrectionR + redirect $ CSubmissionR tid ssh csh shn cid CorrectionR case uploadResult of FormMissing -> return ()