diff options
author | Lauris BH <lauris@nix.lv> | 2021-01-15 01:24:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-15 01:24:03 +0200 |
commit | 6eee9f0f4e56e620b2eacfc9c2b59c6448308290 (patch) | |
tree | 8aa10ddcc6c7ae19ce0e6f28edff93a16949058a /routers/repo | |
parent | 84b147c7f0c2575723d3471783cb24078232fe7a (diff) | |
download | gitea-6eee9f0f4e56e620b2eacfc9c2b59c6448308290.tar.gz gitea-6eee9f0f4e56e620b2eacfc9c2b59c6448308290.zip |
Merge default and system webhooks under one menu (#14244)
Diffstat (limited to 'routers/repo')
-rw-r--r-- | routers/repo/webhook.go | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/routers/repo/webhook.go b/routers/repo/webhook.go index 0c3fd1267d..5d7074b339 100644 --- a/routers/repo/webhook.go +++ b/routers/repo/webhook.go @@ -36,6 +36,7 @@ func Webhooks(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.settings.hooks") ctx.Data["PageIsSettingsHooks"] = true ctx.Data["BaseLink"] = ctx.Repo.RepoLink + "/settings/hooks" + ctx.Data["BaseLinkNew"] = ctx.Repo.RepoLink + "/settings/hooks" ctx.Data["Description"] = ctx.Tr("repo.settings.hooks_desc", "https://docs.gitea.io/en-us/webhooks/") ws, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID, models.ListOptions{}) @@ -54,6 +55,7 @@ type orgRepoCtx struct { IsAdmin bool IsSystemWebhook bool Link string + LinkNew string NewTemplate base.TplName } @@ -63,6 +65,7 @@ func getOrgRepoCtx(ctx *context.Context) (*orgRepoCtx, error) { return &orgRepoCtx{ RepoID: ctx.Repo.Repository.ID, Link: path.Join(ctx.Repo.RepoLink, "settings/hooks"), + LinkNew: path.Join(ctx.Repo.RepoLink, "settings/hooks"), NewTemplate: tplHookNew, }, nil } @@ -71,16 +74,18 @@ func getOrgRepoCtx(ctx *context.Context) (*orgRepoCtx, error) { return &orgRepoCtx{ OrgID: ctx.Org.Organization.ID, Link: path.Join(ctx.Org.OrgLink, "settings/hooks"), + LinkNew: path.Join(ctx.Org.OrgLink, "settings/hooks"), NewTemplate: tplOrgHookNew, }, nil } if ctx.User.IsAdmin { // Are we looking at default webhooks? - if ctx.Params(":configType") == "hooks" { + if ctx.Params(":configType") == "default-hooks" { return &orgRepoCtx{ IsAdmin: true, Link: path.Join(setting.AppSubURL, "/admin/hooks"), + LinkNew: path.Join(setting.AppSubURL, "/admin/default-hooks"), NewTemplate: tplAdminHookNew, }, nil } @@ -89,7 +94,8 @@ func getOrgRepoCtx(ctx *context.Context) (*orgRepoCtx, error) { return &orgRepoCtx{ IsAdmin: true, IsSystemWebhook: true, - Link: path.Join(setting.AppSubURL, "/admin/system-hooks"), + Link: path.Join(setting.AppSubURL, "/admin/hooks"), + LinkNew: path.Join(setting.AppSubURL, "/admin/system-hooks"), NewTemplate: tplAdminHookNew, }, nil } @@ -121,8 +127,8 @@ func WebhooksNew(ctx *context.Context) { ctx.Data["PageIsAdminSystemHooks"] = true ctx.Data["PageIsAdminSystemHooksNew"] = true } else if orCtx.IsAdmin { - ctx.Data["PageIsAdminHooks"] = true - ctx.Data["PageIsAdminHooksNew"] = true + ctx.Data["PageIsAdminDefaultHooks"] = true + ctx.Data["PageIsAdminDefaultHooksNew"] = true } else { ctx.Data["PageIsSettingsHooks"] = true ctx.Data["PageIsSettingsHooksNew"] = true @@ -139,7 +145,7 @@ func WebhooksNew(ctx *context.Context) { "IconURL": setting.AppURL + "img/favicon.png", } } - ctx.Data["BaseLink"] = orCtx.Link + ctx.Data["BaseLink"] = orCtx.LinkNew ctx.HTML(200, orCtx.NewTemplate) } @@ -187,7 +193,7 @@ func GiteaHooksNewPost(ctx *context.Context, form auth.NewWebhookForm) { ctx.ServerError("getOrgRepoCtx", err) return } - ctx.Data["BaseLink"] = orCtx.Link + ctx.Data["BaseLink"] = orCtx.LinkNew if ctx.HasError() { ctx.HTML(200, orCtx.NewTemplate) @@ -241,7 +247,7 @@ func newGogsWebhookPost(ctx *context.Context, form auth.NewGogshookForm, kind mo ctx.ServerError("getOrgRepoCtx", err) return } - ctx.Data["BaseLink"] = orCtx.Link + ctx.Data["BaseLink"] = orCtx.LinkNew if ctx.HasError() { ctx.HTML(200, orCtx.NewTemplate) @@ -537,7 +543,7 @@ func SlackHooksNewPost(ctx *context.Context, form auth.NewSlackHookForm) { if form.HasInvalidChannel() { ctx.Flash.Error(ctx.Tr("repo.settings.add_webhook.invalid_channel_name")) - ctx.Redirect(orCtx.Link + "/slack/new") + ctx.Redirect(orCtx.LinkNew + "/slack/new") return } @@ -632,12 +638,10 @@ func checkWebhook(ctx *context.Context) (*orgRepoCtx, *models.Webhook) { w, err = models.GetWebhookByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) } else if orCtx.OrgID > 0 { w, err = models.GetWebhookByOrgID(ctx.Org.Organization.ID, ctx.ParamsInt64(":id")) - } else if orCtx.IsSystemWebhook { - w, err = models.GetSystemWebhook(ctx.ParamsInt64(":id")) - } else { - w, err = models.GetDefaultWebhook(ctx.ParamsInt64(":id")) + } else if orCtx.IsAdmin { + w, err = models.GetSystemOrDefaultWebhook(ctx.ParamsInt64(":id")) } - if err != nil { + if err != nil || w == nil { if models.IsErrWebhookNotExist(err) { ctx.NotFound("GetWebhookByID", nil) } else { |