From 30614511a5eae39c99f998e1b9c491a36f95abf3 Mon Sep 17 00:00:00 2001 From: SJost Date: Fri, 25 Jan 2019 10:40:18 +0100 Subject: [PATCH] Fixes #277 --- src/Foundation.hs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Foundation.hs b/src/Foundation.hs index f60ca5e3b..08aedb126 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -1326,15 +1326,18 @@ pageActions (CourseR tid ssh csh SheetListR) = ]) , menuItemModal = False , menuItemAccessCallback' = do - uid <- requireAuthId - [E.Value ok] <- runDB . E.select . return . E.exists . E.from $ \(course `E.InnerJoin` sheet `E.InnerJoin` submission) -> do - E.on $ submission E.^. SubmissionSheet E.==. sheet E.^. SheetId - E.on $ sheet E.^. SheetCourse E.==. course E.^. CourseId - E.where_ $ submission E.^. SubmissionRatingBy E.==. E.just (E.val uid) - E.&&. course E.^. CourseTerm E.==. E.val tid - E.&&. course E.^. CourseSchool E.==. E.val ssh - E.&&. course E.^. CourseShorthand E.==. E.val csh - return ok + muid <- maybeAuthId + case muid of + Nothing -> return False + (Just uid) -> do + [E.Value ok] <- runDB . E.select . return . E.exists . E.from $ \(course `E.InnerJoin` sheet `E.InnerJoin` submission) -> do + E.on $ submission E.^. SubmissionSheet E.==. sheet E.^. SheetId + E.on $ sheet E.^. SheetCourse E.==. course E.^. CourseId + E.where_ $ submission E.^. SubmissionRatingBy E.==. E.just (E.val uid) + E.&&. course E.^. CourseTerm E.==. E.val tid + E.&&. course E.^. CourseSchool E.==. E.val ssh + E.&&. course E.^. CourseShorthand E.==. E.val csh + return ok } , MenuItem { menuItemType = PageActionPrime @@ -1494,9 +1497,9 @@ pageActions (CorrectionsR) = , menuItemIcon = Nothing , menuItemRoute = SomeRoute CorrectionsCreateR , menuItemModal = False - , menuItemAccessCallback' = runDB $ do - uid <- liftHandlerT requireAuthId - [E.Value sheetCount] <- E.select . E.from $ \(course `E.InnerJoin` sheet) -> do + , menuItemAccessCallback' = runDB . maybeT (return False) $ do + uid <- MaybeT $ liftHandlerT maybeAuthId + [E.Value sheetCount] <- lift . E.select . E.from $ \(course `E.InnerJoin` sheet) -> do E.on $ course E.^. CourseId E.==. sheet E.^. SheetCourse let isCorrector' = E.exists . E.from $ \sheetCorrector -> E.where_ @@ -1534,9 +1537,9 @@ pageActions (CorrectionsGradeR) = , menuItemIcon = Nothing , menuItemRoute = SomeRoute CorrectionsCreateR , menuItemModal = False - , menuItemAccessCallback' = runDB $ do - uid <- liftHandlerT requireAuthId - [E.Value sheetCount] <- E.select . E.from $ \(course `E.InnerJoin` sheet) -> do + , menuItemAccessCallback' = runDB . maybeT (return False) $ do + uid <- MaybeT $ liftHandlerT maybeAuthId + [E.Value sheetCount] <- lift . E.select . E.from $ \(course `E.InnerJoin` sheet) -> do E.on $ course E.^. CourseId E.==. sheet E.^. SheetCourse let isCorrector' = E.exists . E.from $ \sheetCorrector -> E.where_