Add links to the forge

This commit is contained in:
nemunaire 2023-03-06 18:46:41 +01:00
parent 562cd5b397
commit 6c471b5ec1
2 changed files with 21 additions and 1 deletions

View File

@ -262,7 +262,7 @@
{#await my_submission}
<div class="spinner-grow spinner-grow-sm mx-1" role="status"></div>
{:then submission}
<strong>{submission.commit} ({submission.tag})</strong> (taille&nbsp;: {submission.size}&nbsp;o, date&nbsp;: <DateFormat date={new Date(submission.date)} dateStyle="medium" timeStyle="medium" />)
<strong><a href="/api/works/{w.id}/forge/-/tree/{submission.commit}" target="_blank">{submission.commit}</a> (<a href="/api/works/{w.id}/forge/-/tree/{submission.tag}" target="_blank">{submission.tag}</a>)</strong> (taille&nbsp;: {submission.size}&nbsp;o, date&nbsp;: <DateFormat date={new Date(submission.date)} dateStyle="medium" timeStyle="medium" />)
{:catch}
<strong>-</strong>
{/await}

View File

@ -370,6 +370,26 @@ func declareAPIAuthWorksRoutes(router *gin.RouterGroup) {
})
// Grades related to works
worksRoutes.GET("/forge/*path", func(c *gin.Context) {
w := c.MustGet("work").(*Work)
var u *User
if user, ok := c.Get("user"); ok {
u = user.(*User)
} else {
u = c.MustGet("LoggedUser").(*User)
}
repo, err := u.getRepositoryByWork(w.Id)
if err != nil {
log.Printf("Unable to getRepositoryByWork(uid=%d, wid=%d): %s", u.Id, w.Id, err.Error())
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Unable to find a corresponding repository."})
return
}
c.Redirect(http.StatusFound, strings.TrimSuffix(strings.Replace(strings.Replace(repo.URI, ":", "/", 1), "git@", "https://", 1), ".git")+c.Param("path"))
})
worksRoutes.GET("/score", func(c *gin.Context) {
u := c.MustGet("LoggedUser").(*User)
w := c.MustGet("work").(*Work)