BUGFIX, Attempt 2: Authorization for Admins without schools fixed.

This commit is contained in:
SJost 2017-11-27 16:54:12 +01:00
parent 5886b99bfc
commit 4686c63fd9
2 changed files with 10 additions and 10 deletions

View File

@ -204,21 +204,21 @@ submissionAccess cID = do
adminAccess :: Maybe (Maybe SchoolId) -- ^ If @Just@, matched exactly against 'userAdminSchool' adminAccess :: Maybe (Maybe SchoolId) -- ^ If @Just@, matched exactly against 'userAdminSchool'
-> YesodDB UniWorX AuthResult -> YesodDB UniWorX AuthResult
adminAccess school = do adminAccess school = do
authId <- lift requireAuthId authId <- lift requireAuthId
schools <- map (userAdminSchool . entityVal) <$> selectList [UserAdminUser ==. authId] [] rights <- selectList [UserAdminUser ==. authId, UserAdminSchool <-. catMaybes [school,Just Nothing]] []
return $ case maybe (null schools) (`elem` schools) school of return $ if (not $ null rights)
True -> Authorized then Authorized
False -> Unauthorized "No admin access" else Unauthorized "No admin access"
lecturerAccess :: Maybe SchoolId lecturerAccess :: Maybe SchoolId
-> YesodDB UniWorX AuthResult -> YesodDB UniWorX AuthResult
lecturerAccess school = do lecturerAccess school = do
authId <- lift requireAuthId authId <- lift requireAuthId
schools <- map (userLecturerSchool . entityVal) <$> selectList [UserLecturerUser ==. authId] [] rights <- selectList ((UserLecturerUser ==. authId) : maybe [] (\s -> [UserLecturerSchool ==. s]) school) []
return $ case maybe (null schools) (`elem` schools) school of return $ if (not $ null rights)
True -> Authorized then Authorized
False -> Unauthorized "No lecturer access" else Unauthorized "No lecturer access"
courseLecturerAccess :: CourseId -> YesodDB UniWorX AuthResult courseLecturerAccess :: CourseId -> YesodDB UniWorX AuthResult
courseLecturerAccess courseId = do courseLecturerAccess courseId = do

View File

@ -73,7 +73,7 @@ getCourseListTermR tidini = do
defaultLinkLayout pageLinks $ do defaultLinkLayout pageLinks $ do
-- defaultLayout $ do -- defaultLayout $ do
setTitle "Semesterkurse" setTitle "Semesterkurse"
-- linkButton "Neuen Kurs anlegen" BCPrimary CourseEditR linkButton "Neuen Kurs anlegen" BCPrimary CourseEditR
encodeHeadedWidgetTable tableDefault colonnadeTerms courses -- (map entityVal courses) encodeHeadedWidgetTable tableDefault colonnadeTerms courses -- (map entityVal courses)
getCourseShowR :: TermIdentifier -> Text -> Handler Html getCourseShowR :: TermIdentifier -> Text -> Handler Html