diff --git a/src/Handler/ExternalExam/Show.hs b/src/Handler/ExternalExam/Show.hs index 0945fbc23..5f9d3fdb4 100644 --- a/src/Handler/ExternalExam/Show.hs +++ b/src/Handler/ExternalExam/Show.hs @@ -5,21 +5,41 @@ module Handler.ExternalExam.Show import Import import Handler.Utils +import Handler.Utils.Invitations +import Handler.ExternalExam.StaffInvite () import qualified Data.CaseInsensitive as CI +import qualified Data.Map as Map + +import qualified Database.Esqueleto as E getEEShowR :: TermId -> SchoolId -> CourseName -> ExamName -> Handler Html getEEShowR tid ssh coursen examn = do mUid <- maybeAuthId - (Entity _ ExternalExam{..}, fmap entityVal -> mResult, School{..}) <- runDB $ do + (Entity _ ExternalExam{..}, fmap entityVal -> mResult, School{..}, staff, addSchools) <- runDB $ do exam@(Entity eeId ExternalExam{..}) <- getBy404 $ UniqueExternalExam tid ssh coursen examn + actualStaff <- E.select . E.from $ \(eeStaff `E.InnerJoin` user) -> do + E.on $ eeStaff E.^. ExternalExamStaffUser E.==. user E.^. UserId + E.where_ $ eeStaff E.^. ExternalExamStaffExam E.==. E.val eeId + E.orderBy [E.asc $ user E.^. UserDisplayName] + return user + maySeeInvites <- hasReadAccessTo $ EExamR tid ssh coursen examn EEGradesR + staffInvites <- if + | maySeeInvites -> sourceInvitationsF @ExternalExamStaff eeId + | otherwise -> return Map.empty + let staff = map Right actualStaff ++ map Left (Map.keys staffInvites) + addSchools <- E.select . E.from $ \(eeSchool `E.InnerJoin` school) -> do + E.on $ eeSchool E.^. ExternalExamOfficeSchoolSchool E.==. school E.^. SchoolId + E.where_ $ eeSchool E.^. ExternalExamOfficeSchoolExam E.==. E.val eeId + E.orderBy [E.asc $ school E.^. SchoolName] + return school school <- getJust externalExamSchool mResult <- fmap join . for mUid $ getBy . UniqueExternalExamResult eeId - return (exam, mResult, school) + return (exam, mResult, school, staff, addSchools) let heading = CI.original examn diff --git a/templates/external-exam-show.hamlet b/templates/external-exam-show.hamlet index 48707d0a0..b8cf6c063 100644 --- a/templates/external-exam-show.hamlet +++ b/templates/external-exam-show.hamlet @@ -38,4 +38,25 @@ $maybe ExternalExamResult{externalExamResultResult} <- mResult _{MsgExamTime}
^{formatTimeW SelFormatDateTime examTime} - + $if not (null addSchools) +
+ _{MsgExternalExamExamOfficeSchools} +
+