chore(apc): adjust print acknowledging to deal with apcident in a backward compatible way
This commit is contained in:
parent
03971135e3
commit
81a30fadc4
@ -373,7 +373,11 @@ postPrintAckR ackDay numAck chksm = do
|
|||||||
ackForm
|
ackForm
|
||||||
|
|
||||||
-- no header csv, containing a single column of lms identifiers (logins)
|
-- no header csv, containing a single column of lms identifiers (logins)
|
||||||
instance Csv.FromRecord LmsIdent -- default suffices
|
-- instance Csv.FromRecord LmsIdent -- default suffices
|
||||||
|
instance Csv.FromRecord Text where
|
||||||
|
parseRecord v
|
||||||
|
| length v == 1 = v Csv..! 1
|
||||||
|
| otherwise = mzero
|
||||||
|
|
||||||
postPrintAckDirectR :: Handler Html
|
postPrintAckDirectR :: Handler Html
|
||||||
postPrintAckDirectR = do
|
postPrintAckDirectR = do
|
||||||
@ -388,22 +392,27 @@ postPrintAckDirectR = do
|
|||||||
Left (e :: SomeException) -> do -- catch all to avoid ok220 in case of any error
|
Left (e :: SomeException) -> do -- catch all to avoid ok220 in case of any error
|
||||||
$logWarnS "APC" $ "Result upload failed parsing: " <> tshow e
|
$logWarnS "APC" $ "Result upload failed parsing: " <> tshow e
|
||||||
return (badRequest400, "Error: " <> tshow e)
|
return (badRequest400, "Error: " <> tshow e)
|
||||||
Right lids -> do
|
Right reqIds -> do
|
||||||
|
let nrReq = length reqIds
|
||||||
now <- liftIO getCurrentTime
|
now <- liftIO getCurrentTime
|
||||||
nr <- updateWhereCount
|
nrApcIds <- updateWhereCount
|
||||||
[PrintJobAcknowledged ==. Nothing, PrintJobLmsUser <-. (Just <$> lids)]
|
[PrintJobAcknowledged ==. Nothing, PrintJobApcIdent <-. reqIds]
|
||||||
[PrintJobAcknowledged =. Just now]
|
[PrintJobAcknowledged =. Just now]
|
||||||
let lenLids = length lids
|
nrOk <- if nrApcIds > 0 && nrReq > 0
|
||||||
if | lenLids <= 0 -> do
|
then updateWhereCount -- for downwards compatibility only
|
||||||
let msg = "Error: No print job was acknowledged as printed, but " <> tshow lenLids <> " were requested to be, for file " <> fhead
|
[PrintJobAcknowledged ==. Nothing, PrintJobLmsUser <-. (Just . LmsIdent . dropPrefixText "lms-" <$> reqIds)]
|
||||||
|
[PrintJobAcknowledged =. Just now]
|
||||||
|
else return nrApcIds
|
||||||
|
if | nrReq <= 0 -> do
|
||||||
|
let msg = "Error: No print job was acknowledged as printed, but " <> tshow nrReq <> " were requested to be, for file " <> fhead
|
||||||
$logErrorS "APC" msg
|
$logErrorS "APC" msg
|
||||||
return (badRequest400, msg)
|
return (badRequest400, msg)
|
||||||
| lenLids == fromIntegral nr -> do
|
| nrReq == fromIntegral nrOk -> do
|
||||||
let msg = "Success: " <> tshow nr <> " print jobs were acknowledged as printed, for file " <> fhead
|
let msg = "Success: " <> tshow nrOk <> " print jobs were acknowledged as printed, for file " <> fhead
|
||||||
$logInfoS "APC" msg
|
$logInfoS "APC" msg
|
||||||
return (ok200, msg)
|
return (ok200, msg)
|
||||||
| otherwise -> do
|
| otherwise -> do
|
||||||
let msg = "Warning: Only " <> tshow nr <> " print jobs out of " <> tshow lenLids <> " were acknowledged as printed, for file " <> fhead
|
let msg = "Warning: Only " <> tshow nrOk <> " print jobs out of " <> tshow nrReq <> " were acknowledged as printed, for file " <> fhead
|
||||||
$logWarnS "APC" msg
|
$logWarnS "APC" msg
|
||||||
return (ok200, msg)
|
return (ok200, msg)
|
||||||
[] -> do
|
[] -> do
|
||||||
|
|||||||
@ -150,7 +150,7 @@ randomText extra n = fmap pack . evalRandTIO . replicateM n $ uniform range
|
|||||||
-- eopt = Elo.genOptions -- { genCapitals = False, genSpecials = False, genDigitis = True }
|
-- eopt = Elo.genOptions -- { genCapitals = False, genSpecials = False, genDigitis = True }
|
||||||
|
|
||||||
randomLMSIdent :: MonadIO m => m LmsIdent
|
randomLMSIdent :: MonadIO m => m LmsIdent
|
||||||
randomLMSIdent = LmsIdent <$> randomText [] lengthIdent
|
randomLMSIdent = LmsIdent <$> randomText [] lengthIdent -- idents must not contain '_' nor '-'
|
||||||
|
|
||||||
randomLMSIdentBut :: MonadIO m => Set LmsIdent -> m (Maybe LmsIdent)
|
randomLMSIdentBut :: MonadIO m => Set LmsIdent -> m (Maybe LmsIdent)
|
||||||
randomLMSIdentBut banList = untilJustMaxM maxLmsUserIdentRetries getIdentOk
|
randomLMSIdentBut banList = untilJustMaxM maxLmsUserIdentRetries getIdentOk
|
||||||
@ -159,8 +159,8 @@ randomLMSIdentBut banList = untilJustMaxM maxLmsUserIdentRetries getIdentOk
|
|||||||
l <- randomLMSIdent
|
l <- randomLMSIdent
|
||||||
return $ toMaybe (Set.notMember l banList) l
|
return $ toMaybe (Set.notMember l banList) l
|
||||||
|
|
||||||
randomLMSpw :: MonadIO m => m Text
|
randomLMSpw :: MonadIO m => m Text -- may contain all kinds of symbols, but our users had trouble with some, like ',' '.' ':' '_'
|
||||||
randomLMSpw = randomText extra lengthPassword
|
randomLMSpw = randomText extra lengthPassword
|
||||||
where
|
where
|
||||||
extra = "+=!?" -- you cannot distinguish ;: and ., in printed letters
|
extra = "+=!?" -- you cannot distinguish ;: and ., in printed letters
|
||||||
|
|
||||||
|
|||||||
@ -287,6 +287,12 @@ textElem c = Text.any (c ==)
|
|||||||
stripAll :: Text -> Text
|
stripAll :: Text -> Text
|
||||||
stripAll = Text.filter (not . isSpace)
|
stripAll = Text.filter (not . isSpace)
|
||||||
|
|
||||||
|
-- | Strips an optional prefix. Like `Data.Text.stripPrefix` but returns input text if the prefix is not matched, micking the behaviour of `dropPrefix` for `Data.Text`
|
||||||
|
dropPrefixText :: Text -> Text -> Text
|
||||||
|
-- dropPrefixText p t = fromMaybe t $ stripPrefix p t
|
||||||
|
dropPrefixText p (stripPrefix p -> Just t) = t
|
||||||
|
dropPrefixText _ other = other
|
||||||
|
|
||||||
-- | take first line, only
|
-- | take first line, only
|
||||||
cropText :: Text -> Text
|
cropText :: Text -> Text
|
||||||
cropText (Text.take 255 -> t) = headDef t $ Text.lines t
|
cropText (Text.take 255 -> t) = headDef t $ Text.lines t
|
||||||
|
|||||||
Reference in New Issue
Block a user