chore(lpr): call lpr in qualfication renewal message

This commit is contained in:
Steffen Jost 2022-07-29 16:55:22 +02:00
parent 3ac2151451
commit 4dbf5f35be
3 changed files with 74 additions and 33 deletions

View File

@ -513,7 +513,7 @@ makeCourseUserTable cid acts restrict colChoices psValidator csvColumns = do
, dbParamsFormResult = id , dbParamsFormResult = id
, dbParamsFormIdent = def , dbParamsFormIdent = def
} }
dbtCsvName = MsgCourseUserCsvName courseTerm courseSchool courseShorthand dbtCsvName = MsgCourseUserCsvName courseTerm courseSchool courseShorthand
dbtCsvSheetName = MsgCourseUserCsvSheetName courseTerm courseSchool courseShorthand dbtCsvSheetName = MsgCourseUserCsvSheetName courseTerm courseSchool courseShorthand
dbtCsvEncode = do dbtCsvEncode = do
csvColumns' <- csvColumns csvColumns' <- csvColumns

View File

@ -52,7 +52,10 @@ dispatchNotificationQualificationRenewal nQualification jRecipient = do
-- content = $(i18nWidgetFile "qualification/renewal") -- content = $(i18nWidgetFile "qualification/renewal")
$logDebugS "LMS" $ "Notify " <> tshow jRecipient <> " for renewal of qualifiaction " <> qname $logDebugS "LMS" $ "Notify " <> tshow jRecipient <> " for renewal of qualifiaction " <> qname
let pdfMeta = applyMetas [("recipient", userDisplayName)] mempty -- TODO: add more info to interpolate here! let pdfMeta = applyMetas
[ ("recipient", userDisplayName)
-- TODO: add more info to interpolate here!
] mempty
pdfRenewal pdfMeta >>= \case pdfRenewal pdfMeta >>= \case
Left err -> do Left err -> do
let msg = "Notify " <> tshow jRecipient <> " PDF generation failed with error: " <> err let msg = "Notify " <> tshow jRecipient <> " PDF generation failed with error: " <> err
@ -81,7 +84,12 @@ dispatchNotificationQualificationRenewal nQualification jRecipient = do
-- TODO: this is just a dummy to continue while i18nHamletFile usage is unclear -- TODO: this is just a dummy to continue while i18nHamletFile usage is unclear
addHtmlMarkdownAlternatives $(ihamletFile "templates/mail/qualificationRenewal.hamlet") addHtmlMarkdownAlternatives $(ihamletFile "templates/mail/qualificationRenewal.hamlet")
Right _pdf | otherwise -> do Right pdf | otherwise -> do
let _letterHead = error "TODO" let printJobName = mempty --TODO
-- makePDF "pdflatex" [] writer woptions pandoc lprPDF printJobName pdf >>= \case
error "TODO" Left err -> do
let msg = "Notify " <> tshow jRecipient <> " PDF printing to send letter failed with error: " <> err
$logErrorS "LMS" msg
error $ unpack msg
Right msg | null msg -> return ()
| otherwise -> $logWarnS "LMS" $ "PDF printing to send letter with lpr returned ExitSucces and the following message: " <> msg

View File

@ -272,6 +272,19 @@ sendLetter' printJobName pdf printJobRecipient printJobSender printJobCourse pri
} }
-----------------------------
-- Typed Process Utilities --
-----------------------------
-- | Converts Triple consisting of @ExitCode@, Success- and Failure-Value to Either Failue- or Success-Value.
-- Returns @Right@ if the @ExitCode@ is @ExitsSuccess, entirely ignoring the Failure-Value, which ususally might contain warning messages.
-- To be used with 'System.Process.Typed.readProcess'
exit2either :: (ExitCode, a, b) -> Either b a
exit2either (ExitSuccess , ok, _) = Right ok -- warnings are ignored here!
exit2either (ExitFailure _ , _, err) = Left err
----------- -----------
-- pdftk -- -- pdftk --
----------- -----------
@ -295,6 +308,26 @@ encryptPDF pw bs = over _Left (decodeUtf8 . LBS.toStrict) . exit2either <$> read
-- Note that pdftk will issue a warning, which will be ignored: -- Note that pdftk will issue a warning, which will be ignored:
-- Warning: Using a password on the command line interface can be insecure. -- Warning: Using a password on the command line interface can be insecure.
-- Use the keyword PROMPT to supply a password via standard input instead. -- Use the keyword PROMPT to supply a password via standard input instead.
exit2either :: (ExitCode, a, b) -> Either b a
exit2either (ExitSuccess , ok, _) = Right ok -- warnings are ignored here!
exit2either (ExitFailure _ , _, err) = Left err
---------
-- lpr --
---------
--
-- We use the external tool lpr in the variant supplied by busybox
-- to print pdfs like so:
-- > lpr -P fradrive@fravm017173.fra.fraport.de -J printJobName -
--
lprPDF :: MonadIO m => String -> LBS.ByteString -> m (Either Text Text)
lprPDF jb bs = over _Left (decodeUtf8 . LBS.toStrict) .
over _Right (decodeUtf8 . LBS.toStrict) . exit2either <$> readProcess pc
where
pc = setStdin (byteStringInput bs) $
proc "lpr" $ [ "-P fradrive@fravm017173.fra.fraport.de:515" -- queue@hostname:port TODO: turn this into a setting
] ++ jobname ++ -- a name for job identification at printing site
[ "-" -- read from stdin
]
jobname | null jb = []
| otherwise = ["-J", jb]