Refactored Access check to CRegisterR without NTop for clarity
This commit is contained in:
parent
0bde8d5888
commit
36813d3717
@ -464,20 +464,21 @@ tagAccessPredicate AuthTime = APDB $ \route _ -> case route of
|
|||||||
return Authorized
|
return Authorized
|
||||||
|
|
||||||
CourseR tid ssh csh CRegisterR -> do
|
CourseR tid ssh csh CRegisterR -> do
|
||||||
|
now <- liftIO getCurrentTime
|
||||||
mbc <- getBy $ TermSchoolCourseShort tid ssh csh
|
mbc <- getBy $ TermSchoolCourseShort tid ssh csh
|
||||||
mAid <- lift maybeAuthId
|
mAid <- lift maybeAuthId
|
||||||
registered <- case (mbc,mAid) of
|
registered <- case (mbc,mAid) of
|
||||||
(Just (Entity cid _), Just uid) -> isJust <$> (getBy $ UniqueParticipant uid cid)
|
(Just (Entity cid _), Just uid) -> isJust <$> (getBy $ UniqueParticipant uid cid)
|
||||||
_ -> return False
|
_ -> return False
|
||||||
cTime <- (NTop . Just) <$> liftIO getCurrentTime
|
|
||||||
case mbc of
|
case mbc of
|
||||||
(Just (Entity _ Course{courseRegisterFrom, courseRegisterTo}))
|
(Just (Entity _ Course{courseRegisterFrom, courseRegisterTo}))
|
||||||
| not registered
|
| not registered
|
||||||
, NTop courseRegisterFrom <= cTime -- Nothing => always False!
|
, Just regFrom <- courseRegisterFrom -- Nothing = no registration
|
||||||
, NTop courseRegisterTo >= cTime -> return Authorized
|
, regFrom <= now
|
||||||
|
, maybe True (now <=) courseRegisterTo -> return Authorized
|
||||||
(Just (Entity _ Course{courseDeregisterUntil}))
|
(Just (Entity _ Course{courseDeregisterUntil}))
|
||||||
| registered
|
| registered
|
||||||
, NTop courseDeregisterUntil >= cTime -> return Authorized
|
, maybe True (now <=) courseDeregisterUntil -> return Authorized
|
||||||
_other -> unauthorizedI MsgUnauthorizedCourseTime
|
_other -> unauthorizedI MsgUnauthorizedCourseTime
|
||||||
|
|
||||||
MessageR cID -> maybeT (unauthorizedI MsgUnauthorizedSystemMessageTime) $ do
|
MessageR cID -> maybeT (unauthorizedI MsgUnauthorizedSystemMessageTime) $ do
|
||||||
|
|||||||
Reference in New Issue
Block a user