From 36813d3717af47db383962def80dc3a77a381856 Mon Sep 17 00:00:00 2001 From: SJost Date: Thu, 31 Jan 2019 18:25:41 +0100 Subject: [PATCH] Refactored Access check to CRegisterR without NTop for clarity --- src/Foundation.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Foundation.hs b/src/Foundation.hs index c77329d52..8d338c7f0 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -464,20 +464,21 @@ tagAccessPredicate AuthTime = APDB $ \route _ -> case route of return Authorized CourseR tid ssh csh CRegisterR -> do + now <- liftIO getCurrentTime mbc <- getBy $ TermSchoolCourseShort tid ssh csh mAid <- lift maybeAuthId registered <- case (mbc,mAid) of (Just (Entity cid _), Just uid) -> isJust <$> (getBy $ UniqueParticipant uid cid) _ -> return False - cTime <- (NTop . Just) <$> liftIO getCurrentTime case mbc of (Just (Entity _ Course{courseRegisterFrom, courseRegisterTo})) | not registered - , NTop courseRegisterFrom <= cTime -- Nothing => always False! - , NTop courseRegisterTo >= cTime -> return Authorized + , Just regFrom <- courseRegisterFrom -- Nothing = no registration + , regFrom <= now + , maybe True (now <=) courseRegisterTo -> return Authorized (Just (Entity _ Course{courseDeregisterUntil})) | registered - , NTop courseDeregisterUntil >= cTime -> return Authorized + , maybe True (now <=) courseDeregisterUntil -> return Authorized _other -> unauthorizedI MsgUnauthorizedCourseTime MessageR cID -> maybeT (unauthorizedI MsgUnauthorizedSystemMessageTime) $ do