From e3566d98328c89bfb790b08329232aeed52d4d59 Mon Sep 17 00:00:00 2001 From: SJost Date: Mon, 28 May 2018 18:36:56 +0200 Subject: [PATCH] asidenav.hamlet restored to previous version, bug in Foundation fixed. --- src/Foundation.hs | 51 ++++++++++++++++--------------- templates/widgets/asidenav.hamlet | 16 +++++----- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/Foundation.hs b/src/Foundation.hs index 51aa79102..0d610b932 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -110,6 +110,28 @@ type MsgRenderer = MsgRendererS UniWorX -- see Utils pattern CSheetR tid csh shn ptn = CourseR tid csh (SheetR shn ptn) + +-- Menus and Favourites +data MenuItem = MenuItem + { menuItemLabel :: Text + , menuItemIcon :: Maybe Text + , menuItemRoute :: Route UniWorX + , menuItemAccessCallback' :: Handler Bool -- Check whether action is shown in ADDITION to authorization (which is always checked) + } + +menuItemAccessCallback :: MenuItem -> Handler Bool +menuItemAccessCallback MenuItem{..} = (&&) <$> ((==) Authorized <$> authCheck) <*> menuItemAccessCallback' + where + authCheck = handleAny (\_ -> return . Unauthorized $ error "authCheck caught exception") $ isAuthorized menuItemRoute False + +data MenuTypes -- Semantische Rolle: + = NavbarAside { menuItem :: MenuItem } -- TODO + | NavbarExtra { menuItem :: MenuItem } -- TODO + | NavbarRight { menuItem :: MenuItem } -- Generell, nahezu immer sichtbar + | NavbarSecondary { menuItem :: MenuItem } -- Generell, nahezu immer sichtbar + | PageActionPrime { menuItem :: MenuItem } -- Seitenspezifische Aktion, häufig + | PageActionSecondary { menuItem :: MenuItem } -- Seitenspezifische Aktion, selten + -- Messages mkMessage "UniWorX" "messages" "de" @@ -124,8 +146,8 @@ instance RenderMessage UniWorX TermIdentifier where Winter -> renderMessage' $ MsgWinterTerm year where renderMessage' = renderMessage foundation ls --- Access Control +-- Access Control data AccessPredicate = APPure (Route UniWorX -> Reader MsgRenderer AuthResult) | APHandler (Route UniWorX -> Handler AuthResult) @@ -224,8 +246,8 @@ knownTags = -- should not throw exceptions, i.e. no getBy404 or requireAuthId tag2ap :: Text -> AccessPredicate tag2ap t = case Map.lookup (CI.mk t) knownTags of - (Just ap) -> ap - Nothing -> APHandler $ \r -> do --TODO: can this be pure like falseAP? + (Just acp) -> acp + Nothing -> APHandler $ \_route -> do --TODO: can this be pure like falseAP? $logWarnS "AccessControl" ("route tag unknown for access control") unauthorizedI $ MsgUnauthorized @@ -247,30 +269,9 @@ evalAccess r = case route2ap r of (APHandler p) -> p r (APDB p) -> runDB $ p r - -- TODO: isAuthorized = evalAccess' --- Menus and Favourites -data MenuItem = MenuItem - { menuItemLabel :: Text - , menuItemIcon :: Maybe Text - , menuItemRoute :: Route UniWorX - , menuItemAccessCallback' :: Handler Bool -- Check whether action is shown in ADDITION to authorization (which is always checked) - } - -menuItemAccessCallback :: MenuItem -> Handler Bool -menuItemAccessCallback MenuItem{..} = (&&) <$> ((==) Authorized <$> authCheck) <*> menuItemAccessCallback' - where - authCheck = handleAny (\_ -> return . Unauthorized $ error "authCheck caught exception") $ isAuthorized menuItemRoute False - -data MenuTypes -- Semantische Rolle: - = NavbarAside { menuItem :: MenuItem } -- TODO - | NavbarExtra { menuItem :: MenuItem } -- TODO - | NavbarRight { menuItem :: MenuItem } -- Generell, nahezu immer sichtbar - | NavbarSecondary { menuItem :: MenuItem } -- Generell, nahezu immer sichtbar - | PageActionPrime { menuItem :: MenuItem } -- Seitenspezifische Aktion, häufig - | PageActionSecondary { menuItem :: MenuItem } -- Seitenspezifische Aktion, selten -- Please see the documentation for the Yesod typeclass. There are a number @@ -309,7 +310,7 @@ instance Yesod UniWorX where cid <- MaybeT . getKeyBy $ CourseTermShort tid csh user <- MaybeT $ get uid -- update Favourites - lift $ upsertBy + void . lift $ upsertBy (UniqueCourseFavourite uid cid) (CourseFavourite uid now cid) [CourseFavouriteTime =. now] diff --git a/templates/widgets/asidenav.hamlet b/templates/widgets/asidenav.hamlet index 1d8e82971..8126fd770 100644 --- a/templates/widgets/asidenav.hamlet +++ b/templates/widgets/asidenav.hamlet @@ -5,12 +5,12 @@ $newline never