mirror of
https://github.com/zitadel/zitadel.git
synced 2025-01-11 14:43:40 +00:00
fix(notification): get origin from all relevant events and fix nil pointer (#6726)
This commit is contained in:
parent
0af1c65c4c
commit
ce719a3fa4
@ -2,9 +2,10 @@ package handlers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
"github.com/zitadel/logging"
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/internal/api/authz"
|
"github.com/zitadel/zitadel/internal/api/authz"
|
||||||
http_utils "github.com/zitadel/zitadel/internal/api/http"
|
http_utils "github.com/zitadel/zitadel/internal/api/http"
|
||||||
"github.com/zitadel/zitadel/internal/errors"
|
"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) {
|
func (n *NotificationQueries) Origin(ctx context.Context, e eventstore.Event) (context.Context, error) {
|
||||||
|
var origin string
|
||||||
originEvent, ok := e.(OriginEvent)
|
originEvent, ok := e.(OriginEvent)
|
||||||
if !ok {
|
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 != "" {
|
if origin != "" {
|
||||||
originURL, err := url.Parse(origin)
|
originURL, err := url.Parse(origin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -33,7 +33,7 @@ func generateEmail(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if emailChannels.Len() == 0 {
|
if emailChannels == nil || emailChannels.Len() == 0 {
|
||||||
return errors.ThrowPreconditionFailed(nil, "MAIL-83nof", "Errors.Notification.Channels.NotPresent")
|
return errors.ThrowPreconditionFailed(nil, "MAIL-83nof", "Errors.Notification.Channels.NotPresent")
|
||||||
}
|
}
|
||||||
return emailChannels.HandleMessage(message)
|
return emailChannels.HandleMessage(message)
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/zitadel/logging"
|
"github.com/zitadel/logging"
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/internal/errors"
|
"github.com/zitadel/zitadel/internal/errors"
|
||||||
"github.com/zitadel/zitadel/internal/eventstore"
|
"github.com/zitadel/zitadel/internal/eventstore"
|
||||||
"github.com/zitadel/zitadel/internal/notification/messages"
|
"github.com/zitadel/zitadel/internal/notification/messages"
|
||||||
@ -21,7 +22,7 @@ func generateSms(
|
|||||||
number := ""
|
number := ""
|
||||||
smsChannels, twilioConfig, err := channels.SMS(ctx)
|
smsChannels, twilioConfig, err := channels.SMS(ctx)
|
||||||
logging.OnError(err).Error("could not create sms channel")
|
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")
|
return errors.ThrowPreconditionFailed(nil, "PHONE-w8nfow", "Errors.Notification.Channels.NotPresent")
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -312,9 +312,10 @@ func NewTOTPCheckedEvent(
|
|||||||
type OTPSMSChallengedEvent struct {
|
type OTPSMSChallengedEvent struct {
|
||||||
eventstore.BaseEvent `json:"-"`
|
eventstore.BaseEvent `json:"-"`
|
||||||
|
|
||||||
Code *crypto.CryptoValue `json:"code"`
|
Code *crypto.CryptoValue `json:"code"`
|
||||||
Expiry time.Duration `json:"expiry"`
|
Expiry time.Duration `json:"expiry"`
|
||||||
CodeReturned bool `json:"codeReturned,omitempty"`
|
CodeReturned bool `json:"codeReturned,omitempty"`
|
||||||
|
TriggeredAtOrigin string `json:"triggerOrigin,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *OTPSMSChallengedEvent) Data() interface{} {
|
func (e *OTPSMSChallengedEvent) Data() interface{} {
|
||||||
@ -329,6 +330,10 @@ func (e *OTPSMSChallengedEvent) SetBaseEvent(base *eventstore.BaseEvent) {
|
|||||||
e.BaseEvent = *base
|
e.BaseEvent = *base
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *OTPSMSChallengedEvent) TriggerOrigin() string {
|
||||||
|
return e.TriggeredAtOrigin
|
||||||
|
}
|
||||||
|
|
||||||
func NewOTPSMSChallengedEvent(
|
func NewOTPSMSChallengedEvent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
aggregate *eventstore.Aggregate,
|
aggregate *eventstore.Aggregate,
|
||||||
@ -342,9 +347,10 @@ func NewOTPSMSChallengedEvent(
|
|||||||
aggregate,
|
aggregate,
|
||||||
OTPSMSChallengedType,
|
OTPSMSChallengedType,
|
||||||
),
|
),
|
||||||
Code: code,
|
Code: code,
|
||||||
Expiry: expiry,
|
Expiry: expiry,
|
||||||
CodeReturned: codeReturned,
|
CodeReturned: codeReturned,
|
||||||
|
TriggeredAtOrigin: http.ComposedOrigin(ctx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/zitadel/zitadel/internal/api/http"
|
||||||
"github.com/zitadel/zitadel/internal/eventstore"
|
"github.com/zitadel/zitadel/internal/eventstore"
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/internal/crypto"
|
"github.com/zitadel/zitadel/internal/crypto"
|
||||||
@ -279,8 +280,9 @@ func NewHumanOTPSMSRemovedEvent(
|
|||||||
type HumanOTPSMSCodeAddedEvent struct {
|
type HumanOTPSMSCodeAddedEvent struct {
|
||||||
eventstore.BaseEvent `json:"-"`
|
eventstore.BaseEvent `json:"-"`
|
||||||
|
|
||||||
Code *crypto.CryptoValue `json:"code,omitempty"`
|
Code *crypto.CryptoValue `json:"code,omitempty"`
|
||||||
Expiry time.Duration `json:"expiry,omitempty"`
|
Expiry time.Duration `json:"expiry,omitempty"`
|
||||||
|
TriggeredAtOrigin string `json:"triggerOrigin,omitempty"`
|
||||||
*AuthRequestInfo
|
*AuthRequestInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,6 +298,10 @@ func (e *HumanOTPSMSCodeAddedEvent) SetBaseEvent(event *eventstore.BaseEvent) {
|
|||||||
e.BaseEvent = *event
|
e.BaseEvent = *event
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *HumanOTPSMSCodeAddedEvent) TriggerOrigin() string {
|
||||||
|
return e.TriggeredAtOrigin
|
||||||
|
}
|
||||||
|
|
||||||
func NewHumanOTPSMSCodeAddedEvent(
|
func NewHumanOTPSMSCodeAddedEvent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
aggregate *eventstore.Aggregate,
|
aggregate *eventstore.Aggregate,
|
||||||
@ -309,9 +315,10 @@ func NewHumanOTPSMSCodeAddedEvent(
|
|||||||
aggregate,
|
aggregate,
|
||||||
HumanOTPSMSCodeAddedType,
|
HumanOTPSMSCodeAddedType,
|
||||||
),
|
),
|
||||||
Code: code,
|
Code: code,
|
||||||
Expiry: expiry,
|
Expiry: expiry,
|
||||||
AuthRequestInfo: info,
|
TriggeredAtOrigin: http.ComposedOrigin(ctx),
|
||||||
|
AuthRequestInfo: info,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -473,8 +480,9 @@ func NewHumanOTPEmailRemovedEvent(
|
|||||||
type HumanOTPEmailCodeAddedEvent struct {
|
type HumanOTPEmailCodeAddedEvent struct {
|
||||||
eventstore.BaseEvent `json:"-"`
|
eventstore.BaseEvent `json:"-"`
|
||||||
|
|
||||||
Code *crypto.CryptoValue `json:"code,omitempty"`
|
Code *crypto.CryptoValue `json:"code,omitempty"`
|
||||||
Expiry time.Duration `json:"expiry,omitempty"`
|
Expiry time.Duration `json:"expiry,omitempty"`
|
||||||
|
TriggeredAtOrigin string `json:"triggerOrigin,omitempty"`
|
||||||
*AuthRequestInfo
|
*AuthRequestInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -490,6 +498,10 @@ func (e *HumanOTPEmailCodeAddedEvent) SetBaseEvent(event *eventstore.BaseEvent)
|
|||||||
e.BaseEvent = *event
|
e.BaseEvent = *event
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *HumanOTPEmailCodeAddedEvent) TriggerOrigin() string {
|
||||||
|
return e.TriggeredAtOrigin
|
||||||
|
}
|
||||||
|
|
||||||
func NewHumanOTPEmailCodeAddedEvent(
|
func NewHumanOTPEmailCodeAddedEvent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
aggregate *eventstore.Aggregate,
|
aggregate *eventstore.Aggregate,
|
||||||
@ -503,9 +515,10 @@ func NewHumanOTPEmailCodeAddedEvent(
|
|||||||
aggregate,
|
aggregate,
|
||||||
HumanOTPEmailCodeAddedType,
|
HumanOTPEmailCodeAddedType,
|
||||||
),
|
),
|
||||||
Code: code,
|
Code: code,
|
||||||
Expiry: expiry,
|
Expiry: expiry,
|
||||||
AuthRequestInfo: info,
|
AuthRequestInfo: info,
|
||||||
|
TriggeredAtOrigin: http.ComposedOrigin(ctx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/zitadel/zitadel/internal/api/http"
|
||||||
"github.com/zitadel/zitadel/internal/crypto"
|
"github.com/zitadel/zitadel/internal/crypto"
|
||||||
"github.com/zitadel/zitadel/internal/domain"
|
"github.com/zitadel/zitadel/internal/domain"
|
||||||
"github.com/zitadel/zitadel/internal/errors"
|
"github.com/zitadel/zitadel/internal/errors"
|
||||||
@ -149,9 +150,10 @@ func HumanPhoneVerificationFailedEventMapper(event *repository.Event) (eventstor
|
|||||||
type HumanPhoneCodeAddedEvent struct {
|
type HumanPhoneCodeAddedEvent struct {
|
||||||
eventstore.BaseEvent `json:"-"`
|
eventstore.BaseEvent `json:"-"`
|
||||||
|
|
||||||
Code *crypto.CryptoValue `json:"code,omitempty"`
|
Code *crypto.CryptoValue `json:"code,omitempty"`
|
||||||
Expiry time.Duration `json:"expiry,omitempty"`
|
Expiry time.Duration `json:"expiry,omitempty"`
|
||||||
CodeReturned bool `json:"code_returned,omitempty"`
|
CodeReturned bool `json:"code_returned,omitempty"`
|
||||||
|
TriggeredAtOrigin string `json:"triggerOrigin,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *HumanPhoneCodeAddedEvent) Data() interface{} {
|
func (e *HumanPhoneCodeAddedEvent) Data() interface{} {
|
||||||
@ -162,6 +164,10 @@ func (e *HumanPhoneCodeAddedEvent) UniqueConstraints() []*eventstore.EventUnique
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *HumanPhoneCodeAddedEvent) TriggerOrigin() string {
|
||||||
|
return e.TriggeredAtOrigin
|
||||||
|
}
|
||||||
|
|
||||||
func NewHumanPhoneCodeAddedEvent(
|
func NewHumanPhoneCodeAddedEvent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
aggregate *eventstore.Aggregate,
|
aggregate *eventstore.Aggregate,
|
||||||
@ -183,9 +189,10 @@ func NewHumanPhoneCodeAddedEventV2(
|
|||||||
aggregate,
|
aggregate,
|
||||||
HumanPhoneCodeAddedType,
|
HumanPhoneCodeAddedType,
|
||||||
),
|
),
|
||||||
Code: code,
|
Code: code,
|
||||||
Expiry: expiry,
|
Expiry: expiry,
|
||||||
CodeReturned: codeReturned,
|
CodeReturned: codeReturned,
|
||||||
|
TriggeredAtOrigin: http.ComposedOrigin(ctx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user