mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-27 04:11:03 +00:00
Merge pull request #1709 from bradrydzewski/master
fixed router issue and removed unused HTML pages
This commit is contained in:
commit
35e5435400
2 changed files with 30 additions and 68 deletions
|
@ -6,8 +6,6 @@ import (
|
||||||
|
|
||||||
"github.com/drone/drone/cache"
|
"github.com/drone/drone/cache"
|
||||||
"github.com/drone/drone/model"
|
"github.com/drone/drone/model"
|
||||||
"github.com/drone/drone/remote"
|
|
||||||
"github.com/drone/drone/shared/token"
|
|
||||||
"github.com/drone/drone/store"
|
"github.com/drone/drone/store"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
@ -43,9 +41,9 @@ func SetRepo() gin.HandlerFunc {
|
||||||
var (
|
var (
|
||||||
owner = c.Param("owner")
|
owner = c.Param("owner")
|
||||||
name = c.Param("name")
|
name = c.Param("name")
|
||||||
|
user = User(c)
|
||||||
)
|
)
|
||||||
|
|
||||||
user := User(c)
|
|
||||||
repo, err := store.GetRepoOwnerName(c, owner, name)
|
repo, err := store.GetRepoOwnerName(c, owner, name)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
c.Set("repo", repo)
|
c.Set("repo", repo)
|
||||||
|
@ -53,43 +51,18 @@ func SetRepo() gin.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the user is not nil, check the remote system
|
// debugging
|
||||||
// to see if the repository actually exists. If yes,
|
log.Debugf("Cannot find repository %s/%s. %s",
|
||||||
// we can prompt the user to add.
|
owner,
|
||||||
|
name,
|
||||||
|
err.Error(),
|
||||||
|
)
|
||||||
|
|
||||||
if user != nil {
|
if user != nil {
|
||||||
remote := remote.FromContext(c)
|
c.AbortWithStatus(http.StatusNotFound)
|
||||||
repo, err = remote.Repo(user, owner, name)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Cannot find remote repository %s/%s for user %s. %s",
|
|
||||||
owner, name, user.Login, err)
|
|
||||||
} else {
|
|
||||||
log.Debugf("Found remote repository %s/%s for user %s",
|
|
||||||
owner, name, user.Login)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data := gin.H{
|
|
||||||
"User": user,
|
|
||||||
"Repo": repo,
|
|
||||||
}
|
|
||||||
|
|
||||||
// if we found a repository, we should display a page
|
|
||||||
// to the user allowing them to activate.
|
|
||||||
if repo != nil && len(repo.FullName) != 0 {
|
|
||||||
// we should probably move this code to a
|
|
||||||
// separate route, but for now we need to
|
|
||||||
// add a CSRF token.
|
|
||||||
data["Csrf"], _ = token.New(
|
|
||||||
token.CsrfToken,
|
|
||||||
user.Login,
|
|
||||||
).Sign(user.Hash)
|
|
||||||
|
|
||||||
c.HTML(http.StatusNotFound, "repo_activate.html", data)
|
|
||||||
} else {
|
} else {
|
||||||
c.HTML(http.StatusNotFound, "404.html", data)
|
c.AbortWithStatus(http.StatusUnauthorized)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Abort()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +148,6 @@ func SetPerm() gin.HandlerFunc {
|
||||||
|
|
||||||
func MustPull(c *gin.Context) {
|
func MustPull(c *gin.Context) {
|
||||||
user := User(c)
|
user := User(c)
|
||||||
repo := Repo(c)
|
|
||||||
perm := Perm(c)
|
perm := Perm(c)
|
||||||
|
|
||||||
if perm.Pull {
|
if perm.Pull {
|
||||||
|
@ -183,21 +155,22 @@ func MustPull(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the user doesn't have pull permission to the
|
// debugging
|
||||||
// repository we display a 404 error to avoid leaking
|
if user != nil {
|
||||||
// repository information.
|
c.AbortWithStatus(http.StatusNotFound)
|
||||||
c.HTML(http.StatusNotFound, "404.html", gin.H{
|
log.Debugf("User %s denied read access to %s",
|
||||||
"User": user,
|
user.Login, c.Request.URL.Path)
|
||||||
"Repo": repo,
|
} else {
|
||||||
"Perm": perm,
|
c.AbortWithStatus(http.StatusUnauthorized)
|
||||||
})
|
log.Debugf("Guest denied read access to %s %s",
|
||||||
|
c.Request.Method,
|
||||||
c.Abort()
|
c.Request.URL.Path,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func MustPush(c *gin.Context) {
|
func MustPush(c *gin.Context) {
|
||||||
user := User(c)
|
user := User(c)
|
||||||
repo := Repo(c)
|
|
||||||
perm := Perm(c)
|
perm := Perm(c)
|
||||||
|
|
||||||
// if the user has push access, immediately proceed
|
// if the user has push access, immediately proceed
|
||||||
|
@ -207,32 +180,17 @@ func MustPush(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := gin.H{
|
|
||||||
"User": user,
|
|
||||||
"Repo": repo,
|
|
||||||
"Perm": perm,
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the user has pull access we should tell them
|
|
||||||
// the operation is not authorized. Otherwise we should
|
|
||||||
// give a 404 to avoid leaking information.
|
|
||||||
if !perm.Pull {
|
|
||||||
c.HTML(http.StatusNotFound, "404.html", data)
|
|
||||||
} else {
|
|
||||||
c.HTML(http.StatusUnauthorized, "401.html", data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// debugging
|
// debugging
|
||||||
if user != nil {
|
if user != nil {
|
||||||
log.Debugf("%s denied write access to %s",
|
c.AbortWithStatus(http.StatusNotFound)
|
||||||
|
log.Debugf("User %s denied write access to %s",
|
||||||
user.Login, c.Request.URL.Path)
|
user.Login, c.Request.URL.Path)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
c.AbortWithStatus(http.StatusUnauthorized)
|
||||||
log.Debugf("Guest denied write access to %s %s",
|
log.Debugf("Guest denied write access to %s %s",
|
||||||
c.Request.Method,
|
c.Request.Method,
|
||||||
c.Request.URL.Path,
|
c.Request.URL.Path,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Abort()
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,11 @@ func Load(middleware ...gin.HandlerFunc) http.Handler {
|
||||||
e.Use(gin.Recovery())
|
e.Use(gin.Recovery())
|
||||||
|
|
||||||
e.SetHTMLTemplate(template.Load())
|
e.SetHTMLTemplate(template.Load())
|
||||||
e.StaticFS("/static", dist.AssetFS())
|
|
||||||
|
fs := http.FileServer(dist.AssetFS())
|
||||||
|
e.GET("/static/*filepath", func(c *gin.Context) {
|
||||||
|
fs.ServeHTTP(c.Writer, c.Request)
|
||||||
|
})
|
||||||
|
|
||||||
e.Use(header.NoCache)
|
e.Use(header.NoCache)
|
||||||
e.Use(header.Options)
|
e.Use(header.Options)
|
||||||
|
|
Loading…
Reference in a new issue