Add links to the forge

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

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)