diff options
Diffstat (limited to 'routers')
-rw-r--r-- | routers/admin/hooks.go | 54 | ||||
-rw-r--r-- | routers/org/setting.go | 1 | ||||
-rw-r--r-- | routers/repo/webhook.go | 30 | ||||
-rw-r--r-- | routers/routes/macaron.go | 25 |
4 files changed, 61 insertions, 49 deletions
diff --git a/routers/admin/hooks.go b/routers/admin/hooks.go index 4697c4d933..e233e8ac00 100644 --- a/routers/admin/hooks.go +++ b/routers/admin/hooks.go @@ -18,30 +18,41 @@ const ( // DefaultOrSystemWebhooks renders both admin default and system webhook list pages func DefaultOrSystemWebhooks(ctx *context.Context) { - var ws []*models.Webhook var err error - // Are we looking at default webhooks? - if ctx.Params(":configType") == "hooks" { - ctx.Data["Title"] = ctx.Tr("admin.hooks") - ctx.Data["Description"] = ctx.Tr("admin.hooks.desc") - ctx.Data["PageIsAdminHooks"] = true - ctx.Data["BaseLink"] = setting.AppSubURL + "/admin/hooks" - ws, err = models.GetDefaultWebhooks() - } else { - ctx.Data["Title"] = ctx.Tr("admin.systemhooks") - ctx.Data["Description"] = ctx.Tr("admin.systemhooks.desc") - ctx.Data["PageIsAdminSystemHooks"] = true - ctx.Data["BaseLink"] = setting.AppSubURL + "/admin/system-hooks" - ws, err = models.GetSystemWebhooks() + ctx.Data["PageIsAdminSystemHooks"] = true + ctx.Data["PageIsAdminDefaultHooks"] = true + + def := make(map[string]interface{}, len(ctx.Data)) + sys := make(map[string]interface{}, len(ctx.Data)) + for k, v := range ctx.Data { + def[k] = v + sys[k] = v + } + + sys["Title"] = ctx.Tr("admin.systemhooks") + sys["Description"] = ctx.Tr("admin.systemhooks.desc") + sys["Webhooks"], err = models.GetSystemWebhooks() + sys["BaseLink"] = setting.AppSubURL + "/admin/hooks" + sys["BaseLinkNew"] = setting.AppSubURL + "/admin/system-hooks" + if err != nil { + ctx.ServerError("GetWebhooksAdmin", err) + return } + def["Title"] = ctx.Tr("admin.defaulthooks") + def["Description"] = ctx.Tr("admin.defaulthooks.desc") + def["Webhooks"], err = models.GetDefaultWebhooks() + def["BaseLink"] = setting.AppSubURL + "/admin/hooks" + def["BaseLinkNew"] = setting.AppSubURL + "/admin/default-hooks" if err != nil { ctx.ServerError("GetWebhooksAdmin", err) return } - ctx.Data["Webhooks"] = ws + ctx.Data["DefaultWebhooks"] = def + ctx.Data["SystemWebhooks"] = sys + ctx.HTML(200, tplAdminHooks) } @@ -53,14 +64,7 @@ func DeleteDefaultOrSystemWebhook(ctx *context.Context) { ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success")) } - // Are we looking at default webhooks? - if ctx.Params(":configType") == "hooks" { - ctx.JSON(200, map[string]interface{}{ - "redirect": setting.AppSubURL + "/admin/hooks", - }) - } else { - ctx.JSON(200, map[string]interface{}{ - "redirect": setting.AppSubURL + "/admin/system-hooks", - }) - } + ctx.JSON(200, map[string]interface{}{ + "redirect": setting.AppSubURL + "/admin/hooks", + }) } diff --git a/routers/org/setting.go b/routers/org/setting.go index 454714c7eb..05075ca820 100644 --- a/routers/org/setting.go +++ b/routers/org/setting.go @@ -173,6 +173,7 @@ func Webhooks(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("org.settings") ctx.Data["PageIsSettingsHooks"] = true ctx.Data["BaseLink"] = ctx.Org.OrgLink + "/settings/hooks" + ctx.Data["BaseLinkNew"] = ctx.Org.OrgLink + "/settings/hooks" ctx.Data["Description"] = ctx.Tr("org.settings.hooks_desc") ws, err := models.GetWebhooksByOrgID(ctx.Org.Organization.ID, models.ListOptions{}) 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 { diff --git a/routers/routes/macaron.go b/routers/routes/macaron.go index 66c39b7f82..d331e4ca83 100644 --- a/routers/routes/macaron.go +++ b/routers/routes/macaron.go @@ -370,19 +370,9 @@ func RegisterMacaronRoutes(m *macaron.Macaron) { m.Post("/delete", admin.DeleteRepo) }) - m.Group("/^:configType(hooks|system-hooks)$", func() { + m.Group("/hooks", func() { m.Get("", admin.DefaultOrSystemWebhooks) m.Post("/delete", admin.DeleteDefaultOrSystemWebhook) - m.Get("/:type/new", repo.WebhooksNew) - m.Post("/gitea/new", bindIgnErr(auth.NewWebhookForm{}), repo.GiteaHooksNewPost) - m.Post("/gogs/new", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksNewPost) - m.Post("/slack/new", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksNewPost) - m.Post("/discord/new", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksNewPost) - m.Post("/dingtalk/new", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksNewPost) - m.Post("/telegram/new", bindIgnErr(auth.NewTelegramHookForm{}), repo.TelegramHooksNewPost) - m.Post("/matrix/new", bindIgnErr(auth.NewMatrixHookForm{}), repo.MatrixHooksNewPost) - m.Post("/msteams/new", bindIgnErr(auth.NewMSTeamsHookForm{}), repo.MSTeamsHooksNewPost) - m.Post("/feishu/new", bindIgnErr(auth.NewFeishuHookForm{}), repo.FeishuHooksNewPost) m.Get("/:id", repo.WebHooksEdit) m.Post("/gitea/:id", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost) m.Post("/gogs/:id", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksEditPost) @@ -395,6 +385,19 @@ func RegisterMacaronRoutes(m *macaron.Macaron) { m.Post("/feishu/:id", bindIgnErr(auth.NewFeishuHookForm{}), repo.FeishuHooksEditPost) }) + m.Group("/^:configType(default-hooks|system-hooks)$", func() { + m.Get("/:type/new", repo.WebhooksNew) + m.Post("/gitea/new", bindIgnErr(auth.NewWebhookForm{}), repo.GiteaHooksNewPost) + m.Post("/gogs/new", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksNewPost) + m.Post("/slack/new", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksNewPost) + m.Post("/discord/new", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksNewPost) + m.Post("/dingtalk/new", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksNewPost) + m.Post("/telegram/new", bindIgnErr(auth.NewTelegramHookForm{}), repo.TelegramHooksNewPost) + m.Post("/matrix/new", bindIgnErr(auth.NewMatrixHookForm{}), repo.MatrixHooksNewPost) + m.Post("/msteams/new", bindIgnErr(auth.NewMSTeamsHookForm{}), repo.MSTeamsHooksNewPost) + m.Post("/feishu/new", bindIgnErr(auth.NewFeishuHookForm{}), repo.FeishuHooksNewPost) + }) + m.Group("/auths", func() { m.Get("", admin.Authentications) m.Combo("/new").Get(admin.NewAuthSource).Post(bindIgnErr(auth.AuthenticationForm{}), admin.NewAuthSourcePost) |