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
|
||||
|
||||
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user