1
0

feat(webhooks): register task and project events as webhook

This commit is contained in:
kolaente
2023-09-13 21:25:05 +02:00
parent ad7d485eb5
commit e5b8d8bd2d
3 changed files with 126 additions and 4 deletions

View File

@ -17,8 +17,10 @@
package models
import (
"code.vikunja.io/api/pkg/events"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"sync"
"time"
"xorm.io/xorm"
)
@ -46,6 +48,26 @@ func (w *Webhook) TableName() string {
return "webhooks"
}
type WebhookEvent interface {
events.Event
ProjectID() int64
}
var availableWebhookEvents map[string]bool
var availableWebhookEventsLock *sync.Mutex
func init() {
availableWebhookEvents = make(map[string]bool)
availableWebhookEventsLock = &sync.Mutex{}
}
func RegisterEventForWebhook(event WebhookEvent) {
availableWebhookEventsLock.Lock()
defer availableWebhookEventsLock.Unlock()
availableWebhookEvents[event.Name()] = true
}
func (w *Webhook) Create(s *xorm.Session, a web.Auth) (err error) {
// TODO: check valid webhook events
w.CreatedByID = a.GetID()