diff --git a/src/Handler/Utils/Submission.hs b/src/Handler/Utils/Submission.hs index 169fbcc05..6c14cb496 100644 --- a/src/Handler/Utils/Submission.hs +++ b/src/Handler/Utils/Submission.hs @@ -50,7 +50,7 @@ instance Exception AssignSubmissionException assignSubmissions :: SheetId -> YesodDB UniWorX () assignSubmissions sid = do correctors <- selectList [SheetCorrectorSheet ==. sid] [] - let (corrsGroup, corrsProp) = partition (is _ByTutorial . sheetCorrectorLoad . entityVal) correctors + let (corrsGroup, (filterNonPositive -> corrsProp)) = partition (is _ByTutorial . sheetCorrectorLoad . entityVal) correctors countsToLoad' :: UserId -> Bool countsToLoad' uid = fromMaybe (error "Called `countsToLoad'` on entity not element of `corrsGroup`") $ listToMaybe [sheetCorrectorLoad | Entity _ SheetCorrector{..} <- corrsGroup, sheetCorrectorUser == uid] >>= preview _ByTutorial subs <- E.select . E.from $ \(submission `E.LeftOuterJoin` user) -> do @@ -74,7 +74,7 @@ assignSubmissions sid = do subTutor <- fmap fst . flip execStateT (Map.empty, queue) . forM_ (Map.toList subTutor') $ \case (smid, Just tutid) -> do _1 %= Map.insert smid tutid - when (countsToLoad' tutid) $ + when (any ((== tutid) . sheetCorrectorUser . entityVal) corrsProp && countsToLoad' tutid) $ _2 %= delFirst (Just tutid) (smid, Nothing) -> do (q:qs) <- use _2 @@ -87,6 +87,8 @@ assignSubmissions sid = do return () where + filterNonPositive = filter $ (> 0) . load . sheetCorrectorLoad . entityVal + delFirst _ [] = [] delFirst x (y:ys) | x == y = ys