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,6 +306,13 @@ isBefore :: UTCTime -> Maybe UTCTime -> Bool
isBefore _ Nothing = True isBefore _ Nothing = True
isBefore moment (Just deadline) = moment <= deadline isBefore moment (Just deadline) = moment <= deadline
-- | 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 -> Key Challenge -> ChallengeSubmissionData -> Channel -> Handler ()
doCreateSubmission userId challengeId challengeSubmissionData chan = do doCreateSubmission userId challengeId challengeSubmissionData chan = do
challenge <- runDB $ get404 challengeId challenge <- runDB $ get404 challengeId
@ -314,8 +321,14 @@ doCreateSubmission userId challengeId challengeSubmissionData chan = do
theNow <- liftIO getCurrentTime theNow <- liftIO getCurrentTime
if theNow `isBefore` (versionDeadline $ entityVal version) if theNow `isBefore` (versionDeadline $ entityVal version)
then
do
let wanted = willClone challenge challengeSubmissionData
if wanted
then then
doCreateSubmission' (challengeArchived challenge) userId challengeId challengeSubmissionData chan doCreateSubmission' (challengeArchived challenge) userId challengeId challengeSubmissionData chan
else
msg chan "Refusing to clone the submission from this URL"
else else
msg chan "Submission is past the deadline, no submission will be accepted from now on." msg chan "Submission is past the deadline, no submission will be accepted from now on."