From b558d8d314636873f3b3d873f2197423c5a4ef19 Mon Sep 17 00:00:00 2001 From: SJost Date: Thu, 7 Jun 2018 17:04:17 +0200 Subject: [PATCH] Access tags isWrite isRead added --- messages/de.msg | 1 + routes | 2 ++ src/Foundation.hs | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/messages/de.msg b/messages/de.msg index 5332201d5..6537db277 100644 --- a/messages/de.msg +++ b/messages/de.msg @@ -37,6 +37,7 @@ UnauthorizedSubmissionCorrector: Sie sind nicht der Korrektor für diese Abgabe. OnlyUploadOneFile: Bitte nur eine Datei hochladen. DeprecatedRoute: Diese Ansicht ist obsolet und könnte in Zukunft entfallen. UnfreeMaterials: Die Materialien für diese Veranstaltung sind nicht allgemein freigegeben. +UnauthorizedWrite: Sie haben hierfür keine Schreibberechtigung SubmissionWrongSheet: Abgabenummer gehört nicht zum angegebenen Übungsblatt. SubmissionAlreadyExists: Sie haben bereits eine Abgabe zu diesem Übungsblatt. diff --git a/routes b/routes index 2b5511668..37e2ebecb 100644 --- a/routes +++ b/routes @@ -18,6 +18,8 @@ -- -- !materials -- only if course allows all materials to be free (no meaning outside of courses) -- !time -- access depends on time somehow +-- !isRead -- only if it is read-only access (i.e. GET but not POST) +-- !isWrite -- only if it is write access (i.e. POST only) why needed??? -- -- !deprecated -- like free, but logs and gives a warning -- diff --git a/src/Foundation.hs b/src/Foundation.hs index ed93e5a90..7990cbf5a 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -269,9 +269,9 @@ knownTags = -- should not throw exceptions, i.e. no getBy404 or requireAuthId cTime <- liftIO getCurrentTime case subRoute of SFileR SheetExercise _ -> guard $ maybe False (<= cTime) sheetVisibleFrom - SFileR SheetHint _ -> guard $ maybe False (<= cTime) sheetHintFrom + SFileR SheetHint _ -> guard $ maybe False (<= cTime) sheetHintFrom SFileR SheetSolution _ -> guard $ maybe False (<= cTime) sheetSolutionFrom - SFileR SheetMarking _ -> mzero -- only for correctors and lecturers + SFileR SheetMarking _ -> mzero -- only for correctors and lecturers SubmissionNewR -> guard $ sheetActiveFrom <= cTime && cTime <= sheetActiveTo _ -> guard $ maybe False (<= cTime) sheetVisibleFrom return Authorized @@ -314,6 +314,17 @@ knownTags = -- should not throw exceptions, i.e. no getBy404 or requireAuthId $logErrorS "AccessControl" $ "'!owner' used on route that doesn't support it: " <> tshow r unauthorizedI MsgUnauthorized ) + ,("isRead", APHandler $ \route -> + bool <$> return Authorized + <*> unauthorizedI MsgUnauthorizedWrite + <*> isWriteRequest route + ) + ,("isWrite", APHandler $ \route -> do + write <- isWriteRequest route + if write + then return Authorized + else unauthorizedI MsgUnauthorized + ) ]