diff --git a/messages/uniworx/de-de-formal.msg b/messages/uniworx/de-de-formal.msg index d9966c1a9..dc77097ae 100644 --- a/messages/uniworx/de-de-formal.msg +++ b/messages/uniworx/de-de-formal.msg @@ -137,10 +137,12 @@ ScheduleOffsetWeekForwardDay: 1 Tag vorwärts ScheduleOffsetWeekForwardWeek: 1 Woche vorwärts ScheduleOptActions: Terminübersicht -ScheduleOptOut: Opt-Out -ScheduleOptIn: Opt-In +ScheduleOptOut: Deabonnieren +ScheduleOptIn: Abonnieren -ScheduleOptSuccess: Terminübersichts-Ausnahme gespeichert +ScheduleOptOutSuccess: Termin erfolgreich deabonniert +ScheduleOptInSuccess: Termin erfolgreich abonniert +ScheduleOptDeleteSuccess: Terminabonnement erfolgreich auf Standard zurückgesetzt ScheduleReset: Standard diff --git a/messages/uniworx/en-eu.msg b/messages/uniworx/en-eu.msg index 37dfac88d..64ac06b63 100644 --- a/messages/uniworx/en-eu.msg +++ b/messages/uniworx/en-eu.msg @@ -138,10 +138,12 @@ ScheduleOffsetWeekForwardDay: 1 day forward ScheduleOffsetWeekForwardWeek: 1 week forward ScheduleOptActions: Schedule -ScheduleOptOut: Opt out -ScheduleOptIn: Opt in +ScheduleOptOut: Unsubscribe +ScheduleOptIn: Subscribe -ScheduleOptSuccess: Schedule exception successfully saved +ScheduleOptOutSuccess: Successfully unsubscribed from occurrence +ScheduleOptInSuccess: Successfully subscribed to occurrence +ScheduleOptDeleteSuccess: Successfully reset occurrence subscription to default ScheduleReset: Default diff --git a/src/Handler/Course/Events/Schedule.hs b/src/Handler/Course/Events/Schedule.hs index 98f5ec865..42822b24a 100644 --- a/src/Handler/Course/Events/Schedule.hs +++ b/src/Handler/Course/Events/Schedule.hs @@ -19,5 +19,5 @@ postCEvScheduleOptR tid ssh csh ceId opt = do [ CourseEventScheduleOptOpt =. opt ] - addMessageI Success MsgScheduleOptSuccess + addMessageI Success $ bool MsgScheduleOptOutSuccess MsgScheduleOptInSuccess opt redirect $ CourseR tid ssh csh CShowR diff --git a/src/Handler/Course/Show.hs b/src/Handler/Course/Show.hs index f34d5048f..ef0ab40ca 100644 --- a/src/Handler/Course/Show.hs +++ b/src/Handler/Course/Show.hs @@ -26,14 +26,14 @@ import Handler.Exam.List (mkExamTable) getCShowR :: TermId -> SchoolId -> CourseShorthand -> Handler Html getCShowR tid ssh csh = do - mbAid <- maybeAuthId + mbAuth <- maybeAuthPair now <- liftIO getCurrentTime (cid,course,courseVisible,schoolName,participants,registration,lecturers,assistants,correctors,tutors,mAllocation,hasApplicationTemplate,mApplication,news,events,submissionGroup,hasAllocationRegistrationOpen,mayReRegister) <- runDB . maybeT notFound $ do [(E.Entity cid course, E.Value courseVisible, E.Value schoolName, E.Value participants, fmap entityVal -> registration, E.Value hasAllocationRegistrationOpen)] <- lift . E.select . E.from $ \((school `E.InnerJoin` course) `E.LeftOuterJoin` participant) -> do E.on $ E.just (course E.^. CourseId) E.==. participant E.?. CourseParticipantCourse - E.&&. E.val mbAid E.==. participant E.?. CourseParticipantUser + E.&&. E.val (fst <$> mbAuth) E.==. participant E.?. CourseParticipantUser E.&&. participant E.?. CourseParticipantState E.==. E.just (E.val CourseParticipantActive) E.on $ course E.^. CourseSchool E.==. school E.^. SchoolId E.where_ $ course E.^. CourseTerm E.==. E.val tid @@ -74,7 +74,7 @@ getCShowR tid ssh csh = do return allocation hasApplicationTemplate <- lift . E.selectExists . E.from $ \courseAppInstructionFile -> E.where_ $ courseAppInstructionFile E.^. CourseAppInstructionFileCourse E.==. E.val cid - mApplication <- lift . fmap (listToMaybe =<<) . for mbAid $ \uid -> selectList [CourseApplicationCourse ==. cid, CourseApplicationUser ==. uid, CourseApplicationAllocation ==. Nothing] [] + mApplication <- lift . fmap (listToMaybe =<<) . for mbAuth $ \(uid,_) -> selectList [CourseApplicationCourse ==. cid, CourseApplicationUser ==. uid, CourseApplicationAllocation ==. Nothing] [] news' <- lift $ selectList [ CourseNewsCourse ==. cid ] [ Desc CourseNewsVisibleFrom, Desc CourseNewsTitle, Desc CourseNewsSummary, Desc CourseNewsContent ] cTime <- NTop . Just <$> liftIO getCurrentTime news <- forMaybeM news' $ \(Entity nId n@CourseNews{..}) -> do @@ -93,12 +93,17 @@ getCShowR tid ssh csh = do 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' + events <- forM events' $ \(Entity evId ev) -> do + evId' <- encrypt evId + mScheduleOpt <- case mbAuth of + Just (aid,_) -> lift $ getBy $ UniqueCourseEventScheduleOpt evId aid + Nothing -> return Nothing + return (evId', ev, entityVal <$> mScheduleOpt) hasSubmissionGroups <- lift . E.selectExists . E.from $ \(submissionGroupUser `E.InnerJoin` submissionGroup) -> do E.on $ submissionGroupUser E.^. SubmissionGroupUserSubmissionGroup E.==. submissionGroup E.^. SubmissionGroupId E.where_ $ submissionGroup E.^. SubmissionGroupCourse E.==. E.val cid - submissionGroup' <- lift . for mbAid $ \uid -> + submissionGroup' <- lift . for mbAuth $ \(uid,_) -> fmap (listToMaybe . fmap E.unValue) . E.select . E.from $ \(submissionGroupUser `E.InnerJoin` submissionGroup) -> do E.on $ submissionGroupUser E.^. SubmissionGroupUserSubmissionGroup E.==. submissionGroup E.^. SubmissionGroupId E.where_ $ submissionGroup E.^. SubmissionGroupCourse E.==. E.val cid @@ -117,7 +122,7 @@ getCShowR tid ssh csh = do mAllocation' <- for mAllocation $ \alloc@Allocation{..} -> (alloc, ) <$> toTextUrl (AllocationR allocationTerm allocationSchool allocationShorthand AShowR :#: cID) regForm <- if - | is _Just mbAid -> do + | is _Just mbAuth -> do (courseRegisterForm', regButton) <- courseRegisterForm (Entity cid course) (regWidget, regEnctype) <- generateFormPost $ renderAForm FormStandard courseRegisterForm' return $ wrapForm' regButton regWidget def @@ -170,9 +175,9 @@ getCShowR tid ssh csh = do return . toWidget $ tshow freeCapacity , sortable Nothing (mempty & cellAttrs <>~ pure ("uw-hide-columns--hider-label", mr MsgActionsHead)) $ \DBRow{ dbrOutput = Entity tutId Tutorial{..} } -> sqlCell $ do mayRegister <- (== Authorized) <$> evalAccessDB (CTutorialR tid ssh csh tutorialName TRegisterR) True - isRegistered <- case mbAid of + isRegistered <- case mbAuth of Nothing -> return False - Just uid -> existsBy $ UniqueTutorialParticipant tutId uid + Just (uid,_) -> existsBy $ UniqueTutorialParticipant tutId uid if | mayRegister -> do (tutRegisterForm, tutRegisterEnctype) <- liftHandler . generateFormPost . buttonForm' $ bool [BtnRegister] [BtnDeregister] isRegistered @@ -219,7 +224,7 @@ getCShowR tid ssh csh = do , length fs <= 3 , all (notElem pathSeparator . view _2) fs ] - hiddenEventNotes = all (\(_,CourseEvent{..}) -> is _Nothing courseEventNote) events + hiddenEventNotes = all (\(_,CourseEvent{..},_) -> is _Nothing courseEventNote) events Course{courseVisibleFrom,courseVisibleTo} = course mayCreateNews <- hasWriteAccessTo $ CourseR tid ssh csh CNewsNewR mayCreateEvents <- hasWriteAccessTo $ CourseR tid ssh csh CEventsNewR diff --git a/templates/course.hamlet b/templates/course.hamlet index d863f8b74..2d452ddf8 100644 --- a/templates/course.hamlet +++ b/templates/course.hamlet @@ -260,7 +260,7 @@ $# $if NTop (Just 0) < NTop (courseCapacity course) _{MsgCourseEventRoom} _{MsgCourseEventNote} - $if is _Just mbAid + $if is _Just mbAuth _{MsgScheduleOptActions} $if mayCreateEvents @@ -268,7 +268,7 @@ $# $if NTop (Just 0) < NTop (courseCapacity course) _{MsgCourseEventActions} \ #{iconInvisible} - $forall (cID, CourseEvent{courseEventType, courseEventTime, courseEventRoom, courseEventNote}) <- events + $forall (cID, CourseEvent{courseEventType, courseEventTime, courseEventRoom, courseEventNote}, mEventScheduleOpt) <- events toPathPiece cID}>
@@ -282,12 +282,11 @@ $# $if NTop (Just 0) < NTop (courseCapacity course)
#{courseEventNote} - $if is _Just mbAid + $maybe (_, User{userScheduleOccurrenceDisplayDefault}) <- mbAuth
- $# TODO: check for current opt-* and choose link and label accordingly - - _{MsgScheduleOptOut} + + _{bool MsgScheduleOptIn MsgScheduleOptOut (maybe userScheduleOccurrenceDisplayDefault courseEventScheduleOptOpt mEventScheduleOpt)} $# TODO: add link to remove schedule opt-* $if mayCreateEvents