Skip to content

Commit c35b7ac

Browse files
committed
Modify router to handle system webhooks and default ones
1 parent 1decbb5 commit c35b7ac

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

routers/admin/hooks.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,39 @@
55
package admin
66

77
import (
8+
"strings"
9+
810
"code.gitea.io/gitea/models"
911
"code.gitea.io/gitea/modules/base"
1012
"code.gitea.io/gitea/modules/context"
1113
"code.gitea.io/gitea/modules/setting"
1214
)
1315

1416
const (
15-
// tplAdminHooks template path for render hook settings
17+
// tplAdminHooks template path to render hook settings
1618
tplAdminHooks base.TplName = "admin/hooks"
1719
)
1820

19-
// DefaultWebhooks render admin-default webhook list page
20-
func DefaultWebhooks(ctx *context.Context) {
21+
// DefaultAndSystemWebhooks renders both admin default and system webhook list pages
22+
func DefaultAndSystemWebhooks(ctx *context.Context) {
2123
ctx.Data["Title"] = ctx.Tr("admin.hooks")
22-
ctx.Data["PageIsAdminHooks"] = true
23-
ctx.Data["BaseLink"] = setting.AppSubURL + "/admin/hooks"
2424
ctx.Data["Description"] = ctx.Tr("admin.hooks.desc")
2525

26-
ws, err := models.GetDefaultWebhooks()
26+
// Are we looking at default webhooks?
27+
var ws []*models.Webhook
28+
var err error
29+
if strings.Contains(ctx.Link, "/admin/hooks") {
30+
ctx.Data["PageIsAdminHooks"] = true
31+
ctx.Data["BaseLink"] = setting.AppSubURL + "/admin/hooks"
32+
ws, err = models.GetDefaultWebhooks()
33+
} else {
34+
ctx.Data["PageIsAdminSystemHooks"] = true
35+
ctx.Data["BaseLink"] = setting.AppSubURL + "/admin/system-hooks"
36+
ws, err = models.GetSystemWebhooks()
37+
}
38+
2739
if err != nil {
28-
ctx.ServerError("GetWebhooksDefaults", err)
40+
ctx.ServerError("GetWebhooksAdmin", err)
2941
return
3042
}
3143

routers/routes/routes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,8 @@ func RegisterRoutes(m *macaron.Macaron) {
453453
m.Post("/delete", admin.DeleteRepo)
454454
})
455455

456-
m.Group("/hooks", func() {
457-
m.Get("", admin.DefaultWebhooks)
456+
m.Group("/^:type(hooks|system-hooks)$", func() {
457+
m.Get("", admin.DefaultAndSystemWebhooks)
458458
m.Post("/delete", admin.DeleteDefaultWebhook)
459459
m.Get("/:type/new", repo.WebhooksNew)
460460
m.Post("/gitea/new", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksNewPost)

0 commit comments

Comments
 (0)