Additional info in sinkSubmission-Exceptions
This commit is contained in:
parent
9a6ae9dc49
commit
e98d7849f6
@ -186,7 +186,7 @@ instance Monoid SubmissionSinkState where
|
|||||||
data SubmissionSinkException = DuplicateFileTitle FilePath
|
data SubmissionSinkException = DuplicateFileTitle FilePath
|
||||||
| DuplicateRating
|
| DuplicateRating
|
||||||
| RatingWithoutUpdate
|
| RatingWithoutUpdate
|
||||||
| ForeignRating
|
| ForeignRating CryptoFileNameSubmission
|
||||||
deriving (Typeable, Show)
|
deriving (Typeable, Show)
|
||||||
|
|
||||||
instance Exception SubmissionSinkException
|
instance Exception SubmissionSinkException
|
||||||
@ -277,7 +277,9 @@ sinkSubmission userId mExists isUpdate = do
|
|||||||
Right (submissionId', Rating'{..}) -> do
|
Right (submissionId', Rating'{..}) -> do
|
||||||
$logDebugS "sinkSubmission" $ tshow submissionId'
|
$logDebugS "sinkSubmission" $ tshow submissionId'
|
||||||
|
|
||||||
unless (submissionId' == submissionId) $ throwM ForeignRating
|
unless (submissionId' == submissionId) $ do
|
||||||
|
cID <- encrypt submissionId'
|
||||||
|
throwM $ ForeignRating cID
|
||||||
|
|
||||||
alreadySeen <- gets $ getAny . sinkSeenRating
|
alreadySeen <- gets $ getAny . sinkSeenRating
|
||||||
when alreadySeen $ throwM DuplicateRating
|
when alreadySeen $ throwM DuplicateRating
|
||||||
@ -373,6 +375,16 @@ sinkSubmission userId mExists isUpdate = do
|
|||||||
, SubmissionRatingComment =. Nothing
|
, SubmissionRatingComment =. Nothing
|
||||||
]
|
]
|
||||||
|
|
||||||
|
data SubmissionMultiSinkException
|
||||||
|
= SubmissionSinkException
|
||||||
|
{ submissionSinkId :: CryptoFileNameSubmission
|
||||||
|
, submissionSinkFedFile :: Maybe FilePath
|
||||||
|
, submissionSinkException :: SubmissionSinkException
|
||||||
|
}
|
||||||
|
deriving (Typeable, Show)
|
||||||
|
|
||||||
|
instance Exception SubmissionMultiSinkException
|
||||||
|
|
||||||
sinkMultiSubmission :: UserId
|
sinkMultiSubmission :: UserId
|
||||||
-> Bool {-^ Are these corrections -}
|
-> Bool {-^ Are these corrections -}
|
||||||
-> Sink SubmissionContent (YesodDB UniWorX) (Set SubmissionId)
|
-> Sink SubmissionContent (YesodDB UniWorX) (Set SubmissionId)
|
||||||
@ -411,7 +423,10 @@ sinkMultiSubmission userId isUpdate = do
|
|||||||
Left _ -> error "sinkSubmission returned prematurely"
|
Left _ -> error "sinkSubmission returned prematurely"
|
||||||
Right nSink -> modify $ Map.insert sId nSink
|
Right nSink -> modify $ Map.insert sId nSink
|
||||||
sinks <- execStateLC Map.empty . awaitForever $ \case
|
sinks <- execStateLC Map.empty . awaitForever $ \case
|
||||||
v@(Right (sId, _)) -> lift $ feed sId v
|
v@(Right (sId, _)) -> do
|
||||||
|
cID <- encrypt sId
|
||||||
|
handle (throwM . SubmissionSinkException cID Nothing) $
|
||||||
|
lift $ feed sId v
|
||||||
(Left f@File{..}) -> do
|
(Left f@File{..}) -> do
|
||||||
let
|
let
|
||||||
tryDecrypt :: FilePath -> _ (Either SomeException SubmissionId)
|
tryDecrypt :: FilePath -> _ (Either SomeException SubmissionId)
|
||||||
@ -422,8 +437,15 @@ sinkMultiSubmission userId isUpdate = do
|
|||||||
return . either (const id) (set _1 . Just) msId $ (Nothing, fp)
|
return . either (const id) (set _1 . Just) msId $ (Nothing, fp)
|
||||||
(msId, (joinPath -> fileTitle')) <- foldM acc (Nothing, []) $ splitDirectories fileTitle
|
(msId, (joinPath -> fileTitle')) <- foldM acc (Nothing, []) $ splitDirectories fileTitle
|
||||||
$logDebugS "sinkMultiSubmission" $ tshow (splitDirectories fileTitle, msId, fileTitle')
|
$logDebugS "sinkMultiSubmission" $ tshow (splitDirectories fileTitle, msId, fileTitle')
|
||||||
lift . maybe (const $ return ()) feed msId $ Left f{ fileTitle = fileTitle' }
|
case msId of
|
||||||
fmap Map.keysSet . lift $ mapM (void . closeResumableSink) sinks
|
Nothing -> $logDebugS "sinkMultiSubmission" "Dropped"
|
||||||
|
Just sId -> do
|
||||||
|
cID <- encrypt sId
|
||||||
|
handle (throwM . SubmissionSinkException cID (Just fileTitle)) $
|
||||||
|
lift . feed sId $ Left f{ fileTitle = fileTitle' }
|
||||||
|
fmap Map.keysSet . lift . sequence $ flip Map.mapWithKey sinks $ \sId sink -> do
|
||||||
|
cID <- encrypt sId
|
||||||
|
handle (throwM . SubmissionSinkException cID Nothing) . void $ closeResumableSink sink
|
||||||
|
|
||||||
submissionMatchesSheet :: TermId -> Text -> Text -> CryptoFileNameSubmission -> DB ()
|
submissionMatchesSheet :: TermId -> Text -> Text -> CryptoFileNameSubmission -> DB ()
|
||||||
submissionMatchesSheet tid csh shn cid = do
|
submissionMatchesSheet tid csh shn cid = do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user