diff --git a/src/Handler/Course/Show.hs b/src/Handler/Course/Show.hs index 3165bf4b0..57c7e3b80 100644 --- a/src/Handler/Course/Show.hs +++ b/src/Handler/Course/Show.hs @@ -5,6 +5,7 @@ module Handler.Course.Show import Import +import Utils.Course import Utils.Form import Handler.Utils import qualified Database.Esqueleto.Utils as E @@ -86,9 +87,9 @@ getCShowR tid ssh csh = do & over (mapped . _1) E.unValue & over (mapped . _2) E.unValue lastEditText <- formatTime SelFormatDateTime $ maybe id max (guardOn visible =<< courseNewsVisibleFrom) courseNewsLastEdit - mayEdit <- hasWriteAccessTo $ CNewsR tid ssh csh cID CNEditR + mayEditNews <- hasWriteAccessTo $ CNewsR tid ssh csh cID CNEditR mayDelete <- hasWriteAccessTo $ CNewsR tid ssh csh cID CNDeleteR - return (cID, n, visible, files, lastEditText, mayEdit, mayDelete) + return (cID, n, visible, files, lastEditText, mayEditNews, mayDelete) events' <- fmap (sortOn $ courseEventTime . entityVal) . lift $ selectList [ CourseEventCourse ==. cid ] [] events <- mapM (\(Entity evId ev) -> (, ev) <$> encrypt evId) events' @@ -221,18 +222,15 @@ getCShowR tid ssh csh = do hiddenEventNotes = all (\(_,CourseEvent{..}) -> is _Nothing courseEventNote) events courseVisFrom = courseVisibleFrom course courseVisTo = courseVisibleTo course - courseIsVisible - | Just visFrom <- courseVisFrom, Just visTo <- courseVisTo = visFrom <= now && now <= visTo - | Just visFrom <- courseVisFrom = visFrom <= now - | otherwise = False + courseVisible = courseIsVisible' now course mayCreateNews <- hasWriteAccessTo $ CourseR tid ssh csh CNewsNewR mayCreateEvents <- hasWriteAccessTo $ CourseR tid ssh csh CEventsNewR - mayEditCourse <- hasWriteAccessTo $ CourseR tid ssh csh CEditR + mayEdit <- hasWriteAccessTo $ CourseR tid ssh csh CEditR let heading = [whamlet| $newline never ^{courseName course} - $if not courseIsVisible && mayEditCourse + $if not courseVisible && mayEdit \ #{iconInvisible} |] diff --git a/src/Utils/Course.hs b/src/Utils/Course.hs index 950fa0d79..c85e5f83d 100644 --- a/src/Utils/Course.hs +++ b/src/Utils/Course.hs @@ -4,6 +4,7 @@ module Utils.Course , isCourseLecturer, isCourseTutor, isCourseCorrector, isCourseParticipant, isCourseAssociated , isCourseLecturer' , courseIsVisible + , courseIsVisible' , numCourseParticipants ) where @@ -84,6 +85,10 @@ courseIsVisible now course = E.||. E.val (Just now) E.<=. course E.^. CourseVisibleTo ) +courseIsVisible' :: UTCTime -> Course -> Bool +courseIsVisible' now Course{..} = NTop courseVisibleFrom <= now' && now' <= NTop courseVisibleTo + where now' = NTop $ Just now + numCourseParticipants :: E.SqlExpr (Entity Course) -> E.SqlExpr (E.Value Int) numCourseParticipants course = E.subSelectCount . E.from $ \courseParticipant -> E.where_ $ courseParticipant E.^. CourseParticipantCourse E.==. course E.^. CourseId diff --git a/templates/course.hamlet b/templates/course.hamlet index e0f8e3269..f4341faa3 100644 --- a/templates/course.hamlet +++ b/templates/course.hamlet @@ -8,7 +8,7 @@ $newline never
_{MsgCourseNewsLastEdited lastEditText} - $if mayEdit || mayDelete + $if mayEditNews || mayDelete