Filter out some unwanted submissions

This commit is contained in:
Filip Gralinski 2020-05-30 21:56:52 +02:00
parent aa25d2ecc2
commit bea0787271

View File

@ -306,7 +306,14 @@ isBefore :: UTCTime -> Maybe UTCTime -> Bool
isBefore _ Nothing = True
isBefore moment (Just deadline) = moment <= deadline
doCreateSubmission :: UserId -> Key Challenge -> ChallengeSubmissionData-> Channel -> Handler ()
-- | An attempt to filtre out mistaken/unwanted submissions (without cloning
-- the submission repo, just by looking at the metadata)
willClone :: Challenge -> ChallengeSubmissionData -> Bool
willClone challenge submissionData = (challengeName challenge) `isInfixOf` url
where url = repoSpecUrl $ challengeSubmissionDataRepo submissionData
-- | Main place where submission is done (whether manually or by trigger)
doCreateSubmission :: UserId -> Key Challenge -> ChallengeSubmissionData -> Channel -> Handler ()
doCreateSubmission userId challengeId challengeSubmissionData chan = do
challenge <- runDB $ get404 challengeId
@ -314,8 +321,14 @@ doCreateSubmission userId challengeId challengeSubmissionData chan = do
theNow <- liftIO getCurrentTime
if theNow `isBefore` (versionDeadline $ entityVal version)
then
do
let wanted = willClone challenge challengeSubmissionData
if wanted
then
doCreateSubmission' (challengeArchived challenge) userId challengeId challengeSubmissionData chan
else
msg chan "Refusing to clone the submission from this URL"
else
msg chan "Submission is past the deadline, no submission will be accepted from now on."