mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:17:32 +00:00
fix(notification): get origin from all relevant events and fix nil pointer (#6726)
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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)
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user