convenience functions for authorisation
This commit is contained in:
parent
d881f18352
commit
023da918bb
@ -78,6 +78,8 @@ data UniWorX = UniWorX
|
|||||||
-- type Widget = WidgetT UniWorX IO ()
|
-- type Widget = WidgetT UniWorX IO ()
|
||||||
mkYesodData "UniWorX" $(parseRoutesFile "routes")
|
mkYesodData "UniWorX" $(parseRoutesFile "routes")
|
||||||
|
|
||||||
|
type DB a = YesodDB UniWorX a
|
||||||
|
|
||||||
data MenuItem = MenuItem
|
data MenuItem = MenuItem
|
||||||
{ menuItemLabel :: Text
|
{ menuItemLabel :: Text
|
||||||
, menuItemRoute :: Route UniWorX
|
, menuItemRoute :: Route UniWorX
|
||||||
@ -244,10 +246,28 @@ lecturerAccess school = do
|
|||||||
courseLecturerAccess :: CourseId -> YesodDB UniWorX AuthResult
|
courseLecturerAccess :: CourseId -> YesodDB UniWorX AuthResult
|
||||||
courseLecturerAccess courseId = do
|
courseLecturerAccess courseId = do
|
||||||
authId <- lift requireAuthId
|
authId <- lift requireAuthId
|
||||||
users <- map (lecturerUserId . entityVal ) <$> selectList [ LecturerCourseId ==. courseId ] []
|
lecturer <- getBy $ UniqueLecturer authId courseId
|
||||||
return $ case authId `elem` users of
|
return $ case lecturer of
|
||||||
True -> Authorized
|
(Just _) -> Authorized
|
||||||
False -> Unauthorized "No lecturer access for this course"
|
Nothing -> Unauthorized "Not a lecturer for this course"
|
||||||
|
|
||||||
|
courseCorrectorAccess :: CourseId -> YesodDB UniWorX AuthResult
|
||||||
|
courseCorrectorAccess courseId = do
|
||||||
|
authId <- lift requireAuthId
|
||||||
|
participation <- getBy $ UniqueCorrector authId courseId
|
||||||
|
return $ case participation of
|
||||||
|
(Just _) -> Authorized
|
||||||
|
Nothing -> Unauthorized "Not a corrector for this course"
|
||||||
|
|
||||||
|
courseParticipantAccess :: CourseId -> YesodDB UniWorX AuthResult
|
||||||
|
courseParticipantAccess courseId = do
|
||||||
|
authId <- lift requireAuthId
|
||||||
|
participation <- getBy $ UniqueCourseParticipant courseId authId
|
||||||
|
return $ case participation of
|
||||||
|
(Just _) -> Authorized
|
||||||
|
Nothing -> Unauthorized "Not a participant for this course"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
isAuthorizedDB' :: Route UniWorX -> Bool -> YesodDB UniWorX Bool
|
isAuthorizedDB' :: Route UniWorX -> Bool -> YesodDB UniWorX Bool
|
||||||
isAuthorizedDB' route isWrite = (== Authorized) <$> isAuthorizedDB route isWrite
|
isAuthorizedDB' route isWrite = (== Authorized) <$> isAuthorizedDB route isWrite
|
||||||
|
|||||||
@ -137,17 +137,25 @@ getSheetList courseEnt = do
|
|||||||
submissions <- count sheetsub
|
submissions <- count sheetsub
|
||||||
rated <- count $ (SubmissionRatingTime !=. Nothing):sheetsub
|
rated <- count $ (SubmissionRatingTime !=. Nothing):sheetsub
|
||||||
return (sid, sheet, (submissions, rated))
|
return (sid, sheet, (submissions, rated))
|
||||||
let colSheets = mconcat
|
let colBase = mconcat
|
||||||
[ headed "Blatt" $ \(sid,sheet,_) -> linkButton (toWgt $ sheetName sheet) BCLink $ SheetShowR tid csh (sheetName sheet)
|
[ headed "Blatt" $ \(sid,sheet,_) -> linkButton (toWgt $ sheetName sheet) BCLink $ SheetShowR tid csh (sheetName sheet)
|
||||||
, headed "Abgabe ab" $ toWgt . formatTimeGerWD . sheetActiveFrom . snd3
|
, headed "Abgabe ab" $ toWgt . formatTimeGerWD . sheetActiveFrom . snd3
|
||||||
, headed "Abgabe bis" $ toWgt . formatTimeGerWD . sheetActiveTo . snd3
|
, headed "Abgabe bis" $ toWgt . formatTimeGerWD . sheetActiveTo . snd3
|
||||||
, headed "Bewertung" $ toWgt . show . sheetType . snd3
|
, headed "Bewertung" $ toWgt . show . sheetType . snd3
|
||||||
, headed "Korrigiert" $ toWgt . snd . trd3
|
, headed "Korrigiert" $ toWgt . snd . trd3
|
||||||
, headed "Eingereicht" $ toWgt . fst . trd3
|
, headed "Eingereicht" $ toWgt . fst . trd3
|
||||||
-- TODO: only show edit button for allowed course assistants
|
]
|
||||||
, headed "" $ \s -> linkButton "Edit" BCLink $ SheetEditR tid csh $ sheetName $ snd3 s
|
let colAdmin = mconcat -- only show edit button for allowed course assistants
|
||||||
|
[ headed "" $ \s -> linkButton "Edit" BCLink $ SheetEditR tid csh $ sheetName $ snd3 s
|
||||||
, headed "" $ \s -> linkButton "Delete" BCLink $ SheetDelR tid csh $ sheetName $ snd3 s
|
, headed "" $ \s -> linkButton "Delete" BCLink $ SheetDelR tid csh $ sheetName $ snd3 s
|
||||||
]
|
]
|
||||||
|
showAdmin <- case sheets of
|
||||||
|
((_,firstSheet,_):_) ->
|
||||||
|
(Authorized ==) <$> isAuthorized (SheetEditR tid csh $ sheetName firstSheet) False
|
||||||
|
_otherwise -> return False
|
||||||
|
let colSheets = if showAdmin
|
||||||
|
then colBase `mappend` colAdmin
|
||||||
|
else colBase
|
||||||
let pageActions =
|
let pageActions =
|
||||||
[ NavbarLeft $ MenuItem
|
[ NavbarLeft $ MenuItem
|
||||||
{ menuItemLabel = "Neues Übungsblatt"
|
{ menuItemLabel = "Neues Übungsblatt"
|
||||||
|
|||||||
@ -202,42 +202,6 @@ buttonForm csrf = do
|
|||||||
accResult' (FormFailure errs) _ = FormFailure errs
|
accResult' (FormFailure errs) _ = FormFailure errs
|
||||||
|
|
||||||
|
|
||||||
---------------------------------------
|
|
||||||
-- Buttons (old version, deprecated) --
|
|
||||||
---------------------------------------
|
|
||||||
|
|
||||||
formBtnSave :: (Text,Text,Text)
|
|
||||||
formBtnSave = ("save" ,"Speichern" ,"btn-primary")
|
|
||||||
|
|
||||||
formBtnAbort :: (Text,Text,Text)
|
|
||||||
formBtnAbort = ("abort" ,"Abbrechen" ,"btn-default")
|
|
||||||
|
|
||||||
formBtnDelete ::(Text,Text,Text)
|
|
||||||
formBtnDelete = ("delete","Löschen" ,"btn-warning")
|
|
||||||
|
|
||||||
formActionSave :: Maybe Text
|
|
||||||
formActionSave = Just $ fst3 formBtnSave
|
|
||||||
|
|
||||||
formActionAbort :: Maybe Text
|
|
||||||
formActionAbort = Just $ fst3 formBtnAbort
|
|
||||||
|
|
||||||
formActionDelete :: Maybe Text
|
|
||||||
formActionDelete = Just $ fst3 formBtnDelete
|
|
||||||
|
|
||||||
defaultFormActions :: [(Text,Text,Text)]
|
|
||||||
defaultFormActions = [ formBtnDelete
|
|
||||||
, formBtnAbort
|
|
||||||
, formBtnSave
|
|
||||||
]
|
|
||||||
|
|
||||||
-- Post-Buttons
|
|
||||||
postButtonForm :: Text -> Form ()
|
|
||||||
postButtonForm lblId = identifyForm lblId buttonF
|
|
||||||
where
|
|
||||||
buttonF = renderAForm FormStandard $ pure () <* bootstrapSubmit bProps
|
|
||||||
bProps :: BootstrapSubmit Text
|
|
||||||
bProps = fromString $ unpack lblId
|
|
||||||
|
|
||||||
|
|
||||||
------------
|
------------
|
||||||
-- Fields --
|
-- Fields --
|
||||||
|
|||||||
Reference in New Issue
Block a user