You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.0 KiB

  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package admin
  5. import (
  6. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/modules/base"
  8. "code.gitea.io/gitea/modules/context"
  9. "code.gitea.io/gitea/modules/setting"
  10. )
  11. const (
  12. // tplAdminHooks template path to render hook settings
  13. tplAdminHooks base.TplName = "admin/hooks"
  14. )
  15. // DefaultOrSystemWebhooks renders both admin default and system webhook list pages
  16. func DefaultOrSystemWebhooks(ctx *context.Context) {
  17. var ws []*models.Webhook
  18. var err error
  19. // Are we looking at default webhooks?
  20. if ctx.Params(":configType") == "hooks" {
  21. ctx.Data["Title"] = ctx.Tr("admin.hooks")
  22. ctx.Data["Description"] = ctx.Tr("admin.hooks.desc")
  23. ctx.Data["PageIsAdminHooks"] = true
  24. ctx.Data["BaseLink"] = setting.AppSubURL + "/admin/hooks"
  25. ws, err = models.GetDefaultWebhooks()
  26. } else {
  27. ctx.Data["Title"] = ctx.Tr("admin.systemhooks")
  28. ctx.Data["Description"] = ctx.Tr("admin.systemhooks.desc")
  29. ctx.Data["PageIsAdminSystemHooks"] = true
  30. ctx.Data["BaseLink"] = setting.AppSubURL + "/admin/system-hooks"
  31. ws, err = models.GetSystemWebhooks()
  32. }
  33. if err != nil {
  34. ctx.ServerError("GetWebhooksAdmin", err)
  35. return
  36. }
  37. ctx.Data["Webhooks"] = ws
  38. ctx.HTML(200, tplAdminHooks)
  39. }
  40. // DeleteDefaultOrSystemWebhook handler to delete an admin-defined system or default webhook
  41. func DeleteDefaultOrSystemWebhook(ctx *context.Context) {
  42. if err := models.DeleteDefaultSystemWebhook(ctx.QueryInt64("id")); err != nil {
  43. ctx.Flash.Error("DeleteDefaultWebhook: " + err.Error())
  44. } else {
  45. ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success"))
  46. }
  47. // Are we looking at default webhooks?
  48. if ctx.Params(":configType") == "hooks" {
  49. ctx.JSON(200, map[string]interface{}{
  50. "redirect": setting.AppSubURL + "/admin/hooks",
  51. })
  52. } else {
  53. ctx.JSON(200, map[string]interface{}{
  54. "redirect": setting.AppSubURL + "/admin/system-hooks",
  55. })
  56. }
  57. }