mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
Fix webhook not triggered issue in SendWebhooks()
This commit is contained in:
parent
ec0a8e16f7
commit
52a66ef044
@ -93,12 +93,8 @@ func AddRecord(record *casvisorsdk.Record) bool {
|
|||||||
return affected
|
return affected
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendWebhooks(record *casvisorsdk.Record) error {
|
func getFilteredWebhooks(webhooks []*Webhook, action string) []*Webhook {
|
||||||
webhooks, err := getWebhooksByOrganization(record.Organization)
|
res := []*Webhook{}
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, webhook := range webhooks {
|
for _, webhook := range webhooks {
|
||||||
if !webhook.IsEnabled {
|
if !webhook.IsEnabled {
|
||||||
continue
|
continue
|
||||||
@ -106,28 +102,56 @@ func SendWebhooks(record *casvisorsdk.Record) error {
|
|||||||
|
|
||||||
matched := false
|
matched := false
|
||||||
for _, event := range webhook.Events {
|
for _, event := range webhook.Events {
|
||||||
if record.Action == event {
|
if action == event {
|
||||||
matched = true
|
matched = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if matched {
|
if matched {
|
||||||
|
res = append(res, webhook)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func SendWebhooks(record *casvisorsdk.Record) error {
|
||||||
|
webhooks, err := getWebhooksByOrganization(record.Organization)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
errs := []error{}
|
||||||
|
webhooks = getFilteredWebhooks(webhooks, record.Action)
|
||||||
|
for _, webhook := range webhooks {
|
||||||
var user *User
|
var user *User
|
||||||
if webhook.IsUserExtended {
|
if webhook.IsUserExtended {
|
||||||
user, err = getUser(record.Organization, record.User)
|
user, err = getUser(record.Organization, record.User)
|
||||||
|
if err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
user, err = GetMaskedUser(user, false, err)
|
user, err = GetMaskedUser(user, false, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
errs = append(errs, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = sendWebhook(webhook, record, user)
|
err = sendWebhook(webhook, record, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
errs = append(errs, err)
|
||||||
}
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(errs) > 0 {
|
||||||
|
errStrings := []string{}
|
||||||
|
for _, err := range errs {
|
||||||
|
errStrings = append(errStrings, err.Error())
|
||||||
|
}
|
||||||
|
return fmt.Errorf(strings.Join(errStrings, " | "))
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user