From 600d06f75b4fedf74d68a50869df339ac5fb796c Mon Sep 17 00:00:00 2001 From: SJost Date: Wed, 24 Oct 2018 16:58:31 +0200 Subject: [PATCH] Merge Notification ExpiryDate --- config/settings.yml | 1 + src/Jobs/Crontab.hs | 6 ++++-- .../SendNotification/CorrectionsAssigned.hs | 21 ++++++++++--------- src/Settings.hs | 2 ++ 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/config/settings.yml b/config/settings.yml index e8516a171..f4602cd0e 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -25,6 +25,7 @@ job-cron-interval: "_env:CRON_INTERVAL:60" job-stale-threshold: 300 notification-rate-limit: 3600 notification-collate-delay: 300 +notification-expiration: 259201 log-settings: log-detailed: "_env:DETAILED_LOGGING:false" diff --git a/src/Jobs/Crontab.hs b/src/Jobs/Crontab.hs index 9740ddda6..df29f214c 100644 --- a/src/Jobs/Crontab.hs +++ b/src/Jobs/Crontab.hs @@ -74,9 +74,10 @@ determineCrontab = execWriterT $ do tell $ HashMap.singleton (JobCtlQueue $ JobQueueNotification NotificationSheetInactive{..}) Cron - { cronInitial = CronTimestamp $ utcToLocalTimeTZ appTZ sheetActiveTo - , cronRepeat = CronRepeatOnChange + { cronInitial = CronTimestamp $ utcToLocalTimeTZ appTZ sheetActiveTo + , cronRepeat = CronRepeatOnChange , cronRateLimit = appNotificationRateLimit + , cronNotAfter = Left appNotificationExpiration } sheetSubmissions <- lift $ collateSubmissions <$> @@ -89,6 +90,7 @@ determineCrontab = execWriterT $ do { cronInitial = CronTimestamp $ utcToLocalTimeTZ appTZ $ addUTCTime appNotificationCollateDelay time , cronRepeat = CronRepeatNever , cronRateLimit = appNotificationRateLimit + , cronNotAfter = Left appNotificationExpiration } | otherwise -> mempty diff --git a/src/Jobs/Handler/SendNotification/CorrectionsAssigned.hs b/src/Jobs/Handler/SendNotification/CorrectionsAssigned.hs index 324b26695..71376d4ba 100644 --- a/src/Jobs/Handler/SendNotification/CorrectionsAssigned.hs +++ b/src/Jobs/Handler/SendNotification/CorrectionsAssigned.hs @@ -18,7 +18,7 @@ import Text.Hamlet import qualified Data.CaseInsensitive as CI dispatchNotificationCorrectionsAssigned :: UserId -> SheetId -> UserId -> Handler () -dispatchNotificationCorrectionsAssigned nUser nSheet jRecipient = userMailT jRecipient $ do +dispatchNotificationCorrectionsAssigned nUser nSheet jRecipient = do (Course{..}, Sheet{..}, nbrSubs) <- liftHandlerT . runDB $ do sheet <- getJust nSheet course <- belongsToJust sheetCourse sheet @@ -27,14 +27,15 @@ dispatchNotificationCorrectionsAssigned nUser nSheet jRecipient = userMailT jRe , SubmissionRatingTime ==. Nothing ] return (course, sheet, nbrSubs) - setSubjectI $ MsgMailSubjectSheetActive courseShorthand sheetName + when (nbrSubs > 0) . userMailT jRecipient $ do + setSubjectI $ MsgMailSubjectSheetActive courseShorthand sheetName - MsgRenderer mr <- getMailMsgRenderer - let termDesc = mr . ShortTermIdentifier $ unTermKey courseTerm - tid = courseTerm - ssh = courseSchool - csh = courseShorthand - shn = sheetName + MsgRenderer mr <- getMailMsgRenderer + let termDesc = mr . ShortTermIdentifier $ unTermKey courseTerm + tid = courseTerm + ssh = courseSchool + csh = courseShorthand + shn = sheetName - addAlternatives $ do - providePreferredAlternative ($(ihamletFile "templates/mail/correctionsAssigned.hamlet") :: HtmlUrlI18n UniWorXMessage (Route UniWorX)) + addAlternatives $ do + providePreferredAlternative ($(ihamletFile "templates/mail/correctionsAssigned.hamlet") :: HtmlUrlI18n UniWorXMessage (Route UniWorX)) diff --git a/src/Settings.hs b/src/Settings.hs index 492bc0429..c246311a7 100644 --- a/src/Settings.hs +++ b/src/Settings.hs @@ -90,6 +90,7 @@ data AppSettings = AppSettings , appJobStaleThreshold :: NominalDiffTime , appNotificationRateLimit :: NominalDiffTime , appNotificationCollateDelay :: NominalDiffTime + , appNotificationExpiration :: NominalDiffTime , appInitialLogSettings :: LogSettings @@ -295,6 +296,7 @@ instance FromJSON AppSettings where appJobStaleThreshold <- o .: "job-stale-threshold" appNotificationRateLimit <- o .: "notification-rate-limit" appNotificationCollateDelay <- o .: "notification-collate-delay" + appNotificationExpiration <- o .: "notification-expiration" appReloadTemplates <- o .:? "reload-templates" .!= defaultDev appMutableStatic <- o .:? "mutable-static" .!= defaultDev