2023-03-10 19:58:32 +05:30
|
|
|
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package setting
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2023-11-24 09:19:41 +05:30
|
|
|
"code.gitea.io/gitea/models/db"
|
2023-03-10 19:58:32 +05:30
|
|
|
"code.gitea.io/gitea/models/webhook"
|
|
|
|
"code.gitea.io/gitea/modules/base"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2024-02-27 12:42:22 +05:30
|
|
|
"code.gitea.io/gitea/services/context"
|
2024-03-24 01:58:30 +05:30
|
|
|
webhook_service "code.gitea.io/gitea/services/webhook"
|
2023-03-10 19:58:32 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
tplSettingsHooks base.TplName = "user/settings/hooks"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Webhooks render webhook list page
|
|
|
|
func Webhooks(ctx *context.Context) {
|
|
|
|
ctx.Data["Title"] = ctx.Tr("settings")
|
|
|
|
ctx.Data["PageIsSettingsHooks"] = true
|
|
|
|
ctx.Data["BaseLink"] = setting.AppSubURL + "/user/settings/hooks"
|
|
|
|
ctx.Data["BaseLinkNew"] = setting.AppSubURL + "/user/settings/hooks"
|
2024-03-24 01:58:30 +05:30
|
|
|
ctx.Data["WebhookList"] = webhook_service.List()
|
2023-03-10 19:58:32 +05:30
|
|
|
ctx.Data["Description"] = ctx.Tr("settings.hooks.desc")
|
|
|
|
|
2023-11-24 09:19:41 +05:30
|
|
|
ws, err := db.Find[webhook.Webhook](ctx, webhook.ListWebhookOptions{OwnerID: ctx.Doer.ID})
|
2023-03-10 19:58:32 +05:30
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("ListWebhooksByOpts", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Data["Webhooks"] = ws
|
|
|
|
ctx.HTML(http.StatusOK, tplSettingsHooks)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteWebhook response for delete webhook
|
|
|
|
func DeleteWebhook(ctx *context.Context) {
|
2023-10-14 14:07:24 +05:30
|
|
|
if err := webhook.DeleteWebhookByOwnerID(ctx, ctx.Doer.ID, ctx.FormInt64("id")); err != nil {
|
2023-03-10 19:58:32 +05:30
|
|
|
ctx.Flash.Error("DeleteWebhookByOwnerID: " + err.Error())
|
|
|
|
} else {
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success"))
|
|
|
|
}
|
|
|
|
|
2023-07-26 11:34:01 +05:30
|
|
|
ctx.JSONRedirect(setting.AppSubURL + "/user/settings/hooks")
|
2023-03-10 19:58:32 +05:30
|
|
|
}
|