mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
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.
73 lines
2.1 KiB
73 lines
2.1 KiB
6 years ago
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package admin
|
||
|
|
||
|
import (
|
||
4 years ago
|
"net/http"
|
||
|
|
||
6 years ago
|
"code.gitea.io/gitea/models"
|
||
|
"code.gitea.io/gitea/modules/base"
|
||
|
"code.gitea.io/gitea/modules/context"
|
||
|
"code.gitea.io/gitea/modules/setting"
|
||
|
)
|
||
|
|
||
|
const (
|
||
5 years ago
|
// tplAdminHooks template path to render hook settings
|
||
6 years ago
|
tplAdminHooks base.TplName = "admin/hooks"
|
||
|
)
|
||
|
|
||
5 years ago
|
// DefaultOrSystemWebhooks renders both admin default and system webhook list pages
|
||
|
func DefaultOrSystemWebhooks(ctx *context.Context) {
|
||
|
var err error
|
||
|
|
||
4 years ago
|
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
|
||
5 years ago
|
}
|
||
6 years ago
|
|
||
4 years ago
|
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"
|
||
6 years ago
|
if err != nil {
|
||
5 years ago
|
ctx.ServerError("GetWebhooksAdmin", err)
|
||
6 years ago
|
return
|
||
|
}
|
||
|
|
||
4 years ago
|
ctx.Data["DefaultWebhooks"] = def
|
||
|
ctx.Data["SystemWebhooks"] = sys
|
||
|
|
||
4 years ago
|
ctx.HTML(http.StatusOK, tplAdminHooks)
|
||
6 years ago
|
}
|
||
|
|
||
5 years ago
|
// DeleteDefaultOrSystemWebhook handler to delete an admin-defined system or default webhook
|
||
|
func DeleteDefaultOrSystemWebhook(ctx *context.Context) {
|
||
|
if err := models.DeleteDefaultSystemWebhook(ctx.QueryInt64("id")); err != nil {
|
||
6 years ago
|
ctx.Flash.Error("DeleteDefaultWebhook: " + err.Error())
|
||
|
} else {
|
||
|
ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success"))
|
||
|
}
|
||
|
|
||
4 years ago
|
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||
4 years ago
|
"redirect": setting.AppSubURL + "/admin/hooks",
|
||
|
})
|
||
6 years ago
|
}
|