chore(caching): for company table working
This commit is contained in:
parent
cdcd56ea19
commit
d46ff7ed7f
@ -14,7 +14,7 @@ Company
|
|||||||
UniqueCompanyShorthand shorthand
|
UniqueCompanyShorthand shorthand
|
||||||
-- UniqueCompanyAvsId avsId -- should be the case, unclear if enforcing works here, since we cannot query avs by company id
|
-- UniqueCompanyAvsId avsId -- should be the case, unclear if enforcing works here, since we cannot query avs by company id
|
||||||
Primary shorthand -- newtype Key Company = CompanyKey { unSchoolKey :: CompanyShorthand }
|
Primary shorthand -- newtype Key Company = CompanyKey { unSchoolKey :: CompanyShorthand }
|
||||||
deriving Ord Eq Show Generic
|
deriving Ord Eq Show Generic Binary
|
||||||
|
|
||||||
-- TODO: a way to populate this table (manually)
|
-- TODO: a way to populate this table (manually)
|
||||||
CompanySynonym
|
CompanySynonym
|
||||||
|
|||||||
@ -147,6 +147,8 @@ dependencies:
|
|||||||
- extended-reals
|
- extended-reals
|
||||||
- rfc5051
|
- rfc5051
|
||||||
- unidecode
|
- unidecode
|
||||||
|
- doctemplates
|
||||||
|
- doclayout
|
||||||
- pandoc
|
- pandoc
|
||||||
- pandoc-types
|
- pandoc-types
|
||||||
- typed-process
|
- typed-process
|
||||||
|
|||||||
@ -367,19 +367,17 @@ mkLmsTable :: ( Functor h, ToSortable h
|
|||||||
=> Bool
|
=> Bool
|
||||||
-> Entity Qualification
|
-> Entity Qualification
|
||||||
-> Map LmsTableAction (AForm Handler LmsTableActionData)
|
-> Map LmsTableAction (AForm Handler LmsTableActionData)
|
||||||
-> (Map CompanyId (Entity Company) -> cols)
|
-> (Map CompanyId Company -> cols)
|
||||||
-> PSValidator (MForm Handler) (FormResult (First LmsTableActionData, DBFormResult UserId Bool LmsTableData))
|
-> PSValidator (MForm Handler) (FormResult (First LmsTableActionData, DBFormResult UserId Bool LmsTableData))
|
||||||
-> DB (FormResult (LmsTableActionData, Set UserId), Widget)
|
-> DB (FormResult (LmsTableActionData, Set UserId), Widget)
|
||||||
mkLmsTable isAdmin (Entity qid quali) acts cols psValidator = do
|
mkLmsTable isAdmin (Entity qid quali) acts cols psValidator = do
|
||||||
now <- liftIO getCurrentTime
|
now <- liftIO getCurrentTime
|
||||||
let
|
|
||||||
nowaday = utctDay now
|
|
||||||
companyStamp = "CompanyMap" <> tshow (roundDownToMinutes 5 now)
|
|
||||||
-- lookup all companies
|
-- lookup all companies
|
||||||
cmpMap <- $cachedHereBinary companyStamp $ do
|
cmpMap <- memcachedBy (Just . Right $ 5 * diffMinute) ("CompanyDictionary"::Text) $ do
|
||||||
cmps <- selectList [] [Asc CompanyId]
|
cmps <- selectList [] [Asc CompanyId]
|
||||||
return $ Map.fromAscList $ fmap (\c -> (entityKey c, c)) cmps
|
return $ Map.fromAscList $ fmap (\c -> (entityKey c, entityVal c)) cmps
|
||||||
let
|
let
|
||||||
|
nowaday = utctDay now
|
||||||
-- mbRenewal = addGregorianDurationClip <$> qualificationRefreshWithin quali <*> Just nowaday
|
-- mbRenewal = addGregorianDurationClip <$> qualificationRefreshWithin quali <*> Just nowaday
|
||||||
csvName = T.replace " " "-" $ CI.original (quali ^. _qualificationName)
|
csvName = T.replace " " "-" $ CI.original (quali ^. _qualificationName)
|
||||||
dbtIdent :: Text
|
dbtIdent :: Text
|
||||||
@ -496,8 +494,8 @@ mkLmsTable isAdmin (Entity qid quali) acts cols psValidator = do
|
|||||||
<*> (join . preview (resultLmsUser . _entityVal . _lmsUserEnded))
|
<*> (join . preview (resultLmsUser . _entityVal . _lmsUserEnded))
|
||||||
getCompanies cmps = case mapMaybe (flip Map.lookup cmpMap . view (_entityVal . _userCompanyCompany)) cmps of
|
getCompanies cmps = case mapMaybe (flip Map.lookup cmpMap . view (_entityVal . _userCompanyCompany)) cmps of
|
||||||
[] -> pure Nothing
|
[] -> pure Nothing
|
||||||
somecmps -> pure $ Just $ intercalate ", " $ fmap (view (_entityVal . _companyName . _CI)) somecmps
|
somecmps -> pure $ Just $ intercalate ", " $ fmap (view (_companyName . _CI)) somecmps
|
||||||
getCompanyNos = pure . CsvSemicolonList . mapMaybe (preview (_Just . _entityVal . _companyAvsId) . flip Map.lookup cmpMap . view (_entityVal . _userCompanyCompany))
|
getCompanyNos = pure . CsvSemicolonList . mapMaybe (preview (_Just . _companyAvsId) . flip Map.lookup cmpMap . view (_entityVal . _userCompanyCompany))
|
||||||
|
|
||||||
dbtCsvDecode = Nothing
|
dbtCsvDecode = Nothing
|
||||||
dbtExtraReps = []
|
dbtExtraReps = []
|
||||||
@ -555,7 +553,7 @@ postLmsR sid qsh = do
|
|||||||
cs = [ (cmpName, cmpSpr)
|
cs = [ (cmpName, cmpSpr)
|
||||||
| Entity _ UserCompany{userCompanyCompany=cmpId, userCompanySupervisor=cmpSpr} <- cmps
|
| Entity _ UserCompany{userCompanyCompany=cmpId, userCompanySupervisor=cmpSpr} <- cmps
|
||||||
, let cmpEnt = Map.lookup cmpId cmpMap
|
, let cmpEnt = Map.lookup cmpId cmpMap
|
||||||
, Just (Entity _ Company{companyName = cmpName}) <- [cmpEnt]
|
, Just Company{companyName = cmpName} <- [cmpEnt]
|
||||||
]
|
]
|
||||||
companies = intercalate (text2markup ", ") $
|
companies = intercalate (text2markup ", ") $
|
||||||
(\(cmpName, cmpSpr) -> text2markup (CI.original cmpName) <> bool mempty icnSuper cmpSpr) <$> cs
|
(\(cmpName, cmpSpr) -> text2markup (CI.original cmpName) <> bool mempty icnSuper cmpSpr) <$> cs
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
-- SPDX-FileCopyrightText: 2023 Steffen Jost <jost@cip.ifi.lmu.de>,Steffen Jost <jost@tcs.ifi.lmu.de>
|
-- SPDX-FileCopyrightText: 2022-23 Steffen Jost <S.Jost@fraport.de>,Steffen Jost <jost@tcs.ifi.lmu.de>
|
||||||
--
|
--
|
||||||
-- SPDX-License-Identifier: AGPL-3.0-or-later
|
-- SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
@ -304,20 +304,18 @@ mkQualificationTable ::
|
|||||||
=> Bool
|
=> Bool
|
||||||
-> Entity Qualification
|
-> Entity Qualification
|
||||||
-> Map QualificationTableAction (AForm Handler QualificationTableActionData)
|
-> Map QualificationTableAction (AForm Handler QualificationTableActionData)
|
||||||
-> (Map CompanyId (Entity Company) -> cols)
|
-> (Map CompanyId Company -> cols)
|
||||||
-> PSValidator (MForm Handler) (FormResult (First QualificationTableActionData, DBFormResult UserId Bool QualificationTableData))
|
-> PSValidator (MForm Handler) (FormResult (First QualificationTableActionData, DBFormResult UserId Bool QualificationTableData))
|
||||||
-> DB (FormResult (QualificationTableActionData, Set UserId), Widget)
|
-> DB (FormResult (QualificationTableActionData, Set UserId), Widget)
|
||||||
mkQualificationTable isAdmin (Entity qid quali) acts cols psValidator = do
|
mkQualificationTable isAdmin (Entity qid quali) acts cols psValidator = do
|
||||||
svs <- getSupervisees
|
svs <- getSupervisees
|
||||||
now <- liftIO getCurrentTime
|
now <- liftIO getCurrentTime
|
||||||
|
-- lookup all companies
|
||||||
|
cmpMap <- memcachedBy (Just . Right $ 5 * diffMinute) ("CompanyDictionary"::Text) $ do
|
||||||
|
cmps <- selectList [] [Asc CompanyId]
|
||||||
|
return $ Map.fromAscList $ fmap (\c -> (entityKey c, entityVal c)) cmps
|
||||||
let
|
let
|
||||||
nowaday = utctDay now
|
nowaday = utctDay now
|
||||||
companyStamp = "CompanyMap" <> tshow (roundDownToMinutes 5 now)
|
|
||||||
-- lookup all companies
|
|
||||||
cmpMap <- $cachedHereBinary companyStamp $ do
|
|
||||||
cmps <- selectList [] [Asc CompanyId]
|
|
||||||
return $ Map.fromAscList $ fmap (\c -> (entityKey c, c)) cmps
|
|
||||||
let
|
|
||||||
mbRenewal = addGregorianDurationClip <$> qualificationRefreshWithin quali <*> Just nowaday
|
mbRenewal = addGregorianDurationClip <$> qualificationRefreshWithin quali <*> Just nowaday
|
||||||
csvName = T.replace " " "-" $ CI.original (quali ^. _qualificationName)
|
csvName = T.replace " " "-" $ CI.original (quali ^. _qualificationName)
|
||||||
dbtIdent :: Text
|
dbtIdent :: Text
|
||||||
@ -412,10 +410,10 @@ mkQualificationTable isAdmin (Entity qid quali) acts cols psValidator = do
|
|||||||
<*> view (resultQualUser . _entityVal . _qualificationUserScheduleRenewal)
|
<*> view (resultQualUser . _entityVal . _qualificationUserScheduleRenewal)
|
||||||
<*> getStatusPlusTxt
|
<*> getStatusPlusTxt
|
||||||
<*> getStatusPlusDay
|
<*> getStatusPlusDay
|
||||||
getCompanies cmps = case mapMaybe (flip Map.lookup cmpMap . view (_entityVal . _userCompanyCompany)) cmps of
|
getCompanies cmps = case mapMaybe (flip Map.lookup cmpMap . view (_entityVal . _userCompanyCompany)) cmps of
|
||||||
[] -> pure Nothing
|
[] -> pure Nothing
|
||||||
somecmps -> pure $ Just $ intercalate ", " $ fmap (view (_entityVal . _companyName . _CI)) somecmps
|
somecmps -> pure $ Just $ intercalate ", " $ fmap (view (_companyName . _CI)) somecmps
|
||||||
getCompanyNos = pure . CsvSemicolonList . mapMaybe (preview (_Just . _entityVal . _companyAvsId) . flip Map.lookup cmpMap . view (_entityVal . _userCompanyCompany))
|
getCompanyNos = pure . CsvSemicolonList . mapMaybe (preview (_Just . _companyAvsId) . flip Map.lookup cmpMap . view (_entityVal . _userCompanyCompany))
|
||||||
|
|
||||||
getStatusPlusTxt =
|
getStatusPlusTxt =
|
||||||
(join . preview (resultLmsUser . _entityVal . _lmsUserStatus)) >>= \case
|
(join . preview (resultLmsUser . _entityVal . _lmsUserStatus)) >>= \case
|
||||||
@ -486,7 +484,7 @@ postQualificationR sid qsh = do
|
|||||||
cs = [ (cmpName, cmpSpr)
|
cs = [ (cmpName, cmpSpr)
|
||||||
| Entity _ UserCompany{userCompanyCompany=cmpId, userCompanySupervisor=cmpSpr} <- cmps
|
| Entity _ UserCompany{userCompanyCompany=cmpId, userCompanySupervisor=cmpSpr} <- cmps
|
||||||
, let cmpEnt = Map.lookup cmpId cmpMap
|
, let cmpEnt = Map.lookup cmpId cmpMap
|
||||||
, Just (Entity _ Company{companyName = cmpName}) <- [cmpEnt]
|
, Just Company{companyName = cmpName} <- [cmpEnt]
|
||||||
]
|
]
|
||||||
companies = intercalate (text2markup ", ") $
|
companies = intercalate (text2markup ", ") $
|
||||||
(\(cmpName, cmpSpr) -> text2markup (CI.original cmpName) <> bool mempty icnSuper cmpSpr) <$> cs
|
(\(cmpName, cmpSpr) -> text2markup (CI.original cmpName) <> bool mempty icnSuper cmpSpr) <$> cs
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
-- SPDX-FileCopyrightText: 2023 Gregor Kleen <gregor.kleen@ifi.lmu.de>,Sarah Vaupel <sarah.vaupel@ifi.lmu.de>,Sarah Vaupel <vaupel.sarah@campus.lmu.de>,Steffen Jost <jost@tcs.ifi.lmu.de>,Winnie Ros <winnie.ros@campus.lmu.de>
|
-- SPDX-FileCopyrightText: 2022-23 Gregor Kleen <gregor.kleen@ifi.lmu.de>,Sarah Vaupel <sarah.vaupel@ifi.lmu.de>,Sarah Vaupel <vaupel.sarah@campus.lmu.de>,Steffen Jost <jost@tcs.ifi.lmu.de>,Winnie Ros <winnie.ros@campus.lmu.de>
|
||||||
--
|
--
|
||||||
-- SPDX-License-Identifier: AGPL-3.0-or-later
|
-- SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ import Auth.Dummy (apDummy)
|
|||||||
|
|
||||||
|
|
||||||
hijackUserForm :: Form ()
|
hijackUserForm :: Form ()
|
||||||
hijackUserForm = identifyForm FIDHijackUser $ \csrf -> do
|
hijackUserForm = \csrf -> do
|
||||||
(btnResult, btnView) <- mopt (buttonField BtnHijack) "" Nothing
|
(btnResult, btnView) <- mopt (buttonField BtnHijack) "" Nothing
|
||||||
return (btnResult >>= guard . is _Just, mconcat [toWidget csrf, fvWidget btnView])
|
return (btnResult >>= guard . is _Just, mconcat [toWidget csrf, fvWidget btnView])
|
||||||
|
|
||||||
|
|||||||
@ -128,7 +128,7 @@ makeClassyFor_ ''LmsResult
|
|||||||
makeClassyFor_ ''UserAvs
|
makeClassyFor_ ''UserAvs
|
||||||
makeClassyFor_ ''UserAvsCard
|
makeClassyFor_ ''UserAvsCard
|
||||||
|
|
||||||
makeClassyFor_ ''UserCompany
|
makeLenses_ ''UserCompany
|
||||||
makeLenses_ ''Company
|
makeLenses_ ''Company
|
||||||
|
|
||||||
_entityKey :: Getter (Entity record) (Key record)
|
_entityKey :: Getter (Entity record) (Key record)
|
||||||
|
|||||||
@ -42,6 +42,7 @@ import Text.Hamlet
|
|||||||
import System.Exit
|
import System.Exit
|
||||||
import System.Process.Typed -- for calling pdftk for pdf encryption
|
import System.Process.Typed -- for calling pdftk for pdf encryption
|
||||||
|
|
||||||
|
-- import Handler.Utils.Memcached
|
||||||
import Handler.Utils.Users
|
import Handler.Utils.Users
|
||||||
import Handler.Utils.DateTime
|
import Handler.Utils.DateTime
|
||||||
import Handler.Utils.Mail
|
import Handler.Utils.Mail
|
||||||
@ -49,6 +50,7 @@ import Handler.Utils.Widgets (nameHtml')
|
|||||||
import Handler.Utils.Avs (updateReceivers)
|
import Handler.Utils.Avs (updateReceivers)
|
||||||
import Jobs.Handler.SendNotification.Utils
|
import Jobs.Handler.SendNotification.Utils
|
||||||
|
|
||||||
|
-- import Utils.Print.Instances
|
||||||
import Utils.Print.Letters
|
import Utils.Print.Letters
|
||||||
import Utils.Print.RenewQualification
|
import Utils.Print.RenewQualification
|
||||||
import Utils.Print.CourseCertificate
|
import Utils.Print.CourseCertificate
|
||||||
@ -113,8 +115,10 @@ mdTemplating template meta = runExceptT $ do
|
|||||||
let readerOpts = def { P.readerExtensions = P.pandocExtensions
|
let readerOpts = def { P.readerExtensions = P.pandocExtensions
|
||||||
, P.readerStripComments = True
|
, P.readerStripComments = True
|
||||||
}
|
}
|
||||||
doc <- ExceptT $ $cachedHereBinary ("pandoc: \n" <> template) (pure . P.runPure $ P.readMarkdown readerOpts template)
|
-- doc <- ExceptT $ memcachedBy (Just . Right $ 6 * diffHour) ("pandoc-md: \n" <> template) (pure . P.runPure $ P.readMarkdown readerOpts template)
|
||||||
tmpl <- ExceptT $ $cachedHereBinary ("template: \n" <> template) (pure . P.runPure $ compileTemplate template)
|
-- tmpl <- ExceptT $ memcachedBy (Just . Right $ 6 * diffHour) ("template-md: \n" <> template) (pure . P.runPure $ compileTemplate template)
|
||||||
|
doc <- ExceptT (pure . P.runPure $ P.readMarkdown readerOpts template)
|
||||||
|
tmpl <- ExceptT (pure . P.runPure $ compileTemplate template)
|
||||||
let writerOpts = def { P.writerExtensions = P.pandocExtensions
|
let writerOpts = def { P.writerExtensions = P.pandocExtensions
|
||||||
, P.writerTemplate = Just tmpl
|
, P.writerTemplate = Just tmpl
|
||||||
}
|
}
|
||||||
@ -126,7 +130,8 @@ mdTemplating template meta = runExceptT $ do
|
|||||||
-- | creates a PDF using a LaTeX template
|
-- | creates a PDF using a LaTeX template
|
||||||
pdfLaTeX :: LetterKind -> P.Pandoc -> HandlerFor UniWorX (Either P.PandocError LBS.ByteString)
|
pdfLaTeX :: LetterKind -> P.Pandoc -> HandlerFor UniWorX (Either P.PandocError LBS.ByteString)
|
||||||
pdfLaTeX lk doc = do
|
pdfLaTeX lk doc = do
|
||||||
e_tmpl <- $cachedHereBinary ("LetterKind:" <> tshow lk) (liftIO . P.runIO $ compileTemplate $ templateLatex lk)
|
e_tmpl <- liftIO . P.runIO $ compileTemplate $ templateLatex lk
|
||||||
|
-- e_tmpl <- memcachedBy (Just . Right $ 6 * diffHour) ("LetterKind-latex: \n" <> tshow lk) (liftIO . P.runIO $ compileTemplate $ templateLatex lk)
|
||||||
actRight e_tmpl $ \tmpl -> liftIO . P.runIO $ do
|
actRight e_tmpl $ \tmpl -> liftIO . P.runIO $ do
|
||||||
let writerOpts = def { P.writerExtensions = P.pandocExtensions
|
let writerOpts = def { P.writerExtensions = P.pandocExtensions
|
||||||
, P.writerTemplate = Just tmpl }
|
, P.writerTemplate = Just tmpl }
|
||||||
@ -377,7 +382,7 @@ encryptPDF pw bs = over _Left (decodeUtf8 . LBS.toStrict) . exit2either <$> read
|
|||||||
-- | Internal only, use `printLetter` instead
|
-- | Internal only, use `printLetter` instead
|
||||||
lprPDF :: (MonadHandler m, HasAppSettings (HandlerSite m)) => FilePath -> LBS.ByteString -> m (Either Text Text)
|
lprPDF :: (MonadHandler m, HasAppSettings (HandlerSite m)) => FilePath -> LBS.ByteString -> m (Either Text Text)
|
||||||
lprPDF (sanitizeCmdArg' -> jb) bs = do
|
lprPDF (sanitizeCmdArg' -> jb) bs = do
|
||||||
mbLprServerArg <- $cachedHereBinary ("lprServer"::Text) getLprServerArg
|
mbLprServerArg <- getLprServerArg
|
||||||
case mbLprServerArg of
|
case mbLprServerArg of
|
||||||
Nothing -> return $ Right "Print command ignored due to setting 'mail-reroute-to' being set."
|
Nothing -> return $ Right "Print command ignored due to setting 'mail-reroute-to' being set."
|
||||||
Just lprServerArg -> do
|
Just lprServerArg -> do
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
-- SPDX-FileCopyrightText: 2022 Steffen Jost <jost@tcs.ifi.lmu.de>
|
-- SPDX-FileCopyrightText: 2022-23 Steffen Jost <jost@tcs.ifi.lmu.de>
|
||||||
--
|
--
|
||||||
-- SPDX-License-Identifier: AGPL-3.0-or-later
|
-- SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user