Fix links to public submissions
This commit is contained in:
parent
c68fd58f23
commit
69dea3067e
@ -756,6 +756,25 @@ submissionHeader :: Maybe UserId -> Diff (FullSubmissionInfo, Maybe Text) -> Wid
|
|||||||
submissionHeader mUserId param = do
|
submissionHeader mUserId param = do
|
||||||
showFullInfo <- handlerToWidget $ runDB $ canFullInfoBeShown param mUserId
|
showFullInfo <- handlerToWidget $ runDB $ canFullInfoBeShown param mUserId
|
||||||
|
|
||||||
|
app <- getYesod
|
||||||
|
let repoHost = appRepoHost $ appSettings app
|
||||||
|
let submissionToSubmissionUrl submission'
|
||||||
|
= getReadOnlySubmissionUrl (fsiScheme submission')
|
||||||
|
repoHost
|
||||||
|
(fsiChallengeRepo submission')
|
||||||
|
(challengeName $ fsiChallenge submission')
|
||||||
|
let publicSubmissionRepo = submissionToSubmissionUrl <$> submission
|
||||||
|
|
||||||
|
let submissionToBrowsableUrl submission'
|
||||||
|
= browsableGitRepoBranch (fsiScheme submission')
|
||||||
|
repoHost
|
||||||
|
(fsiChallengeRepo submission')
|
||||||
|
(challengeName $ fsiChallenge submission')
|
||||||
|
(getPublicSubmissionBranch $ fsiSubmissionId submission')
|
||||||
|
|
||||||
|
let browsableUrl = submissionToBrowsableUrl <$> submission
|
||||||
|
|
||||||
|
|
||||||
$(widgetFile "submission-header")
|
$(widgetFile "submission-header")
|
||||||
where variantSettings = ("out", ())
|
where variantSettings = ("out", ())
|
||||||
submission = fst <$> param
|
submission = fst <$> param
|
||||||
@ -763,12 +782,8 @@ submissionHeader mUserId param = do
|
|||||||
commitSha1AsText = fromSHA1ToText <$> submissionCommit <$> fsiSubmission <$> submission
|
commitSha1AsText = fromSHA1ToText <$> submissionCommit <$> fsiSubmission <$> submission
|
||||||
submitter = formatSubmitter <$> fsiUser <$> submission
|
submitter = formatSubmitter <$> fsiUser <$> submission
|
||||||
publicSubmissionBranch = getPublicSubmissionBranch <$> fsiSubmissionId <$> submission
|
publicSubmissionBranch = getPublicSubmissionBranch <$> fsiSubmissionId <$> submission
|
||||||
publicSubmissionRepo = submissionToSubmissionUrl <$> submission
|
|
||||||
browsableUrl = submissionToBrowsableUrl <$> submission
|
|
||||||
stamp = T.pack <$> show <$> submissionStamp <$> fsiSubmission <$> submission
|
stamp = T.pack <$> show <$> submissionStamp <$> fsiSubmission <$> submission
|
||||||
|
|
||||||
submissionToSubmissionUrl submission' = getReadOnlySubmissionUrl (fsiScheme submission') (fsiChallengeRepo submission') $ challengeName $ fsiChallenge submission'
|
|
||||||
submissionToBrowsableUrl submission' = browsableGitRepoBranch (fsiScheme submission') (fsiChallengeRepo submission') (challengeName $ fsiChallenge submission') (getPublicSubmissionBranch $ fsiSubmissionId submission')
|
|
||||||
|
|
||||||
queryResult :: Maybe UserId -> FullSubmissionInfo -> WidgetFor App ()
|
queryResult :: Maybe UserId -> FullSubmissionInfo -> WidgetFor App ()
|
||||||
queryResult mUserId submission = do
|
queryResult mUserId submission = do
|
||||||
|
@ -80,15 +80,22 @@ getPublicSubmissionUrl SelfHosted repoHost _ bareRepoName = repoHost ++ bareRepo
|
|||||||
getPublicSubmissionUrl Branches _ (Just repo) _ = repoUrl repo
|
getPublicSubmissionUrl Branches _ (Just repo) _ = repoUrl repo
|
||||||
getPublicSubmissionUrl NoInternalGitServer repoHost _ bareRepoName = repoHost ++ bareRepoName
|
getPublicSubmissionUrl NoInternalGitServer repoHost _ bareRepoName = repoHost ++ bareRepoName
|
||||||
|
|
||||||
getReadOnlySubmissionUrl :: RepoScheme -> Repo -> Text -> Text
|
-- convert a git URL to a publicly available URL
|
||||||
getReadOnlySubmissionUrl SelfHosted _ bareRepoName = gitReadOnlyServer ++ bareRepoName
|
publicRepoUrl :: Text -> Text
|
||||||
getReadOnlySubmissionUrl Branches repo _ = repoUrl repo
|
publicRepoUrl = T.replace "git@github.com:" "https://github.com/"
|
||||||
getReadOnlySubmissionUrl NoInternalGitServer repo _ = repoUrl repo
|
. T.replace "git@gitlab.com:" "https://gitlab.com/"
|
||||||
|
|
||||||
browsableGitRepoBranch :: RepoScheme -> Repo -> Text -> Text -> Text
|
getReadOnlySubmissionUrl :: RepoScheme -> Text -> Repo -> Text -> Text
|
||||||
browsableGitRepoBranch SelfHosted _ bareRepoName branch = (browsableGitRepo bareRepoName) ++ "/" ++ branch ++ "/"
|
getReadOnlySubmissionUrl SelfHosted _ _ bareRepoName = gitReadOnlyServer ++ bareRepoName
|
||||||
browsableGitRepoBranch Branches repo _ branch = sshToHttps (repoUrl repo) branch
|
getReadOnlySubmissionUrl Branches _ repo _ = repoUrl repo
|
||||||
browsableGitRepoBranch NoInternalGitServer repo _ branch = sshToHttps (repoUrl repo) branch
|
getReadOnlySubmissionUrl NoInternalGitServer repoHost _ bareRepoName = publicRepoUrl (repoHost ++ bareRepoName)
|
||||||
|
|
||||||
|
browsableGitRepoBranch :: RepoScheme -> Text -> Repo -> Text -> Text -> Text
|
||||||
|
browsableGitRepoBranch SelfHosted _ _ bareRepoName branch = (browsableGitRepo bareRepoName) ++ "/" ++ branch ++ "/"
|
||||||
|
browsableGitRepoBranch Branches _ repo _ branch = sshToHttps (repoUrl repo) branch
|
||||||
|
browsableGitRepoBranch NoInternalGitServer repoHost repo _ branch
|
||||||
|
= sshToHttps (getPublicSubmissionUrl NoInternalGitServer repoHost (Just repo) branch)
|
||||||
|
branch
|
||||||
|
|
||||||
sshToHttps :: Text -> Text -> Text
|
sshToHttps :: Text -> Text -> Text
|
||||||
sshToHttps url branch = "https://" ++ (T.replace ".git" "" $ T.replace ":" "/" $ T.replace "ssh://" "" $ T.replace "git@" "" url) ++ "/tree/" ++ branch
|
sshToHttps url branch = "https://" ++ (T.replace ".git" "" $ T.replace ":" "/" $ T.replace "ssh://" "" $ T.replace "git@" "" url) ++ "/tree/" ++ branch
|
||||||
|
@ -287,16 +287,21 @@ statusCellWidget :: Text -> RepoScheme -> Repo -> (SubmissionId, Submission, Var
|
|||||||
statusCellWidget challengeName repoScheme challengeRepo (submissionId, submission, variantId, _, mauthId) = do
|
statusCellWidget challengeName repoScheme challengeRepo (submissionId, submission, variantId, _, mauthId) = do
|
||||||
isReevaluable <- handlerToWidget $ runDB $ canBeReevaluated submissionId
|
isReevaluable <- handlerToWidget $ runDB $ canBeReevaluated submissionId
|
||||||
let isVisible = True
|
let isVisible = True
|
||||||
|
|
||||||
|
app <- getYesod
|
||||||
|
let repoHost = appRepoHost $ appSettings app
|
||||||
|
|
||||||
|
let maybeBrowsableUrl = if isPublic
|
||||||
|
then
|
||||||
|
Just $ browsableGitRepoBranch repoScheme repoHost challengeRepo challengeName publicSubmissionBranch
|
||||||
|
else
|
||||||
|
Nothing
|
||||||
|
|
||||||
$(widgetFile "submission-status")
|
$(widgetFile "submission-status")
|
||||||
where commitHash = fromSHA1ToText $ submissionCommit submission
|
where commitHash = fromSHA1ToText $ submissionCommit submission
|
||||||
isPublic = submissionIsPublic submission
|
isPublic = submissionIsPublic submission
|
||||||
isOwner = (mauthId == Just (submissionSubmitter submission))
|
isOwner = (mauthId == Just (submissionSubmitter submission))
|
||||||
publicSubmissionBranch = getPublicSubmissionBranch submissionId
|
publicSubmissionBranch = getPublicSubmissionBranch submissionId
|
||||||
maybeBrowsableUrl = if isPublic
|
|
||||||
then
|
|
||||||
Just $ browsableGitRepoBranch repoScheme challengeRepo challengeName publicSubmissionBranch
|
|
||||||
else
|
|
||||||
Nothing
|
|
||||||
|
|
||||||
getInfoLink :: Submission -> Maybe UserId -> Maybe (Route App)
|
getInfoLink :: Submission -> Maybe UserId -> Maybe (Route App)
|
||||||
getInfoLink submission _ = Just $ QueryResultsR commitHash
|
getInfoLink submission _ = Just $ QueryResultsR commitHash
|
||||||
|
Loading…
Reference in New Issue
Block a user