Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System-wide webhooks #10546

Merged
merged 19 commits into from
Mar 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix deleting admin webhooks and rename method
  • Loading branch information
jamesorlakin committed Mar 1, 2020
commit 1fa71fa3cf12035fd1bf1834f61a272b4f5687ff
6 changes: 3 additions & 3 deletions models/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,16 +412,16 @@ func DeleteWebhookByOrgID(orgID, id int64) error {
})
}

// DeleteDefaultWebhook deletes an admin-default webhook by given ID.
func DeleteDefaultWebhook(id int64) error {
// DeleteDefaultSystemWebhook deletes an admin-configured default or system webhook (where Org and Repo ID both 0)
func DeleteDefaultSystemWebhook(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=? AND is_system_webhook=?", 0, 0, false).
Where("repo_id=? AND org_id=?", 0, 0).
Delete(&Webhook{ID: id})
if err != nil {
return err
Expand Down
23 changes: 15 additions & 8 deletions routers/admin/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const (
tplAdminHooks base.TplName = "admin/hooks"
)

// DefaultAndSystemWebhooks renders both admin default and system webhook list pages
func DefaultAndSystemWebhooks(ctx *context.Context) {
// DefaultOrSystemWebhooks renders both admin default and system webhook list pages
func DefaultOrSystemWebhooks(ctx *context.Context) {
var ws []*models.Webhook
var err error

Expand Down Expand Up @@ -45,15 +45,22 @@ func DefaultAndSystemWebhooks(ctx *context.Context) {
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 {
// 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 {
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",
})
// 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",
})
}
}
4 changes: 2 additions & 2 deletions routers/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ func RegisterRoutes(m *macaron.Macaron) {
})

m.Group("/^:configType(hooks|system-hooks)$", func() {
m.Get("", admin.DefaultAndSystemWebhooks)
m.Post("/delete", admin.DeleteDefaultWebhook)
m.Get("", admin.DefaultOrSystemWebhooks)
m.Post("/delete", admin.DeleteDefaultOrSystemWebhook)
m.Get("/:type/new", repo.WebhooksNew)
m.Post("/gitea/new", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksNewPost)
m.Post("/gogs/new", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksNewPost)
Expand Down