Automatically check isAuthorized for MenuItems
This commit is contained in:
parent
8c427c9e83
commit
c78184a946
@ -96,9 +96,14 @@ data MenuItem = MenuItem
|
|||||||
{ menuItemLabel :: Text
|
{ menuItemLabel :: Text
|
||||||
, menuItemIcon :: Maybe Text
|
, menuItemIcon :: Maybe Text
|
||||||
, menuItemRoute :: Route UniWorX
|
, menuItemRoute :: Route UniWorX
|
||||||
, menuItemAccessCallback :: Handler Bool
|
, menuItemAccessCallback' :: Handler Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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:
|
data MenuTypes -- Semantische Rolle:
|
||||||
= NavbarAside { menuItem :: MenuItem } -- TODO
|
= NavbarAside { menuItem :: MenuItem } -- TODO
|
||||||
| NavbarExtra { menuItem :: MenuItem } -- TODO
|
| NavbarExtra { menuItem :: MenuItem } -- TODO
|
||||||
@ -355,49 +360,49 @@ defaultLinks = -- Define the menu items of the header.
|
|||||||
{ menuItemLabel = "Home"
|
{ menuItemLabel = "Home"
|
||||||
, menuItemIcon = Just "home"
|
, menuItemIcon = Just "home"
|
||||||
, menuItemRoute = HomeR
|
, menuItemRoute = HomeR
|
||||||
, menuItemAccessCallback = return True
|
, menuItemAccessCallback' = return True
|
||||||
}
|
}
|
||||||
, NavbarRight $ MenuItem
|
, NavbarRight $ MenuItem
|
||||||
{ menuItemLabel = "Profile"
|
{ menuItemLabel = "Profile"
|
||||||
, menuItemIcon = Just "profile"
|
, menuItemIcon = Just "profile"
|
||||||
, menuItemRoute = ProfileR
|
, menuItemRoute = ProfileR
|
||||||
, menuItemAccessCallback = isJust <$> maybeAuthPair
|
, menuItemAccessCallback' = isJust <$> maybeAuthPair
|
||||||
}
|
}
|
||||||
, NavbarSecondary $ MenuItem
|
, NavbarSecondary $ MenuItem
|
||||||
{ menuItemLabel = "Login"
|
{ menuItemLabel = "Login"
|
||||||
, menuItemIcon = Just "login"
|
, menuItemIcon = Just "login"
|
||||||
, menuItemRoute = AuthR LoginR
|
, menuItemRoute = AuthR LoginR
|
||||||
, menuItemAccessCallback = isNothing <$> maybeAuthPair
|
, menuItemAccessCallback' = isNothing <$> maybeAuthPair
|
||||||
}
|
}
|
||||||
, NavbarSecondary $ MenuItem
|
, NavbarSecondary $ MenuItem
|
||||||
{ menuItemLabel = "Logout"
|
{ menuItemLabel = "Logout"
|
||||||
, menuItemIcon = Just "logout"
|
, menuItemIcon = Just "logout"
|
||||||
, menuItemRoute = AuthR LogoutR
|
, menuItemRoute = AuthR LogoutR
|
||||||
, menuItemAccessCallback = isJust <$> maybeAuthPair
|
, menuItemAccessCallback' = isJust <$> maybeAuthPair
|
||||||
}
|
}
|
||||||
, NavbarAside $ MenuItem
|
, NavbarAside $ MenuItem
|
||||||
{ menuItemLabel = "Aktuelle Veranstaltungen"
|
{ menuItemLabel = "Aktuelle Veranstaltungen"
|
||||||
, menuItemIcon = Just "book"
|
, menuItemIcon = Just "book"
|
||||||
, menuItemRoute = CourseListR -- should be CourseListActiveR or similar in the future
|
, menuItemRoute = CourseListR -- should be CourseListActiveR or similar in the future
|
||||||
, menuItemAccessCallback = return True
|
, menuItemAccessCallback' = return True
|
||||||
}
|
}
|
||||||
, NavbarAside $ MenuItem
|
, NavbarAside $ MenuItem
|
||||||
{ menuItemLabel = "Alte Veranstaltungen"
|
{ menuItemLabel = "Alte Veranstaltungen"
|
||||||
, menuItemIcon = Just "book"
|
, menuItemIcon = Just "book"
|
||||||
, menuItemRoute = CourseListR -- should be CourseListInactiveR or similar in the future
|
, menuItemRoute = CourseListR -- should be CourseListInactiveR or similar in the future
|
||||||
, menuItemAccessCallback = return True
|
, menuItemAccessCallback' = return True
|
||||||
}
|
}
|
||||||
, NavbarAside $ MenuItem
|
, NavbarAside $ MenuItem
|
||||||
{ menuItemLabel = "Veranstaltungen"
|
{ menuItemLabel = "Veranstaltungen"
|
||||||
, menuItemIcon = Just "book"
|
, menuItemIcon = Just "book"
|
||||||
, menuItemRoute = CourseListR
|
, menuItemRoute = CourseListR
|
||||||
, menuItemAccessCallback = return True
|
, menuItemAccessCallback' = return True
|
||||||
}
|
}
|
||||||
, NavbarAside $ MenuItem
|
, NavbarAside $ MenuItem
|
||||||
{ menuItemLabel = "Benutzer"
|
{ menuItemLabel = "Benutzer"
|
||||||
, menuItemIcon = Just "user"
|
, menuItemIcon = Just "user"
|
||||||
, menuItemRoute = UsersR
|
, menuItemRoute = UsersR
|
||||||
, menuItemAccessCallback = return True -- Creates a LOOP: (Authorized ==) <$> isAuthorized UsersR False
|
, menuItemAccessCallback' = return True -- Creates a LOOP: (Authorized ==) <$> isAuthorized UsersR False
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@ -68,7 +68,7 @@ getCourseListTermR tidini = do
|
|||||||
{ menuItemLabel = "Neuer Kurs"
|
{ menuItemLabel = "Neuer Kurs"
|
||||||
, menuItemIcon = Just "book"
|
, menuItemIcon = Just "book"
|
||||||
, menuItemRoute = CourseNewR
|
, menuItemRoute = CourseNewR
|
||||||
, menuItemAccessCallback = (== Authorized) <$> isAuthorized CourseNewR False
|
, menuItemAccessCallback' = return True
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
let coursesTable = encodeWidgetTable tableSortable colonnadeTerms courses
|
let coursesTable = encodeWidgetTable tableSortable colonnadeTerms courses
|
||||||
@ -97,7 +97,7 @@ getCourseShowR tid csh = do
|
|||||||
{ menuItemLabel = "Übungsblätter"
|
{ menuItemLabel = "Übungsblätter"
|
||||||
, menuItemIcon = Nothing
|
, menuItemIcon = Nothing
|
||||||
, menuItemRoute = CSheetR tid csh SheetListR
|
, menuItemRoute = CSheetR tid csh SheetListR
|
||||||
, menuItemAccessCallback = (== Authorized) <$> isAuthorized (CSheetR tid csh SheetListR) False
|
, menuItemAccessCallback' = return True
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
defaultLinkLayout pageActions $ do
|
defaultLinkLayout pageActions $ do
|
||||||
|
|||||||
@ -196,7 +196,7 @@ getSheetList courseEnt = do
|
|||||||
{ menuItemLabel = "Neues Übungsblatt"
|
{ menuItemLabel = "Neues Übungsblatt"
|
||||||
, menuItemIcon = Nothing
|
, menuItemIcon = Nothing
|
||||||
, menuItemRoute = CSheetR tid csh SheetNewR
|
, menuItemRoute = CSheetR tid csh SheetNewR
|
||||||
, menuItemAccessCallback = (== Authorized) <$> isAuthorized CourseNewR False
|
, menuItemAccessCallback' = return True
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
defaultLinkLayout pageActions $ do
|
defaultLinkLayout pageActions $ do
|
||||||
|
|||||||
@ -80,7 +80,7 @@ getTermShowR = do
|
|||||||
{ menuItemLabel = "Neues Semester"
|
{ menuItemLabel = "Neues Semester"
|
||||||
, menuItemIcon = Nothing
|
, menuItemIcon = Nothing
|
||||||
, menuItemRoute = TermEditR
|
, menuItemRoute = TermEditR
|
||||||
, menuItemAccessCallback = (== Authorized) <$> isAuthorized TermEditR True
|
, menuItemAccessCallback' = return True
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
defaultLinkLayout pageActions $ do
|
defaultLinkLayout pageActions $ do
|
||||||
|
|||||||
Reference in New Issue
Block a user