diff --git a/routers/web/web.go b/routers/web/web.go index b2677f1a65..ec7f6749bf 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -613,9 +613,9 @@ func registerRoutes(m *web.Route) { m.Post("/{type}/new", repo_setting.WebhookCreate) m.Group("/{id}", func() { m.Get("", repo_setting.WebHooksEdit) + m.Post("", repo_setting.WebhookUpdate) m.Post("/replay/{uuid}", repo_setting.ReplayWebhook) }) - m.Post("/{type}/{id:[0-9]+}", repo_setting.WebhookUpdate) }, webhooksEnabled) m.Group("/blocked_users", func() { @@ -715,9 +715,9 @@ func registerRoutes(m *web.Route) { m.Post("/delete", admin.DeleteDefaultOrSystemWebhook) m.Group("/{id}", func() { m.Get("", repo_setting.WebHooksEdit) + m.Post("", repo_setting.WebhookUpdate) m.Post("/replay/{uuid}", repo_setting.ReplayWebhook) }) - m.Post("/{type}/{id:[0-9]+}", repo_setting.WebhookUpdate) }, webhooksEnabled) m.Group("/{configType:default-hooks|system-hooks}", func() { @@ -884,9 +884,9 @@ func registerRoutes(m *web.Route) { m.Post("/{type}/new", repo_setting.WebhookCreate) m.Group("/{id}", func() { m.Get("", repo_setting.WebHooksEdit) + m.Post("", repo_setting.WebhookUpdate) m.Post("/replay/{uuid}", repo_setting.ReplayWebhook) }) - m.Post("/{type}/{id:[0-9]+}", repo_setting.WebhookUpdate) }, webhooksEnabled) m.Group("/labels", func() { @@ -1059,10 +1059,10 @@ func registerRoutes(m *web.Route) { m.Post("/{type}/new", repo_setting.WebhookCreate) m.Group("/{id}", func() { m.Get("", repo_setting.WebHooksEdit) + m.Post("", repo_setting.WebhookUpdate) m.Post("/test", repo_setting.TestWebhook) m.Post("/replay/{uuid}", repo_setting.ReplayWebhook) }) - m.Post("/{type}/{id:[0-9]+}", repo_setting.WebhookUpdate) }, webhooksEnabled) m.Group("/keys", func() { diff --git a/templates/repo/settings/webhook/dingtalk.tmpl b/templates/repo/settings/webhook/dingtalk.tmpl index 0ba99e98ee..f1cd6a1932 100644 --- a/templates/repo/settings/webhook/dingtalk.tmpl +++ b/templates/repo/settings/webhook/dingtalk.tmpl @@ -1,6 +1,6 @@ {{if eq .HookType "dingtalk"}}

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://dingtalk.com" (ctx.Locale.Tr "repo.settings.web_hook_name_dingtalk")}}

-
+ {{.CsrfTokenHtml}}
diff --git a/templates/repo/settings/webhook/discord.tmpl b/templates/repo/settings/webhook/discord.tmpl index d390e739be..95a3806c89 100644 --- a/templates/repo/settings/webhook/discord.tmpl +++ b/templates/repo/settings/webhook/discord.tmpl @@ -1,6 +1,6 @@ {{if eq .HookType "discord"}}

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://discord.com" (ctx.Locale.Tr "repo.settings.web_hook_name_discord")}}

- + {{.CsrfTokenHtml}}
diff --git a/templates/repo/settings/webhook/feishu.tmpl b/templates/repo/settings/webhook/feishu.tmpl index d80deab26f..cd6aaf935a 100644 --- a/templates/repo/settings/webhook/feishu.tmpl +++ b/templates/repo/settings/webhook/feishu.tmpl @@ -1,7 +1,7 @@ {{if eq .HookType "feishu"}}

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://feishu.cn" (ctx.Locale.Tr "repo.settings.web_hook_name_feishu")}}

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://larksuite.com" (ctx.Locale.Tr "repo.settings.web_hook_name_larksuite")}}

- + {{.CsrfTokenHtml}}
diff --git a/templates/repo/settings/webhook/forgejo.tmpl b/templates/repo/settings/webhook/forgejo.tmpl index 0bfb99115c..5c8233a638 100644 --- a/templates/repo/settings/webhook/forgejo.tmpl +++ b/templates/repo/settings/webhook/forgejo.tmpl @@ -1,6 +1,6 @@ {{if eq .HookType "forgejo"}}

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://forgejo.org/docs/latest/user/webhooks/" (ctx.Locale.Tr "repo.settings.web_hook_name_forgejo")}}

- + {{template "base/disable_form_autofill"}} {{.CsrfTokenHtml}}
diff --git a/templates/repo/settings/webhook/gitea.tmpl b/templates/repo/settings/webhook/gitea.tmpl index 38ec29c784..e2a80d3c78 100644 --- a/templates/repo/settings/webhook/gitea.tmpl +++ b/templates/repo/settings/webhook/gitea.tmpl @@ -1,6 +1,6 @@ {{if eq .HookType "gitea"}}

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://forgejo.org/docs/latest/user/webhooks/" (ctx.Locale.Tr "repo.settings.web_hook_name_gitea")}}

- + {{template "base/disable_form_autofill"}} {{.CsrfTokenHtml}}
diff --git a/templates/repo/settings/webhook/gogs.tmpl b/templates/repo/settings/webhook/gogs.tmpl index ff1742aa18..3c60033650 100644 --- a/templates/repo/settings/webhook/gogs.tmpl +++ b/templates/repo/settings/webhook/gogs.tmpl @@ -1,6 +1,6 @@ {{if eq .HookType "gogs"}}

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://forgejo.org/docs/latest/user/webhooks/" (ctx.Locale.Tr "repo.settings.web_hook_name_gogs")}}

- + {{template "base/disable_form_autofill"}} {{.CsrfTokenHtml}}
diff --git a/templates/repo/settings/webhook/matrix.tmpl b/templates/repo/settings/webhook/matrix.tmpl index 43df8fd5bd..57a78d3c81 100644 --- a/templates/repo/settings/webhook/matrix.tmpl +++ b/templates/repo/settings/webhook/matrix.tmpl @@ -1,6 +1,6 @@ {{if eq .HookType "matrix"}}

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://matrix.org/" (ctx.Locale.Tr "repo.settings.web_hook_name_matrix")}}

- + {{.CsrfTokenHtml}}
diff --git a/templates/repo/settings/webhook/msteams.tmpl b/templates/repo/settings/webhook/msteams.tmpl index 62ea24e763..771183c13c 100644 --- a/templates/repo/settings/webhook/msteams.tmpl +++ b/templates/repo/settings/webhook/msteams.tmpl @@ -1,6 +1,6 @@ {{if eq .HookType "msteams"}}

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://teams.microsoft.com" (ctx.Locale.Tr "repo.settings.web_hook_name_msteams")}}

- + {{.CsrfTokenHtml}}
diff --git a/templates/repo/settings/webhook/packagist.tmpl b/templates/repo/settings/webhook/packagist.tmpl index 447f0d7e6b..aad1ab5917 100644 --- a/templates/repo/settings/webhook/packagist.tmpl +++ b/templates/repo/settings/webhook/packagist.tmpl @@ -1,6 +1,6 @@ {{if eq .HookType "packagist"}}

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://packagist.org" (ctx.Locale.Tr "repo.settings.web_hook_name_packagist")}}

- + {{.CsrfTokenHtml}}
diff --git a/templates/repo/settings/webhook/slack.tmpl b/templates/repo/settings/webhook/slack.tmpl index 22c5f6e72f..1000f4a633 100644 --- a/templates/repo/settings/webhook/slack.tmpl +++ b/templates/repo/settings/webhook/slack.tmpl @@ -1,6 +1,6 @@ {{if eq .HookType "slack"}}

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://slack.com" (ctx.Locale.Tr "repo.settings.web_hook_name_slack")}}

- + {{.CsrfTokenHtml}}
diff --git a/templates/repo/settings/webhook/telegram.tmpl b/templates/repo/settings/webhook/telegram.tmpl index 46f96ce495..84bc2dc49d 100644 --- a/templates/repo/settings/webhook/telegram.tmpl +++ b/templates/repo/settings/webhook/telegram.tmpl @@ -1,6 +1,6 @@ {{if eq .HookType "telegram"}}

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://core.telegram.org/bots" (ctx.Locale.Tr "repo.settings.web_hook_name_telegram")}}

- + {{.CsrfTokenHtml}}
diff --git a/templates/repo/settings/webhook/wechatwork.tmpl b/templates/repo/settings/webhook/wechatwork.tmpl index 78a1617123..bee753bf6b 100644 --- a/templates/repo/settings/webhook/wechatwork.tmpl +++ b/templates/repo/settings/webhook/wechatwork.tmpl @@ -1,6 +1,6 @@ {{if eq .HookType "wechatwork"}}

{{ctx.Locale.Tr "repo.settings.add_web_hook_desc" "https://work.weixin.qq.com" (ctx.Locale.Tr "repo.settings.web_hook_name_wechatwork")}}

- + {{.CsrfTokenHtml}}
diff --git a/tests/integration/links_test.go b/tests/integration/links_test.go index 6edcbbc71b..68d7008e02 100644 --- a/tests/integration/links_test.go +++ b/tests/integration/links_test.go @@ -193,8 +193,8 @@ func TestRedirectsWebhooks(t *testing.T) { {from: "/user2/repo1/settings/hooks/" + kind + "/new", to: "/", verb: "POST"}, {from: "/admin/system-hooks/" + kind + "/new", to: "/", verb: "POST"}, {from: "/admin/default-hooks/" + kind + "/new", to: "/", verb: "POST"}, - {from: "/user2/repo1/settings/hooks/" + kind + "/1", to: "/", verb: "POST"}, - {from: "/admin/hooks/" + kind + "/1", to: "/", verb: "POST"}, + {from: "/user2/repo1/settings/hooks/1", to: "/", verb: "POST"}, + {from: "/admin/hooks/1", to: "/", verb: "POST"}, } for _, info := range redirects { req := NewRequest(t, info.verb, info.from) diff --git a/tests/integration/repo_webhook_test.go b/tests/integration/repo_webhook_test.go index 3264f3894e..15da511758 100644 --- a/tests/integration/repo_webhook_test.go +++ b/tests/integration/repo_webhook_test.go @@ -52,7 +52,7 @@ func TestNewWebHookLink(t *testing.T) { htmlDoc := NewHTMLParser(t, resp.Body) assert.Equal(t, webhooksLen, htmlDoc.Find(`a[href^="`+baseurl+`/"][href$="/new"]`).Length(), "not all webhooks are listed in the 'new' dropdown on failure") - resp = session.MakeRequest(t, NewRequestWithValues(t, "POST", baseurl+"/gitea/1", map[string]string{"_csrf": csrfToken}), http.StatusUnprocessableEntity) + resp = session.MakeRequest(t, NewRequestWithValues(t, "POST", baseurl+"/1", map[string]string{"_csrf": csrfToken}), http.StatusUnprocessableEntity) htmlDoc = NewHTMLParser(t, resp.Body) assert.Equal(t, webhooksLen, htmlDoc.Find(`a[href^="`+baseurl+`/"][href$="/new"]`).Length(), "not all webhooks are listed in the 'new' dropdown on failure") }