Add webhook.SingleOrgOnly

This commit is contained in:
Yang Luo
2024-03-04 21:14:52 +08:00
parent f9ee8a68cb
commit 19942a8bd4
27 changed files with 221 additions and 145 deletions

View File

@ -134,13 +134,19 @@ func GetRecordsByField(record *casvisorsdk.Record) ([]*casvisorsdk.Record, error
return records, nil
}
func getFilteredWebhooks(webhooks []*Webhook, action string) []*Webhook {
func getFilteredWebhooks(webhooks []*Webhook, organization string, action string) []*Webhook {
res := []*Webhook{}
for _, webhook := range webhooks {
if !webhook.IsEnabled {
continue
}
if webhook.SingleOrgOnly {
if webhook.Organization != organization {
continue
}
}
matched := false
for _, event := range webhook.Events {
if action == event {
@ -163,7 +169,7 @@ func SendWebhooks(record *casvisorsdk.Record) error {
}
errs := []error{}
webhooks = getFilteredWebhooks(webhooks, record.Action)
webhooks = getFilteredWebhooks(webhooks, record.Organization, record.Action)
for _, webhook := range webhooks {
var user *User
if webhook.IsUserExtended {

View File

@ -39,6 +39,7 @@ type Webhook struct {
Headers []*Header `xorm:"mediumtext" json:"headers"`
Events []string `xorm:"varchar(1000)" json:"events"`
IsUserExtended bool `json:"isUserExtended"`
SingleOrgOnly bool `json:"singleOrgOnly"`
IsEnabled bool `json:"isEnabled"`
}