mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-01-02 14:28:52 -05:00
Modify router to handle system webhooks and default ones
This commit is contained in:
parent
1decbb5b27
commit
c35b7acafa
2 changed files with 21 additions and 9 deletions
|
@ -5,6 +5,8 @@
|
||||||
package admin
|
package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
|
@ -12,20 +14,30 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// tplAdminHooks template path for render hook settings
|
// tplAdminHooks template path to render hook settings
|
||||||
tplAdminHooks base.TplName = "admin/hooks"
|
tplAdminHooks base.TplName = "admin/hooks"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultWebhooks render admin-default webhook list page
|
// DefaultAndSystemWebhooks renders both admin default and system webhook list pages
|
||||||
func DefaultWebhooks(ctx *context.Context) {
|
func DefaultAndSystemWebhooks(ctx *context.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("admin.hooks")
|
ctx.Data["Title"] = ctx.Tr("admin.hooks")
|
||||||
ctx.Data["PageIsAdminHooks"] = true
|
|
||||||
ctx.Data["BaseLink"] = setting.AppSubURL + "/admin/hooks"
|
|
||||||
ctx.Data["Description"] = ctx.Tr("admin.hooks.desc")
|
ctx.Data["Description"] = ctx.Tr("admin.hooks.desc")
|
||||||
|
|
||||||
ws, err := models.GetDefaultWebhooks()
|
// Are we looking at default webhooks?
|
||||||
|
var ws []*models.Webhook
|
||||||
|
var err error
|
||||||
|
if strings.Contains(ctx.Link, "/admin/hooks") {
|
||||||
|
ctx.Data["PageIsAdminHooks"] = true
|
||||||
|
ctx.Data["BaseLink"] = setting.AppSubURL + "/admin/hooks"
|
||||||
|
ws, err = models.GetDefaultWebhooks()
|
||||||
|
} else {
|
||||||
|
ctx.Data["PageIsAdminSystemHooks"] = true
|
||||||
|
ctx.Data["BaseLink"] = setting.AppSubURL + "/admin/system-hooks"
|
||||||
|
ws, err = models.GetSystemWebhooks()
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetWebhooksDefaults", err)
|
ctx.ServerError("GetWebhooksAdmin", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -453,8 +453,8 @@ func RegisterRoutes(m *macaron.Macaron) {
|
||||||
m.Post("/delete", admin.DeleteRepo)
|
m.Post("/delete", admin.DeleteRepo)
|
||||||
})
|
})
|
||||||
|
|
||||||
m.Group("/hooks", func() {
|
m.Group("/^:type(hooks|system-hooks)$", func() {
|
||||||
m.Get("", admin.DefaultWebhooks)
|
m.Get("", admin.DefaultAndSystemWebhooks)
|
||||||
m.Post("/delete", admin.DeleteDefaultWebhook)
|
m.Post("/delete", admin.DeleteDefaultWebhook)
|
||||||
m.Get("/:type/new", repo.WebhooksNew)
|
m.Get("/:type/new", repo.WebhooksNew)
|
||||||
m.Post("/gitea/new", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksNewPost)
|
m.Post("/gitea/new", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksNewPost)
|
||||||
|
|
Loading…
Reference in a new issue