func webhookUpdate(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	var webhook eventTypes.Webhook
	err := ParseInput(r, &webhook)
	if err != nil {
		return err
	}
	webhook.Name = r.URL.Query().Get(":name")
	ctx := permission.Context(permTypes.CtxTeam, webhook.TeamOwner)
	if !permission.Check(t, permission.PermWebhookUpdate, ctx) {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypeWebhook, Value: webhook.Name},
		Kind:       permission.PermWebhookUpdate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermWebhookReadEvents, ctx),
	})
	if err != nil {
		return err
	}
	defer func() {
		evt.Done(err)
	}()
	err = servicemanager.Webhook.Update(webhook)
	if err == eventTypes.ErrWebhookNotFound {
		w.WriteHeader(http.StatusNotFound)
	}
	return err
}
func webhookUpdate(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	var webhook eventTypes.Webhook
	err := ParseInput(r, &webhook)
	if err != nil {
		return err
	}
	webhook.Name = r.URL.Query().Get(":name")
	ctx := permission.Context(permTypes.CtxTeam, webhook.TeamOwner)
	if !permission.Check(t, permission.PermWebhookUpdate, ctx) {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypeWebhook, Value: webhook.Name},
		Kind:       permission.PermWebhookUpdate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermWebhookReadEvents, ctx),
	})
	if err != nil {
		return err
	}
	defer func() {
		evt.Done(err)
	}()
	err = servicemanager.Webhook.Update(webhook)
	if err == eventTypes.ErrWebhookNotFound {
		w.WriteHeader(http.StatusNotFound)
	}
	return err
}
// title: webhook update
// path: /events/webhooks/{name}
// method: PUT
// responses:
//   200: Webhook updated
//   401: Unauthorized
//   400: Invalid webhook
//   404: Webhook not found