From ee9481ebd8261048d7bb24f009cc3fc827c02db1 Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Wed, 22 Mar 2023 15:36:18 +0000 Subject: [PATCH] chore(letter): letters may choose attachment encryption --- src/Utils/Print.hs | 6 +++++- src/Utils/Print/Letters.hs | 6 +++++- src/Utils/Print/RenewQualification.hs | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Utils/Print.hs b/src/Utils/Print.hs index 6c65b335c..55b81a0c8 100644 --- a/src/Utils/Print.hs +++ b/src/Utils/Print.hs @@ -251,7 +251,11 @@ sendEmailOrLetter recipient letter = do $logWarnS "LETTER" $ "PDF printing to send letter with lpr returned ExitSuccess and the following message: " <> msg return True Right pdf -> do -- send email - attachment <- case underling ^. _userPinPassword of + let pdfPass = case encrypPDFfor (pure letter) of + NoPassword -> Nothing + PasswordSupervisor -> rcvrUsr ^. _userPinPassword + PasswordUnderling -> underling ^. _userPinPassword + attachment <- case pdfPass of Nothing -> return pdf Just passwd -> encryptPDF passwd pdf >>= \case Right encPdf -> return encPdf diff --git a/src/Utils/Print/Letters.hs b/src/Utils/Print/Letters.hs index 82212c8be..9a92a1ea8 100644 --- a/src/Utils/Print/Letters.hs +++ b/src/Utils/Print/Letters.hs @@ -214,6 +214,9 @@ convertProto _ (IsMeta v) = v convertProto f (IsTime t) = P.toMetaValue $ f t -} +data EncryptPDFfor = NoPassword | PasswordSupervisor | PasswordUnderling + deriving (Eq, Show) + class MDLetter l where getMailSubject :: l -> SomeMessage UniWorX -- only used if letter is sent by email as pdf attachment getMailBody :: l -> DateTimeFormatter -> HtmlUrlI18n (SomeMessage UniWorX) (Route UniWorX) -- only used if letter is sent by email as pdf attachment @@ -221,7 +224,8 @@ class MDLetter l where getPJId :: l -> PrintJobIdentification getLetterEnvelope :: l -> Char getLetterKind :: Proxy l -> LetterKind - getTemplate :: Proxy l -> Text + getTemplate :: Proxy l -> Text + encrypPDFfor :: Proxy l -> EncryptPDFfor letterApcIdent :: (MDLetter l, MonadHandler m) => l -> CryptoUUIDUser -> UTCTime -> m Text letterApcIdent l uuid now = do diff --git a/src/Utils/Print/RenewQualification.hs b/src/Utils/Print/RenewQualification.hs index c4983c760..55496a840 100644 --- a/src/Utils/Print/RenewQualification.hs +++ b/src/Utils/Print/RenewQualification.hs @@ -47,6 +47,7 @@ letterRenewalQualificationFData LetterRenewQualificationF{lmsLogin} = LetterRene lmsIdent = getLmsIdent lmsLogin instance MDLetter LetterRenewQualificationF where + encrypPDFfor _ = PasswordUnderling getLetterKind _ = PinLetter getLetterEnvelope l = maybe 'q' (Char.toLower . fst) $ Text.uncons (qualShort l) getTemplate _ = decodeUtf8 $(Data.FileEmbed.embedFile "templates/letter/fraport_renewal.md")