diff --git a/Foundation.hs b/Foundation.hs index eef32b7..7847d75 100644 --- a/Foundation.hs +++ b/Foundation.hs @@ -159,6 +159,7 @@ instance Yesod App where isAuthorized QueryFormR _ = return Authorized isAuthorized (QueryResultsR _) _ = return Authorized isAuthorized ListChallengesR _ = return Authorized + isAuthorized (ViewVariantR _) _ = return Authorized isAuthorized TagsR _ = return Authorized isAuthorized AchievementsR _ = return Authorized diff --git a/Handler/Query.hs b/Handler/Query.hs index c27c030..3dc9360 100644 --- a/Handler/Query.hs +++ b/Handler/Query.hs @@ -92,6 +92,43 @@ processQuery query = do setTitle "query results" $(widgetFile "query-results") + +getViewVariantR :: VariantId -> Handler Html +getViewVariantR variantId = do + mauthId <- maybeAuth + variant <- runDB $ get404 variantId + let theSubmissionId = variantSubmission variant + theSubmission <- runDB $ get404 theSubmissionId + + if submissionIsPublic theSubmission || Just (submissionSubmitter theSubmission) == (entityKey <$> mauthId) + then + do + fullSubmissionInfo <- getFullInfo (Entity theSubmissionId theSubmission) + + testOutputs <- runDB $ E.select + $ E.from $ \(out, test) -> do + E.where_ (out ^. OutTest E.==. test ^. TestId + E.&&. out ^. OutVariant E.==. E.val variantId) + E.orderBy [] + return (out, test) + + + let outputs = + sortBy (\a b -> ((snd b) `compare` (snd a))) + $ nub + $ map (\(out, test) -> (outChecksum $ entityVal out, testName $ entityVal test)) testOutputs + + defaultLayout $ do + setTitle "Variant" + $(widgetFile "view-variant") + else + error "Cannot access this submission variant" + +viewOutput :: (SHA1, Text) -> WidgetFor App () +viewOutput (outputHash, test) = do + let outputSha1AsText = fromSHA1ToText $ outputHash + $(widgetFile "view-output") + resultTable :: Entity Submission -> WidgetFor App () resultTable (Entity submissionId submission) = do (tableEntries, tests) <- handlerToWidget $ runDB $ getChallengeSubmissionInfos (\s -> entityKey s == submissionId) diff --git a/config/routes b/config/routes index b50736a..f2ed0bc 100644 --- a/config/routes +++ b/config/routes @@ -32,6 +32,8 @@ /q QueryFormR GET POST /q/#Text QueryResultsR GET +/view-variant/#VariantId ViewVariantR GET + /api/txt/score/#Text ApiTxtScoreR GET /make-public/#SubmissionId MakePublicR GET diff --git a/templates/edit-submission.hamlet b/templates/edit-submission.hamlet index 87cf5b9..39a715b 100644 --- a/templates/edit-submission.hamlet +++ b/templates/edit-submission.hamlet @@ -9,7 +9,7 @@
+
+
+
+