fix(notification): get origin from all relevant events and fix nil pointer (#6726)

This commit is contained in:
Livio Spring
2023-10-13 17:45:38 +03:00
committed by adlerhurst
parent 46187f7619
commit 426c4acbfe
6 changed files with 57 additions and 27 deletions

View File

@@ -2,9 +2,10 @@ package handlers
import (
"context"
"fmt"
"net/url"
"github.com/zitadel/logging"
"github.com/zitadel/zitadel/internal/api/authz"
http_utils "github.com/zitadel/zitadel/internal/api/http"
"github.com/zitadel/zitadel/internal/errors"
@@ -18,11 +19,13 @@ type OriginEvent interface {
}
func (n *NotificationQueries) Origin(ctx context.Context, e eventstore.Event) (context.Context, error) {
var origin string
originEvent, ok := e.(OriginEvent)
if !ok {
return ctx, errors.ThrowInternal(fmt.Errorf("event of type %T doesn't implement OriginEvent", e), "NOTIF-3m9fs", "Errors.Internal")
logging.Errorf("event of type %T doesn't implement OriginEvent", e)
} else {
origin = originEvent.TriggerOrigin()
}
origin := originEvent.TriggerOrigin()
if origin != "" {
originURL, err := url.Parse(origin)
if err != nil {

View File

@@ -33,7 +33,7 @@ func generateEmail(
if err != nil {
return err
}
if emailChannels.Len() == 0 {
if emailChannels == nil || emailChannels.Len() == 0 {
return errors.ThrowPreconditionFailed(nil, "MAIL-83nof", "Errors.Notification.Channels.NotPresent")
}
return emailChannels.HandleMessage(message)

View File

@@ -4,6 +4,7 @@ import (
"context"
"github.com/zitadel/logging"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/notification/messages"
@@ -21,7 +22,7 @@ func generateSms(
number := ""
smsChannels, twilioConfig, err := channels.SMS(ctx)
logging.OnError(err).Error("could not create sms channel")
if smsChannels.Len() == 0 {
if smsChannels == nil || smsChannels.Len() == 0 {
return errors.ThrowPreconditionFailed(nil, "PHONE-w8nfow", "Errors.Notification.Channels.NotPresent")
}
if err == nil {