diff --git a/messages/uniworx/de-de-formal.msg b/messages/uniworx/de-de-formal.msg index 2516680b4..3b1dbedec 100644 --- a/messages/uniworx/de-de-formal.msg +++ b/messages/uniworx/de-de-formal.msg @@ -866,6 +866,9 @@ MailExamOfficeExamResultsIntro courseName@Text termDesc@Text examn@ExamName: Ein MailSubjectExamOfficeExamResultsChanged csh@CourseShorthand examn@ExamName: Ergebnisse für #{examn} in #{csh} wurden verändert MailExamOfficeExamResultsChangedIntro courseName@Text termDesc@Text examn@ExamName: Ein Kursverwalter hat Prüfungsleistungen für #{examn} im Kurs #{courseName} (#{termDesc}) verändert. +MailSubjectExamOfficeExternalExamResults coursen@CourseName examn@ExamName: Ergebnisse für #{examn} in #{coursen} +MailExamOfficeExternalExamResultsIntro coursen@CourseName termDesc@Text examn@ExamName: Ein Kursverwalter hat Prüfungsleistungen für #{examn} im Kurs #{coursen} (#{termDesc}) erstellt oder angepasst. + MailSubjectExamRegistrationActive csh@CourseShorthand examn@ExamName: Anmeldung für #{examn} in #{csh} ist möglich MailExamRegistrationActiveIntro courseName@Text termDesc@Text examn@ExamName: Sie können sich nun für #{examn} im Kurs #{courseName} (#{termDesc}) anmelden. diff --git a/src/Jobs/Crontab.hs b/src/Jobs/Crontab.hs index 814a53407..9c5d81203 100644 --- a/src/Jobs/Crontab.hs +++ b/src/Jobs/Crontab.hs @@ -307,6 +307,27 @@ determineCrontab = execWriterT $ do runConduit $ transPipe lift (selectSource [] []) .| C.mapM_ examJobs + + let + externalExamJobs (Entity nExternalExam ExternalExam{..}) = do + newestResult <- lift . E.select . E.from $ \externalExamResult -> do + E.where_ $ externalExamResult E.^. ExternalExamResultExam E.==. E.val nExternalExam + return . E.max_ $ externalExamResult E.^. ExternalExamResultLastChanged + + case newestResult of + [E.Value (Just lastChange)] -> + tell $ HashMap.singleton + (JobCtlQueue $ JobQueueNotification NotificationExamOfficeExternalExamResults{..}) + Cron + { cronInitial = CronTimestamp . utcToLocalTimeTZ appTZ $ addUTCTime appNotificationCollateDelay lastChange + , cronRepeat = CronRepeatOnChange + , cronRateLimit = nominalDay + , cronNotAfter = Left appNotificationExpiration + } + _other -> return () + + runConduit $ transPipe lift (selectSource [] []) .| C.mapM_ externalExamJobs + let allocationJobs (Entity nAllocation Allocation{..}) = do whenIsJust allocationStaffRegisterFrom $ \staffRegisterFrom -> diff --git a/src/Jobs/Handler/QueueNotification.hs b/src/Jobs/Handler/QueueNotification.hs index 6a7b36fcb..c38575bbc 100644 --- a/src/Jobs/Handler/QueueNotification.hs +++ b/src/Jobs/Handler/QueueNotification.hs @@ -16,6 +16,7 @@ import Jobs.Queue import qualified Data.Set as Set import Handler.Utils.ExamOffice.Exam +import Handler.Utils.ExamOffice.ExternalExam dispatchJobQueueNotification :: Notification -> Handler () @@ -198,6 +199,12 @@ determineNotificationCandidates NotificationExamOfficeExamResultsChanged{..} = E.where_ $ examResult E.^. ExamResultId `E.in_` E.valList (Set.toList nExamResults) E.where_ $ examOfficeExamResultAuth (user E.^. UserId) examResult return user +determineNotificationCandidates NotificationExamOfficeExternalExamResults{..} = + E.select . E.from $ \user -> do + E.where_ . E.exists . E.from $ \externalExamResult -> do + E.where_ $ externalExamResult E.^. ExternalExamResultExam E.==. E.val nExternalExam + E.where_ $ examOfficeExternalExamResultAuth (user E.^. UserId) externalExamResult + return user determineNotificationCandidates notif@NotificationAllocationResults{..} = do lastExec <- fmap (fmap $ cronLastExecTime . entityVal) . getBy . UniqueCronLastExec . toJSON $ JobQueueNotification notif E.select . E.from $ \user -> do @@ -261,6 +268,7 @@ classifyNotification NotificationAllocationOutdatedRatings{} = return NTAll classifyNotification NotificationAllocationUnratedApplications{} = return NTAllocationUnratedApplications classifyNotification NotificationExamOfficeExamResults{} = return NTExamOfficeExamResults classifyNotification NotificationExamOfficeExamResultsChanged{} = return NTExamOfficeExamResultsChanged +classifyNotification NotificationExamOfficeExternalExamResults{} = return NTExamOfficeExamResults classifyNotification NotificationAllocationResults{} = return NTAllocationResults classifyNotification NotificationCourseRegistered{} = return NTCourseRegistered classifyNotification NotificationSubmissionEdited{} = return NTSubmissionEdited diff --git a/src/Jobs/Handler/SendNotification/ExamOffice.hs b/src/Jobs/Handler/SendNotification/ExamOffice.hs index a4cc11818..fe7d766e1 100644 --- a/src/Jobs/Handler/SendNotification/ExamOffice.hs +++ b/src/Jobs/Handler/SendNotification/ExamOffice.hs @@ -3,6 +3,7 @@ module Jobs.Handler.SendNotification.ExamOffice ( dispatchNotificationExamOfficeExamResults , dispatchNotificationExamOfficeExamResultsChanged + , dispatchNotificationExamOfficeExternalExamResults ) where import Import @@ -61,3 +62,22 @@ dispatchNotificationExamOfficeExamResultsChanged nExamResults jRecipient = do addAlternatives $ providePreferredAlternative ($(ihamletFile "templates/mail/examOffice/examResultsChanged.hamlet") :: HtmlUrlI18n UniWorXMessage (Route UniWorX)) + + +dispatchNotificationExamOfficeExternalExamResults :: ExternalExamId -> UserId -> Handler () +dispatchNotificationExamOfficeExternalExamResults nExternalExam jRecipient = userMailT jRecipient $ do + ExternalExam{..} <- liftHandler . runDB $ getJust nExternalExam + replaceMailHeader "Auto-Submitted" $ Just "auto-generated" + setSubjectI $ MsgMailSubjectExamOfficeExternalExamResults externalExamCourseName externalExamExamName + + MsgRenderer mr <- getMailMsgRenderer + let termDesc = mr . ShortTermIdentifier $ unTermKey externalExamTerm + tid = externalExamTerm + ssh = externalExamSchool + coursen = externalExamCourseName + examn = externalExamExamName + + editNotifications <- mkEditNotifications jRecipient + + addAlternatives $ + providePreferredAlternative ($(ihamletFile "templates/mail/examOffice/externalExamResults.hamlet") :: HtmlUrlI18n UniWorXMessage (Route UniWorX)) diff --git a/src/Jobs/Types.hs b/src/Jobs/Types.hs index b23a68c0d..21bea5be8 100644 --- a/src/Jobs/Types.hs +++ b/src/Jobs/Types.hs @@ -89,6 +89,7 @@ data Notification = NotificationSubmissionRated { nSubmission :: SubmissionId } | NotificationAllocationOutdatedRatings { nAllocation :: AllocationId } | NotificationExamOfficeExamResults { nExam :: ExamId } | NotificationExamOfficeExamResultsChanged { nExamResults :: Set ExamResultId } + | NotificationExamOfficeExternalExamResults { nExternalExam :: ExternalExamId } | NotificationAllocationResults { nAllocation :: AllocationId } | NotificationCourseRegistered { nUser :: UserId, nCourse :: CourseId } | NotificationSubmissionEdited { nInitiator :: UserId, nSubmission :: SubmissionId } diff --git a/templates/mail/examOffice/externalExamResults.hamlet b/templates/mail/examOffice/externalExamResults.hamlet new file mode 100644 index 000000000..65c73c705 --- /dev/null +++ b/templates/mail/examOffice/externalExamResults.hamlet @@ -0,0 +1,18 @@ +$newline never +\ + + + +