From 1f7c175a581d32b74fcc1c0debbc228f649c379c Mon Sep 17 00:00:00 2001 From: Steffen Date: Thu, 11 Apr 2024 17:39:19 +0200 Subject: [PATCH] refactor(avs): rework guessAvsUser --- src/Application.hs | 2 +- src/Foundation/Type.hs | 2 +- src/Handler/Admin/Avs.hs | 380 ++++++++++++++--------------- src/Handler/Utils/Avs.hs | 83 +++++-- src/Handler/Utils/Table/Columns.hs | 10 +- src/Jobs/Handler/SynchroniseAvs.hs | 7 +- src/Utils/Avs.hs | 2 +- 7 files changed, 263 insertions(+), 223 deletions(-) diff --git a/src/Application.hs b/src/Application.hs index 4b60ecb39..83bda733e 100644 --- a/src/Application.hs +++ b/src/Application.hs @@ -124,7 +124,7 @@ import Handler.Utils.Memcached (manageMemcachedLocalInvalidations) import qualified System.Clock as Clock -import Utils.Avs +import Utils.Avs (mkAvsQuery) -- Import all relevant handler modules here. -- (HPack takes care to add new modules to our cabal file nowadays.) diff --git a/src/Foundation/Type.hs b/src/Foundation/Type.hs index 5c77e9863..162eb0887 100644 --- a/src/Foundation/Type.hs +++ b/src/Foundation/Type.hs @@ -43,7 +43,7 @@ import Data.Time.Clock.POSIX (POSIXTime) import GHC.Fingerprint (Fingerprint) import Handler.Sheet.PersonalisedFiles.Types (PersonalisedSheetFilesSeedKey) -import Utils.Avs (AvsQuery) +import Utils.Avs (AvsQuery()) type SMTPPool = Pool SMTPConnection diff --git a/src/Handler/Admin/Avs.hs b/src/Handler/Admin/Avs.hs index 836e7e6dc..1d7a05cf5 100644 --- a/src/Handler/Admin/Avs.hs +++ b/src/Handler/Admin/Avs.hs @@ -28,8 +28,6 @@ import Handler.Utils import Handler.Utils.Avs -- import Handler.Utils.Qualification -import Utils.Avs - import Database.Esqueleto.Experimental ((:&)(..)) import qualified Database.Esqueleto.Legacy as E @@ -43,6 +41,13 @@ import qualified Database.Esqueleto.Utils as E single :: (k,a) -> Map k a single = uncurry Map.singleton +exceptionWgt :: SomeException -> Widget +exceptionWgt (SomeException e) = [whamlet|

Error:

#{tshow e}|] + +tryShow :: MonadCatch m => m Widget -> m Widget +tryShow act = try act >>= \case + Left err -> return $ exceptionWgt err + Right res -> return res -- Button only needed in AVS TEST; further buttons see below data ButtonAvsTest = BtnCheckLicences -- | BtnSynchLicences @@ -152,169 +157,155 @@ postAdminAvsR = do $nothing AVS nicht konfiguriert! |] - mAvsQuery <- getsYesod $ view _appAvsQuery - case mAvsQuery of - Nothing -> siteLayoutMsg MsgMenuAvs [whamlet|Error: AVS interface configuration is incomplete.|] -- should never occur after initilisation - Just AvsQuery{..} -> do - ((presult, pwidget), penctype) <- runFormPost $ makeAvsPersonForm Nothing + + ((presult, pwidget), penctype) <- runFormPost $ makeAvsPersonForm Nothing - let procFormPerson fr = do - addMessage Info $ text2Html $ "Query: " <> tshow (toJSON fr) - res <- avsQueryPerson fr - case res of - Left err -> let msg = tshow err in return $ Just [whamlet|

Error:

#{msg}|] - Right (AvsResponsePerson pns) -> return $ Just [whamlet| -