feat(webhooks): add setting to enable webhooks

This commit is contained in:
kolaente 2023-10-17 19:03:11 +02:00
parent 8cc775ac4c
commit 34a92b759e
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 21 additions and 9 deletions

View File

@ -172,6 +172,9 @@ const (
DefaultSettingsLanguage Key = `defaultsettings.language`
DefaultSettingsTimezone Key = `defaultsettings.timezone`
DefaultSettingsOverdueTaskRemindersTime Key = `defaultsettings.overdue_tasks_reminders_time`
WebhooksEnabled Key = `webhooks.enabled`
WebhooksTimeoutSeconds Key = `webhooks.timeoutseconds`
)
// GetString returns a string config value
@ -387,6 +390,8 @@ func InitDefaultConfig() {
DefaultSettingsAvatarProvider.setDefault("initials")
DefaultSettingsOverdueTaskRemindersEnabled.setDefault(true)
DefaultSettingsOverdueTaskRemindersTime.setDefault("9:00")
// Webhook
WebhooksEnabled.setDefault(true)
}
// InitConfig initializes the config, sets defaults etc.

View File

@ -18,6 +18,7 @@ package models
import (
"bytes"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/events"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/user"
@ -67,6 +68,10 @@ func init() {
}
func RegisterEventForWebhook(event events.Event) {
if !config.WebhooksEnabled.GetBool() {
return
}
availableWebhookEventsLock.Lock()
defer availableWebhookEventsLock.Unlock()

View File

@ -576,16 +576,18 @@ func registerAPIRoutes(a *echo.Group) {
a.DELETE("/tokens/:token", apiTokenProvider.DeleteWeb)
// Webhooks
webhookProvider := &handler.WebHandler{
EmptyStruct: func() handler.CObject {
return &models.Webhook{}
},
if config.WebhooksEnabled.GetBool() {
webhookProvider := &handler.WebHandler{
EmptyStruct: func() handler.CObject {
return &models.Webhook{}
},
}
a.GET("/projects/:project/webhooks", webhookProvider.ReadAllWeb)
a.PUT("/projects/:project/webhooks", webhookProvider.CreateWeb)
a.DELETE("/projects/:project/webhooks/:webhook", webhookProvider.DeleteWeb)
a.POST("/projects/:project/webhooks/:webhook", webhookProvider.UpdateWeb)
a.GET("/webhooks/events", apiv1.GetAvailableWebhookEvents)
}
a.GET("/projects/:project/webhooks", webhookProvider.ReadAllWeb)
a.PUT("/projects/:project/webhooks", webhookProvider.CreateWeb)
a.DELETE("/projects/:project/webhooks/:webhook", webhookProvider.DeleteWeb)
a.POST("/projects/:project/webhooks/:webhook", webhookProvider.UpdateWeb)
a.GET("/webhooks/events", apiv1.GetAvailableWebhookEvents)
}
func registerMigrations(m *echo.Group) {