Partially implement #770. Add "Default Webhooks" page in site admin UI. Persist to the existing webhooks table, but store with RepoID=0 and OrgID=0. Upon repo creation, copy the set of default webhooks into the new repo.tags/v1.9.0-rc1
return fmt.Errorf("newRepoAction: %v", err) | return fmt.Errorf("newRepoAction: %v", err) | ||||
} | } | ||||
if err = copyDefaultWebhooksToRepo(e, repo.ID); err != nil { | |||||
return fmt.Errorf("copyDefaultWebhooksToRepo: %v", err) | |||||
} | |||||
return nil | return nil | ||||
} | } | ||||
// CreateWebhook creates a new web hook. | // CreateWebhook creates a new web hook. | ||||
func CreateWebhook(w *Webhook) error { | func CreateWebhook(w *Webhook) error { | ||||
_, err := x.Insert(w) | |||||
return createWebhook(x, w) | |||||
} | |||||
func createWebhook(e Engine, w *Webhook) error { | |||||
_, err := e.Insert(w) | |||||
return err | return err | ||||
} | } | ||||
return ws, err | return ws, err | ||||
} | } | ||||
// GetDefaultWebhook returns admin-default webhook by given ID. | |||||
func GetDefaultWebhook(id int64) (*Webhook, error) { | |||||
webhook := &Webhook{ID: id} | |||||
has, err := x. | |||||
Where("repo_id=? AND org_id=?", 0, 0). | |||||
Get(webhook) | |||||
if err != nil { | |||||
return nil, err | |||||
} else if !has { | |||||
return nil, ErrWebhookNotExist{id} | |||||
} | |||||
return webhook, nil | |||||
} | |||||
// GetDefaultWebhooks returns all admin-default webhooks. | |||||
func GetDefaultWebhooks() ([]*Webhook, error) { | |||||
return getDefaultWebhooks(x) | |||||
} | |||||
func getDefaultWebhooks(e Engine) ([]*Webhook, error) { | |||||
webhooks := make([]*Webhook, 0, 5) | |||||
return webhooks, e. | |||||
Where("repo_id=? AND org_id=?", 0, 0). | |||||
Find(&webhooks) | |||||
} | |||||
// UpdateWebhook updates information of webhook. | // UpdateWebhook updates information of webhook. | ||||
func UpdateWebhook(w *Webhook) error { | func UpdateWebhook(w *Webhook) error { | ||||
_, err := x.ID(w.ID).AllCols().Update(w) | _, err := x.ID(w.ID).AllCols().Update(w) | ||||
}) | }) | ||||
} | } | ||||
// DeleteDefaultWebhook deletes an admin-default webhook by given ID. | |||||
func DeleteDefaultWebhook(id int64) error { | |||||
sess := x.NewSession() | |||||
defer sess.Close() | |||||
if err := sess.Begin(); err != nil { | |||||
return err | |||||
} | |||||
count, err := sess. | |||||
Where("repo_id=? AND org_id=?", 0, 0). | |||||
Delete(&Webhook{ID: id}) | |||||
if err != nil { | |||||
return err | |||||
} else if count == 0 { | |||||
return ErrWebhookNotExist{ID: id} | |||||
} | |||||
if _, err := sess.Delete(&HookTask{HookID: id}); err != nil { | |||||
return err | |||||
} | |||||
return sess.Commit() | |||||
} | |||||
// copyDefaultWebhooksToRepo creates copies of the default webhooks in a new repo | |||||
func copyDefaultWebhooksToRepo(e Engine, repoID int64) error { | |||||
ws, err := getDefaultWebhooks(e) | |||||
if err != nil { | |||||
return fmt.Errorf("GetDefaultWebhooks: %v", err) | |||||
} | |||||
for _, w := range ws { | |||||
w.ID = 0 | |||||
w.RepoID = repoID | |||||
if err := createWebhook(e, w); err != nil { | |||||
return fmt.Errorf("CreateWebhook: %v", err) | |||||
} | |||||
} | |||||
return nil | |||||
} | |||||
// ___ ___ __ ___________ __ | // ___ ___ __ ___________ __ | ||||
// / | \ ____ ____ | | _\__ ___/____ _____| | __ | // / | \ ____ ____ | | _\__ ___/____ _____| | __ | ||||
// / ~ \/ _ \ / _ \| |/ / | | \__ \ / ___/ |/ / | // / ~ \/ _ \ / _ \| |/ / | | \__ \ / ___/ |/ / |
users = User Accounts | users = User Accounts | ||||
organizations = Organizations | organizations = Organizations | ||||
repositories = Repositories | repositories = Repositories | ||||
hooks = Default Webhooks | |||||
authentication = Authentication Sources | authentication = Authentication Sources | ||||
config = Configuration | config = Configuration | ||||
notices = System Notices | notices = System Notices | ||||
repos.issues = Issues | repos.issues = Issues | ||||
repos.size = Size | repos.size = Size | ||||
hooks.desc = Webhooks automatically make HTTP POST requests to a server when certain Gitea events trigger. Webhooks defined here are defaults and will be copied into all new repositories. Read more in the <a target="_blank" rel="noopener" href="https://docs.gitea.io/en-us/webhooks/">webhooks guide</a>. | |||||
hooks.add_webhook = Add Default Webhook | |||||
hooks.update_webhook = Update Default Webhook | |||||
auths.auth_manage_panel = Authentication Source Management | auths.auth_manage_panel = Authentication Source Management | ||||
auths.new = Add Authentication Source | auths.new = Add Authentication Source | ||||
auths.name = Name | auths.name = Name |
// 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 ( | |||||
"code.gitea.io/gitea/models" | |||||
"code.gitea.io/gitea/modules/base" | |||||
"code.gitea.io/gitea/modules/context" | |||||
"code.gitea.io/gitea/modules/setting" | |||||
) | |||||
const ( | |||||
// tplAdminHooks template path for render hook settings | |||||
tplAdminHooks base.TplName = "admin/hooks" | |||||
) | |||||
// DefaultWebhooks render admin-default webhook list page | |||||
func DefaultWebhooks(ctx *context.Context) { | |||||
ctx.Data["Title"] = ctx.Tr("admin.hooks") | |||||
ctx.Data["PageIsAdminHooks"] = true | |||||
ctx.Data["BaseLink"] = setting.AppSubURL + "/admin/hooks" | |||||
ctx.Data["Description"] = ctx.Tr("admin.hooks.desc") | |||||
ws, err := models.GetDefaultWebhooks() | |||||
if err != nil { | |||||
ctx.ServerError("GetWebhooksDefaults", err) | |||||
return | |||||
} | |||||
ctx.Data["Webhooks"] = ws | |||||
ctx.HTML(200, tplAdminHooks) | |||||
} | |||||
// DeleteDefaultWebhook response for delete admin-default webhook | |||||
func DeleteDefaultWebhook(ctx *context.Context) { | |||||
if err := models.DeleteDefaultWebhook(ctx.QueryInt64("id")); err != nil { | |||||
ctx.Flash.Error("DeleteDefaultWebhook: " + err.Error()) | |||||
} else { | |||||
ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success")) | |||||
} | |||||
ctx.JSON(200, map[string]interface{}{ | |||||
"redirect": setting.AppSubURL + "/admin/hooks", | |||||
}) | |||||
} |
func Webhooks(ctx *context.Context) { | func Webhooks(ctx *context.Context) { | ||||
ctx.Data["Title"] = ctx.Tr("org.settings") | ctx.Data["Title"] = ctx.Tr("org.settings") | ||||
ctx.Data["PageIsSettingsHooks"] = true | ctx.Data["PageIsSettingsHooks"] = true | ||||
ctx.Data["BaseLink"] = ctx.Org.OrgLink | |||||
ctx.Data["BaseLink"] = ctx.Org.OrgLink + "/settings/hooks" | |||||
ctx.Data["Description"] = ctx.Tr("org.settings.hooks_desc") | ctx.Data["Description"] = ctx.Tr("org.settings.hooks_desc") | ||||
ws, err := models.GetWebhooksByOrgID(ctx.Org.Organization.ID) | ws, err := models.GetWebhooksByOrgID(ctx.Org.Organization.ID) |
"encoding/json" | "encoding/json" | ||||
"errors" | "errors" | ||||
"fmt" | "fmt" | ||||
"path" | |||||
"strings" | "strings" | ||||
"code.gitea.io/git" | "code.gitea.io/git" | ||||
) | ) | ||||
const ( | const ( | ||||
tplHooks base.TplName = "repo/settings/webhook/base" | |||||
tplHookNew base.TplName = "repo/settings/webhook/new" | |||||
tplOrgHookNew base.TplName = "org/settings/hook_new" | |||||
tplHooks base.TplName = "repo/settings/webhook/base" | |||||
tplHookNew base.TplName = "repo/settings/webhook/new" | |||||
tplOrgHookNew base.TplName = "org/settings/hook_new" | |||||
tplAdminHookNew base.TplName = "admin/hook_new" | |||||
) | ) | ||||
// Webhooks render web hooks list page | // Webhooks render web hooks list page | ||||
func Webhooks(ctx *context.Context) { | func Webhooks(ctx *context.Context) { | ||||
ctx.Data["Title"] = ctx.Tr("repo.settings.hooks") | ctx.Data["Title"] = ctx.Tr("repo.settings.hooks") | ||||
ctx.Data["PageIsSettingsHooks"] = true | ctx.Data["PageIsSettingsHooks"] = true | ||||
ctx.Data["BaseLink"] = ctx.Repo.RepoLink | |||||
ctx.Data["BaseLink"] = ctx.Repo.RepoLink + "/settings/hooks" | |||||
ctx.Data["Description"] = ctx.Tr("repo.settings.hooks_desc", "https://docs.gitea.io/en-us/webhooks/") | ctx.Data["Description"] = ctx.Tr("repo.settings.hooks_desc", "https://docs.gitea.io/en-us/webhooks/") | ||||
ws, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID) | ws, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID) | ||||
type orgRepoCtx struct { | type orgRepoCtx struct { | ||||
OrgID int64 | OrgID int64 | ||||
RepoID int64 | RepoID int64 | ||||
IsAdmin bool | |||||
Link string | Link string | ||||
NewTemplate base.TplName | NewTemplate base.TplName | ||||
} | } | ||||
// getOrgRepoCtx determines whether this is a repo context or organization context. | |||||
// getOrgRepoCtx determines whether this is a repo, organization, or admin context. | |||||
func getOrgRepoCtx(ctx *context.Context) (*orgRepoCtx, error) { | func getOrgRepoCtx(ctx *context.Context) (*orgRepoCtx, error) { | ||||
if len(ctx.Repo.RepoLink) > 0 { | if len(ctx.Repo.RepoLink) > 0 { | ||||
return &orgRepoCtx{ | return &orgRepoCtx{ | ||||
RepoID: ctx.Repo.Repository.ID, | RepoID: ctx.Repo.Repository.ID, | ||||
Link: ctx.Repo.RepoLink, | |||||
Link: path.Join(ctx.Repo.RepoLink, "settings/hooks"), | |||||
NewTemplate: tplHookNew, | NewTemplate: tplHookNew, | ||||
}, nil | }, nil | ||||
} | } | ||||
if len(ctx.Org.OrgLink) > 0 { | if len(ctx.Org.OrgLink) > 0 { | ||||
return &orgRepoCtx{ | return &orgRepoCtx{ | ||||
OrgID: ctx.Org.Organization.ID, | OrgID: ctx.Org.Organization.ID, | ||||
Link: ctx.Org.OrgLink, | |||||
Link: path.Join(ctx.Org.OrgLink, "settings/hooks"), | |||||
NewTemplate: tplOrgHookNew, | NewTemplate: tplOrgHookNew, | ||||
}, nil | }, nil | ||||
} | } | ||||
if ctx.User.IsAdmin { | |||||
return &orgRepoCtx{ | |||||
IsAdmin: true, | |||||
Link: path.Join(setting.AppSubURL, "/admin/hooks"), | |||||
NewTemplate: tplAdminHookNew, | |||||
}, nil | |||||
} | |||||
return nil, errors.New("Unable to set OrgRepo context") | return nil, errors.New("Unable to set OrgRepo context") | ||||
} | } | ||||
// WebhooksNew render creating webhook page | // WebhooksNew render creating webhook page | ||||
func WebhooksNew(ctx *context.Context) { | func WebhooksNew(ctx *context.Context) { | ||||
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook") | ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook") | ||||
ctx.Data["PageIsSettingsHooks"] = true | |||||
ctx.Data["PageIsSettingsHooksNew"] = true | |||||
ctx.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}} | ctx.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}} | ||||
orCtx, err := getOrgRepoCtx(ctx) | orCtx, err := getOrgRepoCtx(ctx) | ||||
return | return | ||||
} | } | ||||
if orCtx.IsAdmin { | |||||
ctx.Data["PageIsAdminHooks"] = true | |||||
ctx.Data["PageIsAdminHooksNew"] = true | |||||
} else { | |||||
ctx.Data["PageIsSettingsHooks"] = true | |||||
ctx.Data["PageIsSettingsHooksNew"] = true | |||||
} | |||||
hookType := checkHookType(ctx) | hookType := checkHookType(ctx) | ||||
ctx.Data["HookType"] = hookType | ctx.Data["HookType"] = hookType | ||||
if ctx.Written() { | if ctx.Written() { | ||||
} | } | ||||
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) | ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) | ||||
ctx.Redirect(orCtx.Link + "/settings/hooks") | |||||
ctx.Redirect(orCtx.Link) | |||||
} | } | ||||
// GogsHooksNewPost response for creating webhook | // GogsHooksNewPost response for creating webhook | ||||
} | } | ||||
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) | ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) | ||||
ctx.Redirect(orCtx.Link + "/settings/hooks") | |||||
ctx.Redirect(orCtx.Link) | |||||
} | } | ||||
// DiscordHooksNewPost response for creating discord hook | // DiscordHooksNewPost response for creating discord hook | ||||
} | } | ||||
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) | ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) | ||||
ctx.Redirect(orCtx.Link + "/settings/hooks") | |||||
ctx.Redirect(orCtx.Link) | |||||
} | } | ||||
// DingtalkHooksNewPost response for creating dingtalk hook | // DingtalkHooksNewPost response for creating dingtalk hook | ||||
} | } | ||||
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) | ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) | ||||
ctx.Redirect(orCtx.Link + "/settings/hooks") | |||||
ctx.Redirect(orCtx.Link) | |||||
} | } | ||||
// SlackHooksNewPost response for creating slack hook | // SlackHooksNewPost response for creating slack hook | ||||
} | } | ||||
ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) | ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) | ||||
ctx.Redirect(orCtx.Link + "/settings/hooks") | |||||
ctx.Redirect(orCtx.Link) | |||||
} | } | ||||
func checkWebhook(ctx *context.Context) (*orgRepoCtx, *models.Webhook) { | func checkWebhook(ctx *context.Context) (*orgRepoCtx, *models.Webhook) { | ||||
var w *models.Webhook | var w *models.Webhook | ||||
if orCtx.RepoID > 0 { | if orCtx.RepoID > 0 { | ||||
w, err = models.GetWebhookByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) | w, err = models.GetWebhookByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) | ||||
} else { | |||||
} else if orCtx.OrgID > 0 { | |||||
w, err = models.GetWebhookByOrgID(ctx.Org.Organization.ID, ctx.ParamsInt64(":id")) | w, err = models.GetWebhookByOrgID(ctx.Org.Organization.ID, ctx.ParamsInt64(":id")) | ||||
} else { | |||||
w, err = models.GetDefaultWebhook(ctx.ParamsInt64(":id")) | |||||
} | } | ||||
if err != nil { | if err != nil { | ||||
if models.IsErrWebhookNotExist(err) { | if models.IsErrWebhookNotExist(err) { | ||||
} | } | ||||
ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) | ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) | ||||
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID)) | |||||
ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID)) | |||||
} | } | ||||
// GogsHooksEditPost response for editing gogs hook | // GogsHooksEditPost response for editing gogs hook | ||||
} | } | ||||
ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) | ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) | ||||
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID)) | |||||
ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID)) | |||||
} | } | ||||
// SlackHooksEditPost response for editing slack hook | // SlackHooksEditPost response for editing slack hook | ||||
} | } | ||||
ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) | ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) | ||||
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID)) | |||||
ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID)) | |||||
} | } | ||||
// DiscordHooksEditPost response for editing discord hook | // DiscordHooksEditPost response for editing discord hook | ||||
} | } | ||||
ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) | ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) | ||||
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID)) | |||||
ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID)) | |||||
} | } | ||||
// DingtalkHooksEditPost response for editing discord hook | // DingtalkHooksEditPost response for editing discord hook | ||||
} | } | ||||
ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) | ctx.Flash.Success(ctx.Tr("repo.settings.update_hook_success")) | ||||
ctx.Redirect(fmt.Sprintf("%s/settings/hooks/%d", orCtx.Link, w.ID)) | |||||
ctx.Redirect(fmt.Sprintf("%s/%d", orCtx.Link, w.ID)) | |||||
} | } | ||||
// TestWebhook test if web hook is work fine | // TestWebhook test if web hook is work fine |
m.Post("/delete", admin.DeleteRepo) | m.Post("/delete", admin.DeleteRepo) | ||||
}) | }) | ||||
m.Group("/hooks", func() { | |||||
m.Get("", admin.DefaultWebhooks) | |||||
m.Post("/delete", admin.DeleteDefaultWebhook) | |||||
m.Get("/:type/new", repo.WebhooksNew) | |||||
m.Post("/gitea/new", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksNewPost) | |||||
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.Get("/:id", repo.WebHooksEdit) | |||||
m.Post("/gitea/:id", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost) | |||||
m.Post("/gogs/:id", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksEditPost) | |||||
m.Post("/slack/:id", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksEditPost) | |||||
m.Post("/discord/:id", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksEditPost) | |||||
m.Post("/dingtalk/:id", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksEditPost) | |||||
}) | |||||
m.Group("/auths", func() { | m.Group("/auths", func() { | ||||
m.Get("", admin.Authentications) | m.Get("", admin.Authentications) | ||||
m.Combo("/new").Get(admin.NewAuthSource).Post(bindIgnErr(auth.AuthenticationForm{}), admin.NewAuthSourcePost) | m.Combo("/new").Get(admin.NewAuthSource).Post(bindIgnErr(auth.AuthenticationForm{}), admin.NewAuthSourcePost) |
{{template "base/head" .}} | |||||
<div class="admin new webhook"> | |||||
{{template "admin/navbar" .}} | |||||
<div class="ui container"> | |||||
{{template "base/alert" .}} | |||||
<h4 class="ui top attached header"> | |||||
{{if .PageIsAdminHooksNew}} | |||||
{{.i18n.Tr "admin.hooks.add_webhook"}} | |||||
{{else}} | |||||
{{.i18n.Tr "admin.hooks.update_webhook"}} | |||||
{{end}} | |||||
<div class="ui right"> | |||||
{{if eq .HookType "gitea"}} | |||||
<img class="img-13" src="{{AppSubUrl}}/img/gitea-sm.png"> | |||||
{{else if eq .HookType "gogs"}} | |||||
<img class="img-13" src="{{AppSubUrl}}/img/gogs.ico"> | |||||
{{else if eq .HookType "slack"}} | |||||
<img class="img-13" src="{{AppSubUrl}}/img/slack.png"> | |||||
{{else if eq .HookType "discord"}} | |||||
<img class="img-13" src="{{AppSubUrl}}/img/discord.png"> | |||||
{{else if eq .HookType "dingtalk"}} | |||||
<img class="img-13" src="{{AppSubUrl}}/img/dingtalk.ico"> | |||||
{{end}} | |||||
</div> | |||||
</h4> | |||||
<div class="ui attached segment"> | |||||
{{template "repo/settings/webhook/gitea" .}} | |||||
{{template "repo/settings/webhook/gogs" .}} | |||||
{{template "repo/settings/webhook/slack" .}} | |||||
{{template "repo/settings/webhook/discord" .}} | |||||
{{template "repo/settings/webhook/dingtalk" .}} | |||||
</div> | |||||
{{template "repo/settings/webhook/history" .}} | |||||
</div> | |||||
</div> | |||||
{{template "base/footer" .}} |
{{template "base/head" .}} | |||||
<div class="admin hooks"> | |||||
{{template "admin/navbar" .}} | |||||
<div class="ui container"> | |||||
{{template "repo/settings/webhook/list" .}} | |||||
</div> | |||||
</div> | |||||
{{template "base/footer" .}} |
<li {{if .PageIsAdminUsers}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/users">{{.i18n.Tr "admin.users"}}</a></li> | <li {{if .PageIsAdminUsers}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/users">{{.i18n.Tr "admin.users"}}</a></li> | ||||
<li {{if .PageIsAdminOrganizations}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/orgs">{{.i18n.Tr "admin.organizations"}}</a></li> | <li {{if .PageIsAdminOrganizations}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/orgs">{{.i18n.Tr "admin.organizations"}}</a></li> | ||||
<li {{if .PageIsAdminRepositories}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/repos">{{.i18n.Tr "admin.repositories"}}</a></li> | <li {{if .PageIsAdminRepositories}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/repos">{{.i18n.Tr "admin.repositories"}}</a></li> | ||||
<li {{if .PageIsAdminHooks}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/hooks">{{.i18n.Tr "admin.hooks"}}</a></li> | |||||
<li {{if .PageIsAdminAuthentications}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/auths">{{.i18n.Tr "admin.authentication"}}</a></li> | <li {{if .PageIsAdminAuthentications}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/auths">{{.i18n.Tr "admin.authentication"}}</a></li> | ||||
<li {{if .PageIsAdminConfig}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/config">{{.i18n.Tr "admin.config"}}</a></li> | <li {{if .PageIsAdminConfig}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/config">{{.i18n.Tr "admin.config"}}</a></li> | ||||
<li {{if .PageIsAdminNotices}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/notices">{{.i18n.Tr "admin.notices"}}</a></li> | <li {{if .PageIsAdminNotices}}class="current"{{end}}><a href="{{AppSubUrl}}/admin/notices">{{.i18n.Tr "admin.notices"}}</a></li> |
<a class="{{if .PageIsAdminRepositories}}active{{end}} item" href="{{AppSubUrl}}/admin/repos"> | <a class="{{if .PageIsAdminRepositories}}active{{end}} item" href="{{AppSubUrl}}/admin/repos"> | ||||
{{.i18n.Tr "admin.repositories"}} | {{.i18n.Tr "admin.repositories"}} | ||||
</a> | </a> | ||||
<a class="{{if .PageIsAdminHooks}}active{{end}} item" href="{{AppSubUrl}}/admin/hooks"> | |||||
{{.i18n.Tr "admin.hooks"}} | |||||
</a> | |||||
<a class="{{if .PageIsAdminAuthentications}}active{{end}} item" href="{{AppSubUrl}}/admin/auths"> | <a class="{{if .PageIsAdminAuthentications}}active{{end}} item" href="{{AppSubUrl}}/admin/auths"> | ||||
{{.i18n.Tr "admin.authentication"}} | {{.i18n.Tr "admin.authentication"}} | ||||
</a> | </a> | ||||
<a class="{{if .PageIsAdminMonitor}}active{{end}} item" href="{{AppSubUrl}}/admin/monitor"> | <a class="{{if .PageIsAdminMonitor}}active{{end}} item" href="{{AppSubUrl}}/admin/monitor"> | ||||
{{.i18n.Tr "admin.monitor"}} | {{.i18n.Tr "admin.monitor"}} | ||||
</a> | </a> | ||||
</div> | |||||
</div> |
{{if eq .HookType "dingtalk"}} | {{if eq .HookType "dingtalk"}} | ||||
<p>{{.i18n.Tr "repo.settings.add_dingtalk_hook_desc" "https://dingtalk.com" | Str2html}}</p> | <p>{{.i18n.Tr "repo.settings.add_dingtalk_hook_desc" "https://dingtalk.com" | Str2html}}</p> | ||||
<form class="ui form" action="{{.BaseLink}}/settings/hooks/dingtalk/{{if .PageIsSettingsHooksNew}}new{{else}}{{.Webhook.ID}}{{end}}" method="post"> | |||||
<form class="ui form" action="{{.BaseLink}}/dingtalk/{{or .Webhook.ID "new"}}" method="post"> | |||||
{{.CsrfTokenHtml}} | {{.CsrfTokenHtml}} | ||||
<div class="required field {{if .Err_PayloadURL}}error{{end}}"> | <div class="required field {{if .Err_PayloadURL}}error{{end}}"> | ||||
<label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label> | <label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label> |
{{if eq .HookType "discord"}} | {{if eq .HookType "discord"}} | ||||
<p>{{.i18n.Tr "repo.settings.add_discord_hook_desc" "https://discordapp.com" | Str2html}}</p> | <p>{{.i18n.Tr "repo.settings.add_discord_hook_desc" "https://discordapp.com" | Str2html}}</p> | ||||
<form class="ui form" action="{{.BaseLink}}/settings/hooks/discord/{{if .PageIsSettingsHooksNew}}new{{else}}{{.Webhook.ID}}{{end}}" method="post"> | |||||
<form class="ui form" action="{{.BaseLink}}/discord/{{or .Webhook.ID "new"}}" method="post"> | |||||
{{.CsrfTokenHtml}} | {{.CsrfTokenHtml}} | ||||
<div class="required field {{if .Err_PayloadURL}}error{{end}}"> | <div class="required field {{if .Err_PayloadURL}}error{{end}}"> | ||||
<label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label> | <label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label> |
{{if eq .HookType "gitea"}} | {{if eq .HookType "gitea"}} | ||||
<p>{{.i18n.Tr "repo.settings.add_webhook_desc" "https://docs.gitea.io/en-us/webhooks/" | Str2html}}</p> | <p>{{.i18n.Tr "repo.settings.add_webhook_desc" "https://docs.gitea.io/en-us/webhooks/" | Str2html}}</p> | ||||
<form class="ui form" action="{{.BaseLink}}/settings/hooks/gitea/{{if .PageIsSettingsHooksNew}}new{{else}}{{.Webhook.ID}}{{end}}" method="post"> | |||||
<form class="ui form" action="{{.BaseLink}}/gitea/{{or .Webhook.ID "new"}}" method="post"> | |||||
{{.CsrfTokenHtml}} | {{.CsrfTokenHtml}} | ||||
<div class="required field {{if .Err_PayloadURL}}error{{end}}"> | <div class="required field {{if .Err_PayloadURL}}error{{end}}"> | ||||
<label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label> | <label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label> |
{{if eq .HookType "gogs"}} | {{if eq .HookType "gogs"}} | ||||
<p>{{.i18n.Tr "repo.settings.add_webhook_desc" "https://docs.gitea.io/en-us/webhooks/" | Str2html}}</p> | <p>{{.i18n.Tr "repo.settings.add_webhook_desc" "https://docs.gitea.io/en-us/webhooks/" | Str2html}}</p> | ||||
<form class="ui form" action="{{.BaseLink}}/settings/hooks/gogs/{{if .PageIsSettingsHooksNew}}new{{else}}{{.Webhook.ID}}{{end}}" method="post"> | |||||
<form class="ui form" action="{{.BaseLink}}/gogs/{{or .Webhook.ID "new"}}" method="post"> | |||||
{{.CsrfTokenHtml}} | {{.CsrfTokenHtml}} | ||||
<div class="required field {{if .Err_PayloadURL}}error{{end}}"> | <div class="required field {{if .Err_PayloadURL}}error{{end}}"> | ||||
<label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label> | <label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label> |
<div class="ui floating1 jump dropdown"> | <div class="ui floating1 jump dropdown"> | ||||
<div class="ui blue tiny button">{{.i18n.Tr "repo.settings.add_webhook"}}</div> | <div class="ui blue tiny button">{{.i18n.Tr "repo.settings.add_webhook"}}</div> | ||||
<div class="menu"> | <div class="menu"> | ||||
<a class="item" href="{{.BaseLink}}/settings/hooks/gitea/new"> | |||||
<a class="item" href="{{.BaseLink}}/gitea/new"> | |||||
<img class="img-10" src="{{AppSubUrl}}/img/gitea-sm.png">Gitea | <img class="img-10" src="{{AppSubUrl}}/img/gitea-sm.png">Gitea | ||||
</a> | </a> | ||||
<a class="item" href="{{.BaseLink}}/settings/hooks/gogs/new"> | |||||
<a class="item" href="{{.BaseLink}}/gogs/new"> | |||||
<img class="img-10" src="{{AppSubUrl}}/img/gogs.ico">Gogs | <img class="img-10" src="{{AppSubUrl}}/img/gogs.ico">Gogs | ||||
</a> | </a> | ||||
<a class="item" href="{{.BaseLink}}/settings/hooks/slack/new"> | |||||
<a class="item" href="{{.BaseLink}}/slack/new"> | |||||
<img class="img-10" src="{{AppSubUrl}}/img/slack.png">Slack | <img class="img-10" src="{{AppSubUrl}}/img/slack.png">Slack | ||||
</a> | </a> | ||||
<a class="item" href="{{.BaseLink}}/settings/hooks/discord/new"> | |||||
<a class="item" href="{{.BaseLink}}/discord/new"> | |||||
<img class="img-10" src="{{AppSubUrl}}/img/discord.png">Discord | <img class="img-10" src="{{AppSubUrl}}/img/discord.png">Discord | ||||
</a> | </a> | ||||
<a class="item" href="{{.BaseLink}}/settings/hooks/dingtalk/new"> | |||||
<a class="item" href="{{.BaseLink}}/dingtalk/new"> | |||||
<img class="img-10" src="{{AppSubUrl}}/img/dingtalk.ico">Dingtalk | <img class="img-10" src="{{AppSubUrl}}/img/dingtalk.ico">Dingtalk | ||||
</a> | </a> | ||||
</div> | </div> | ||||
{{else}} | {{else}} | ||||
<span class="text grey"><i class="octicon octicon-primitive-dot"></i></span> | <span class="text grey"><i class="octicon octicon-primitive-dot"></i></span> | ||||
{{end}} | {{end}} | ||||
<a class="dont-break-out" href="{{$.BaseLink}}/settings/hooks/{{.ID}}">{{.URL}}</a> | |||||
<a class="dont-break-out" href="{{$.BaseLink}}/{{.ID}}">{{.URL}}</a> | |||||
<div class="ui right"> | <div class="ui right"> | ||||
<span class="text blue"><a href="{{$.BaseLink}}/settings/hooks/{{.ID}}"><i class="fa fa-pencil"></i></a></span> | |||||
<span class="text blue"><a href="{{$.BaseLink}}/{{.ID}}"><i class="fa fa-pencil"></i></a></span> | |||||
<span class="text red"><a class="delete-button" data-url="{{$.Link}}/delete" data-id="{{.ID}}"><i class="fa fa-times"></i></a></span> | <span class="text red"><a class="delete-button" data-url="{{$.Link}}/delete" data-id="{{.ID}}"><i class="fa fa-times"></i></a></span> | ||||
</div> | </div> | ||||
</div> | </div> |
{{$isNew:=or .PageIsSettingsHooksNew .PageIsAdminHooksNew}} | |||||
<div class="field"> | <div class="field"> | ||||
<h4>{{.i18n.Tr "repo.settings.event_desc"}}</h4> | <h4>{{.i18n.Tr "repo.settings.event_desc"}}</h4> | ||||
<div class="grouped event type fields"> | <div class="grouped event type fields"> | ||||
<div class="field"> | <div class="field"> | ||||
<div class="ui radio non-events checkbox"> | <div class="ui radio non-events checkbox"> | ||||
<input class="hidden" name="events" type="radio" value="push_only" {{if or .PageIsSettingsHooksNew .Webhook.PushOnly}}checked{{end}}> | |||||
<input class="hidden" name="events" type="radio" value="push_only" {{if or $isNew .Webhook.PushOnly}}checked{{end}}> | |||||
<label>{{.i18n.Tr "repo.settings.event_push_only" | Str2html}}</label> | <label>{{.i18n.Tr "repo.settings.event_push_only" | Str2html}}</label> | ||||
</div> | </div> | ||||
</div> | </div> | ||||
<div class="inline field"> | <div class="inline field"> | ||||
<div class="ui checkbox"> | <div class="ui checkbox"> | ||||
<input class="hidden" name="active" type="checkbox" tabindex="0" {{if or .PageIsSettingsHooksNew .Webhook.IsActive}}checked{{end}}> | |||||
<input class="hidden" name="active" type="checkbox" tabindex="0" {{if or $isNew .Webhook.IsActive}}checked{{end}}> | |||||
<label>{{.i18n.Tr "repo.settings.active"}}</label> | <label>{{.i18n.Tr "repo.settings.active"}}</label> | ||||
<span class="help">{{.i18n.Tr "repo.settings.active_helper"}}</span> | <span class="help">{{.i18n.Tr "repo.settings.active_helper"}}</span> | ||||
</div> | </div> | ||||
</div> | </div> | ||||
<div class="field"> | <div class="field"> | ||||
{{if .PageIsSettingsHooksNew}} | |||||
{{if $isNew}} | |||||
<button class="ui green button">{{.i18n.Tr "repo.settings.add_webhook"}}</button> | <button class="ui green button">{{.i18n.Tr "repo.settings.add_webhook"}}</button> | ||||
{{else}} | {{else}} | ||||
<button class="ui green button">{{.i18n.Tr "repo.settings.update_webhook"}}</button> | <button class="ui green button">{{.i18n.Tr "repo.settings.update_webhook"}}</button> | ||||
<a class="ui red delete-button button" data-url="{{.BaseLink}}/settings/hooks/delete" data-id="{{.Webhook.ID}}">{{.i18n.Tr "repo.settings.delete_webhook"}}</a> | |||||
<a class="ui red delete-button button" data-url="{{.BaseLink}}/delete" data-id="{{.Webhook.ID}}">{{.i18n.Tr "repo.settings.delete_webhook"}}</a> | |||||
{{end}} | {{end}} | ||||
</div> | </div> | ||||
{{if eq .HookType "slack"}} | {{if eq .HookType "slack"}} | ||||
<p>{{.i18n.Tr "repo.settings.add_slack_hook_desc" "http://slack.com" | Str2html}}</p> | <p>{{.i18n.Tr "repo.settings.add_slack_hook_desc" "http://slack.com" | Str2html}}</p> | ||||
<form class="ui form" action="{{.BaseLink}}/settings/hooks/slack/{{if .PageIsSettingsHooksNew}}new{{else}}{{.Webhook.ID}}{{end}}" method="post"> | |||||
<form class="ui form" action="{{.BaseLink}}/slack/{{or .Webhook.ID "new"}}" method="post"> | |||||
{{.CsrfTokenHtml}} | {{.CsrfTokenHtml}} | ||||
<div class="required field {{if .Err_PayloadURL}}error{{end}}"> | <div class="required field {{if .Err_PayloadURL}}error{{end}}"> | ||||
<label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label> | <label for="payload_url">{{.i18n.Tr "repo.settings.payload_url"}}</label> |