only public submissions are listed when queried

This commit is contained in:
Filip Gralinski 2016-02-15 12:42:05 +01:00
parent 923b1fe8f0
commit 4e3523e3db
5 changed files with 46 additions and 13 deletions

View File

@ -6,9 +6,6 @@ import Handler.Shared
import PersistSHA1
import Text.Printf
import Database.Persist.Sql
import Data.Text as T
getMakePublicR :: SubmissionId -> Handler TypedContent
@ -23,15 +20,15 @@ doMakePublic submissionId chan = do
else do
msg chan "Making the submission public..."
runDB $ update submissionId [SubmissionIsPublic =. True]
let targetBranchName = printf "submission-%05d" $ fromSqlKey submissionId
submission <- runDB $ get404 submissionId
challenge <- runDB $ get404 $ submissionChallenge submission
let submissionRepoId = submissionRepo submission
submissionRepoDir <- getRepoDir submissionRepoId
let targetRepoUrl = T.unpack $ gitServer ++ challengeName challenge
msg chan $ T.pack $ "Start pushing from " ++ submissionRepoDir ++ " to repo " ++ targetRepoUrl ++ ", branch " ++ targetBranchName ++ " ..."
let targetRepoUrl = getPublicSubmissionUrl $ challengeName challenge
let targetBranchName = getPublicSubmissionBranch submissionId
msg chan $ "Start pushing from " ++ (T.pack submissionRepoDir) ++ " to repo " ++ targetRepoUrl ++ ", branch " ++ targetBranchName ++ " ..."
let commit = submissionCommit submission
pushRepo submissionRepoDir commit targetRepoUrl targetBranchName chan
pushRepo submissionRepoDir commit (T.unpack $ targetRepoUrl) (T.unpack $ targetBranchName) chan
return ()

View File

@ -3,6 +3,7 @@ module Handler.Query where
import Import
import Handler.Tables (formatSubmitter)
import Handler.Shared
import PersistSHA1
import Database.Persist.Sql
@ -12,22 +13,27 @@ import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3,
withSmallInput)
data FullSubmissionInfo = FullSubmissionInfo {
fsiSubmissionId :: SubmissionId,
fsiSubmission :: Submission,
fsiUser :: User,
fsiRepo :: Repo }
fsiRepo :: Repo,
fsiChallenge :: Challenge }
getFullInfo :: Entity Submission -> Handler FullSubmissionInfo
getFullInfo (Entity submissionId submission) = do
repo <- runDB $ get404 $ submissionRepo submission
user <- runDB $ get404 $ submissionSubmitter submission
challenge <- runDB $ get404 $ submissionChallenge submission
return $ FullSubmissionInfo {
fsiSubmissionId = submissionId,
fsiSubmission = submission,
fsiUser = user,
fsiRepo = repo }
fsiRepo = repo,
fsiChallenge = challenge }
findSubmissions :: Text -> Handler [FullSubmissionInfo]
findSubmissions sha1Prefix = do
submissions <- runDB $ rawSql "SELECT ?? FROM submission WHERE cast(commit as text) like ?" [PersistText $ "\\\\x" ++ sha1Prefix ++ "%"]
submissions <- runDB $ rawSql "SELECT ?? FROM submission WHERE is_public AND cast(commit as text) like ?" [PersistText $ "\\\\x" ++ sha1Prefix ++ "%"]
mapM getFullInfo submissions
getQueryFormR :: Handler Html
@ -62,9 +68,13 @@ processQuery query = do
setTitle "query results"
$(widgetFile "query-results")
queryResult submission = $(widgetFile "query-result")
queryResult submission = do
$(widgetFile "query-result")
where commitSha1AsText = fromSHA1ToText $ submissionCommit $ fsiSubmission submission
submitter = formatSubmitter $ fsiUser submission
publicSubmissionBranch = getPublicSubmissionBranch $ fsiSubmissionId submission
publicSubmissionRepo = getReadOnlySubmissionUrl $ challengeName $ fsiChallenge submission
browsableUrl = browsableGitRepoBranch (challengeName $ fsiChallenge submission) publicSubmissionBranch
stamp = T.pack $ show $ submissionStamp $ fsiSubmission submission
queryForm :: Form Text

View File

@ -27,6 +27,9 @@ import PersistSHA1
import qualified Data.ByteString as BS
import Text.Printf
import Database.Persist.Sql
atom = Control.Concurrent.STM.atomically
type Channel = TChan (Maybe Text)
@ -42,8 +45,27 @@ gitPath = "/usr/bin/git"
browsableGitSite :: Text
browsableGitSite = "http://gonito.net/gitlist/"
serverAddress :: Text
serverAddress = "gonito.net"
gitServer :: Text
gitServer = "ssh://gitolite@gonito.net/"
gitServer = "ssh://gitolite@" ++ serverAddress ++ "/"
gitReadOnlyServer :: Text
gitReadOnlyServer = "git://" ++ serverAddress ++ "/"
getPublicSubmissionBranch :: SubmissionId -> Text
getPublicSubmissionBranch = T.pack . (printf "submission-%05d") . fromSqlKey
getPublicSubmissionUrl :: Text -> Text
getPublicSubmissionUrl bareRepoName = gitServer ++ bareRepoName
getReadOnlySubmissionUrl :: Text -> Text
getReadOnlySubmissionUrl bareRepoName = gitReadOnlyServer ++ bareRepoName
browsableGitRepoBranch :: Text -> Text -> Text
browsableGitRepoBranch bareRepoName branch = (browsableGitRepo bareRepoName) ++ "/" ++ branch ++ "/"
browsableGitRepo :: Text -> Text
browsableGitRepo bareRepoName

View File

@ -1,5 +1,7 @@
<h2>Search for submission by Git commit SHA1 hashes:
<p>(Only public submissions will be returned.)
<p>
<form method=post action=@{QueryFormR}#form enctype=#{formEnctype}>
^{formWidget}

View File

@ -2,5 +2,7 @@
<div .subm-description>#{submissionDescription $ fsiSubmission submission}
<div .subm-user>#{submitter}
<div .subm-stamp>#{stamp}
<div .subm-repo>#{repoUrl $ fsiRepo submission} / #{repoBranch $ fsiRepo submission}
<div .subm-repo>taken from: #{repoUrl $ fsiRepo submission} / branch #{repoBranch $ fsiRepo submission}
<div .subm-repo>publicly available at: #{publicSubmissionRepo} / branch #{publicSubmissionBranch}
<div .subm-browsable>browsable at: <a href="#{browsableUrl}">#{browsableUrl}</a>
<hr>