forked from filipg/gonito
Validate challenge when add or update
This commit is contained in:
parent
5bd6e34c6b
commit
f5c480205e
@ -11,6 +11,7 @@ import Handler.Extract
|
|||||||
import GEval.Core
|
import GEval.Core
|
||||||
import GEval.OptionsParser
|
import GEval.OptionsParser
|
||||||
import GEval.EvaluationScheme
|
import GEval.EvaluationScheme
|
||||||
|
import GEval.Validation
|
||||||
|
|
||||||
import Gonito.ExtractMetadata (getLastCommitMessage)
|
import Gonito.ExtractMetadata (getLastCommitMessage)
|
||||||
|
|
||||||
@ -95,7 +96,9 @@ doCreateChallenge name publicUrl publicBranch publicGitAnnexRemote privateUrl pr
|
|||||||
repoSpecBranch = (repoBranch publicRepo),
|
repoSpecBranch = (repoBranch publicRepo),
|
||||||
repoSpecGitAnnexRemote = (repoGitAnnexRemote publicRepo)}}) chan
|
repoSpecGitAnnexRemote = (repoGitAnnexRemote publicRepo)}}) chan
|
||||||
case maybePrivateRepoId of
|
case maybePrivateRepoId of
|
||||||
Just privateRepoId -> addChallenge name publicRepoId privateRepoId mDeadline chan
|
Just privateRepoId -> do
|
||||||
|
isValidated <- validateChallenge privateRepoId chan
|
||||||
|
when isValidated $ addChallenge name publicRepoId privateRepoId mDeadline chan
|
||||||
Nothing -> return ()
|
Nothing -> return ()
|
||||||
Nothing -> return ()
|
Nothing -> return ()
|
||||||
|
|
||||||
@ -204,6 +207,10 @@ doChallengeUpdate challengeId
|
|||||||
repoSpecGitAnnexRemote = privateGitAnnexRemote}
|
repoSpecGitAnnexRemote = privateGitAnnexRemote}
|
||||||
chan
|
chan
|
||||||
|
|
||||||
|
isValidated <- validateChallenge privateRepoId chan
|
||||||
|
|
||||||
|
when isValidated $
|
||||||
|
do
|
||||||
privateRepo <- runDB $ get404 $ privateRepoId
|
privateRepo <- runDB $ get404 $ privateRepoId
|
||||||
repoDir <- getRepoDir privateRepoId
|
repoDir <- getRepoDir privateRepoId
|
||||||
(Just versionDescription) <- liftIO $ getLastCommitMessage repoDir
|
(Just versionDescription) <- liftIO $ getLastCommitMessage repoDir
|
||||||
@ -243,7 +250,7 @@ doChallengeUpdate challengeId
|
|||||||
updateTests challengeId chan
|
updateTests challengeId chan
|
||||||
|
|
||||||
return ()
|
return ()
|
||||||
|
return ()
|
||||||
|
|
||||||
incrementVersion :: ChallengeUpdateType -> (Int, Int, Int) -> (Int, Int, Int)
|
incrementVersion :: ChallengeUpdateType -> (Int, Int, Int) -> (Int, Int, Int)
|
||||||
incrementVersion MajorChange (major, _, _) = (major + 1, 0, 0)
|
incrementVersion MajorChange (major, _, _) = (major + 1, 0, 0)
|
||||||
@ -431,3 +438,29 @@ updateChallengeForm publicRepo privateRepo mDeadline = renderBootstrap3 Bootstra
|
|||||||
<*> aopt dayField (bfs MsgChallengeDeadlineDay) (Just $ utctDay <$> mDeadline)
|
<*> aopt dayField (bfs MsgChallengeDeadlineDay) (Just $ utctDay <$> mDeadline)
|
||||||
<*> aopt timeFieldTypeTime (fieldWithTooltip MsgChallengeDeadlineTime MsgChallengeDeadlineTooltip)
|
<*> aopt timeFieldTypeTime (fieldWithTooltip MsgChallengeDeadlineTime MsgChallengeDeadlineTooltip)
|
||||||
(Just $ timeToTimeOfDay <$> utctDayTime <$> mDeadline)
|
(Just $ timeToTimeOfDay <$> utctDayTime <$> mDeadline)
|
||||||
|
|
||||||
|
-- Validate whether a challenge is correct.
|
||||||
|
-- Contrary to `GEval.Validate.validationChallenge` do not
|
||||||
|
-- throw an exception (just return `False`)
|
||||||
|
validateChallenge :: RepoId -- ID of the private repository
|
||||||
|
-> Channel
|
||||||
|
-> Handler Bool -- returns false if not validated
|
||||||
|
validateChallenge repoId chan = do
|
||||||
|
msg chan "Validating the challenge..."
|
||||||
|
|
||||||
|
repoDir <- getRepoDir repoId
|
||||||
|
|
||||||
|
optionsParsingResult <- liftIO $ getOptions [
|
||||||
|
"--expected-directory", repoDir]
|
||||||
|
|
||||||
|
case optionsParsingResult of
|
||||||
|
Left _ -> do
|
||||||
|
err chan "Cannot read metric"
|
||||||
|
return False
|
||||||
|
Right opts -> do
|
||||||
|
result <- liftIO (try $ validationChallenge repoDir (geoSpec opts) :: IO (Either SomeException ()))
|
||||||
|
case result of
|
||||||
|
Left ex -> do
|
||||||
|
err chan (T.pack $ "Invalid challenge!!! " ++ (show ex))
|
||||||
|
return False
|
||||||
|
Right _ -> return True
|
||||||
|
@ -127,7 +127,7 @@ library
|
|||||||
, filemanip
|
, filemanip
|
||||||
, cryptohash
|
, cryptohash
|
||||||
, markdown
|
, markdown
|
||||||
, geval >= 1.21.1.0 && < 1.23
|
, geval >= 1.21.1.0 && < 1.24
|
||||||
, filepath
|
, filepath
|
||||||
, yesod-table
|
, yesod-table
|
||||||
, regex-tdfa
|
, regex-tdfa
|
||||||
|
Loading…
Reference in New Issue
Block a user