diff --git a/src/Utils/Schedule.hs b/src/Utils/Schedule.hs index 750eb53d5..5c5ed4896 100644 --- a/src/Utils/Schedule.hs +++ b/src/Utils/Schedule.hs @@ -31,9 +31,10 @@ fetchCourseEvents muid ata now = E.select $ E.from $ \(course `E.InnerJoin` cour fetchTutorials :: MonadHandler m => Maybe UserId -> AuthTagActive -> UTCTime -> ReaderT SqlBackend m [ScheduleTutorialInfo] fetchTutorials muid ata now = E.select $ E.from $ \(course `E.InnerJoin` tutorial) -> do E.on $ course E.^. CourseId E.==. tutorial E.^. TutorialCourse - E.where_ $ mayViewCourse muid ata now course Nothing -- should not be necessary, but let's be on the safe side - E.&&. ( isTutorialTutor muid ata (tutorial E.^. TutorialId) - E.||. isTutorialParticipant muid ata (tutorial E.^. TutorialId) + E.where_ $ tutorialShouldBeDisplayed muid course tutorial + E.&&. mayViewCourse muid ata now course Nothing -- should not be necessary, but let's be on the safe side + E.&&. ( isTutorialTutor muid ata (tutorial E.^. TutorialId) + E.||. isTutorialParticipant muid ata (tutorial E.^. TutorialId) ) return (course, tutorial) @@ -62,6 +63,14 @@ courseEventShouldBeDisplayed :: Maybe UserId -> E.SqlExpr (Entity Course) -> E.S courseEventShouldBeDisplayed (Just uid) _course _courseEvent = E.exists . E.from $ \user -> E.where_ $ user E.^. UserId E.==. E.val uid E.&&. ( -- TODO: also check whether there is a display opt-in/out for this course or course event - user E.^. UserScheduleNewCoursesDisplayDefault + user E.^. UserScheduleOccurrenceDisplayDefault ) courseEventShouldBeDisplayed _ _ _ = E.false + +tutorialShouldBeDisplayed :: Maybe UserId -> E.SqlExpr (Entity Course) -> E.SqlExpr (Entity Tutorial) -> E.SqlExpr (E.Value Bool) +tutorialShouldBeDisplayed (Just uid) _course _tutorial = E.exists . E.from $ \user -> + E.where_ $ user E.^. UserId E.==. E.val uid + E.&&. ( -- TODO: also check whether there is a display opt-in/out for this course or tutorial + user E.^. UserScheduleOccurrenceDisplayDefault + ) +tutorialShouldBeDisplayed _ _ _ = E.false