mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-27 04:11:03 +00:00
split settings to multiple handler funcs
This commit is contained in:
parent
b039519d3f
commit
ad63fc7060
2 changed files with 32 additions and 21 deletions
|
@ -89,10 +89,7 @@ func ShowRepo(c *gin.Context) {
|
|||
db := context.Database(c)
|
||||
user := session.User(c)
|
||||
repo := session.Repo(c)
|
||||
if !user.Admin {
|
||||
c.AbortWithStatus(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
builds, _ := model.GetBuildList(db, repo)
|
||||
groups := []*model.BuildGroup{}
|
||||
|
||||
|
@ -123,26 +120,13 @@ func ShowRepoConf(c *gin.Context) {
|
|||
user := session.User(c)
|
||||
repo := session.Repo(c)
|
||||
key, _ := model.GetKey(db, repo)
|
||||
if !user.Admin {
|
||||
c.AbortWithStatus(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
var view = "repo_config.html"
|
||||
switch c.Param("action") {
|
||||
case "delete":
|
||||
view = "repo_delete.html"
|
||||
case "encrypt":
|
||||
view = "repo_secret.html"
|
||||
case "badges":
|
||||
view = "repo_badge.html"
|
||||
}
|
||||
|
||||
token, _ := token.New(
|
||||
token.CsrfToken,
|
||||
user.Login,
|
||||
).Sign(user.Hash)
|
||||
|
||||
c.HTML(200, view, gin.H{
|
||||
c.HTML(200, "repo_config.html", gin.H{
|
||||
"User": user,
|
||||
"Repo": repo,
|
||||
"Key": key,
|
||||
|
@ -151,6 +135,33 @@ func ShowRepoConf(c *gin.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
func ShowRepoEncrypt(c *gin.Context) {
|
||||
user := session.User(c)
|
||||
repo := session.Repo(c)
|
||||
|
||||
token, _ := token.New(
|
||||
token.CsrfToken,
|
||||
user.Login,
|
||||
).Sign(user.Hash)
|
||||
|
||||
c.HTML(200, "repo_secret.html", gin.H{
|
||||
"User": user,
|
||||
"Repo": repo,
|
||||
"Csrf": token,
|
||||
})
|
||||
}
|
||||
|
||||
func ShowRepoBadges(c *gin.Context) {
|
||||
user := session.User(c)
|
||||
repo := session.Repo(c)
|
||||
|
||||
c.HTML(200, "repo_badge.html", gin.H{
|
||||
"User": user,
|
||||
"Repo": repo,
|
||||
"Link": httputil.GetURL(c.Request),
|
||||
})
|
||||
}
|
||||
|
||||
func ShowBuild(c *gin.Context) {
|
||||
db := context.Database(c)
|
||||
user := session.User(c)
|
||||
|
|
|
@ -44,9 +44,9 @@ func Load(middleware ...gin.HandlerFunc) http.Handler {
|
|||
repo.GET("/builds/:number/:job", controller.ShowBuild)
|
||||
repo_settings := repo.Group("/settings")
|
||||
{
|
||||
repo_settings.Use(session.MustPush)
|
||||
repo_settings.GET("", controller.ShowRepoConf)
|
||||
repo_settings.GET("/:action", controller.ShowRepoConf)
|
||||
repo_settings.GET("", session.MustPush, controller.ShowRepoConf)
|
||||
repo_settings.GET("/encrypt", session.MustPush, controller.ShowRepoEncrypt)
|
||||
repo_settings.GET("/badges", controller.ShowRepoBadges)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue