From 4686c63fd9875be1013b997034aabba1fbe08a53 Mon Sep 17 00:00:00 2001 From: SJost Date: Mon, 27 Nov 2017 16:54:12 +0100 Subject: [PATCH] BUGFIX, Attempt 2: Authorization for Admins without schools fixed. --- src/Foundation.hs | 18 +++++++++--------- src/Handler/Course.hs | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Foundation.hs b/src/Foundation.hs index 6d422c7e8..d6cf6ef55 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -204,21 +204,21 @@ submissionAccess cID = do adminAccess :: Maybe (Maybe SchoolId) -- ^ If @Just@, matched exactly against 'userAdminSchool' -> YesodDB UniWorX AuthResult -adminAccess school = do +adminAccess school = do authId <- lift requireAuthId - schools <- map (userAdminSchool . entityVal) <$> selectList [UserAdminUser ==. authId] [] - return $ case maybe (null schools) (`elem` schools) school of - True -> Authorized - False -> Unauthorized "No admin access" + rights <- selectList [UserAdminUser ==. authId, UserAdminSchool <-. catMaybes [school,Just Nothing]] [] + return $ if (not $ null rights) + then Authorized + else Unauthorized "No admin access" lecturerAccess :: Maybe SchoolId -> YesodDB UniWorX AuthResult lecturerAccess school = do authId <- lift requireAuthId - schools <- map (userLecturerSchool . entityVal) <$> selectList [UserLecturerUser ==. authId] [] - return $ case maybe (null schools) (`elem` schools) school of - True -> Authorized - False -> Unauthorized "No lecturer access" + rights <- selectList ((UserLecturerUser ==. authId) : maybe [] (\s -> [UserLecturerSchool ==. s]) school) [] + return $ if (not $ null rights) + then Authorized + else Unauthorized "No lecturer access" courseLecturerAccess :: CourseId -> YesodDB UniWorX AuthResult courseLecturerAccess courseId = do diff --git a/src/Handler/Course.hs b/src/Handler/Course.hs index 727ad0ef4..57e740a7f 100644 --- a/src/Handler/Course.hs +++ b/src/Handler/Course.hs @@ -73,7 +73,7 @@ getCourseListTermR tidini = do defaultLinkLayout pageLinks $ do -- defaultLayout $ do setTitle "Semesterkurse" - -- linkButton "Neuen Kurs anlegen" BCPrimary CourseEditR + linkButton "Neuen Kurs anlegen" BCPrimary CourseEditR encodeHeadedWidgetTable tableDefault colonnadeTerms courses -- (map entityVal courses) getCourseShowR :: TermIdentifier -> Text -> Handler Html