From 7aef0ccfeedaebacbe0ae20fa771af15bb1c9be8 Mon Sep 17 00:00:00 2001 From: Livio Spring Date: Wed, 21 Sep 2022 16:18:55 +0200 Subject: [PATCH] fix(email): set correct logo url (#4426) --- cmd/start/start.go | 2 +- internal/api/assets/asset.go | 6 ++++++ internal/notification/projection.go | 23 ++++++++++++----------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/cmd/start/start.go b/cmd/start/start.go index cb12e2a635..9efeb90777 100644 --- a/cmd/start/start.go +++ b/cmd/start/start.go @@ -145,7 +145,7 @@ func startZitadel(config *Config, masterKey string) error { return fmt.Errorf("cannot start commands: %w", err) } - notification.Start(ctx, config.Projections.Customizations["notifications"], config.ExternalPort, config.ExternalSecure, commands, queries, eventstoreClient, assets.AssetAPI(config.ExternalSecure), config.SystemDefaults.Notifications.FileSystemPath, keys.User, keys.SMTP, keys.SMS) + notification.Start(ctx, config.Projections.Customizations["notifications"], config.ExternalPort, config.ExternalSecure, commands, queries, eventstoreClient, assets.AssetAPIFromDomain(config.ExternalSecure, config.ExternalPort), config.SystemDefaults.Notifications.FileSystemPath, keys.User, keys.SMTP, keys.SMS) router := mux.NewRouter() tlsConfig, err := config.TLS.Config() diff --git a/internal/api/assets/asset.go b/internal/api/assets/asset.go index c417230b24..8117ab6969 100644 --- a/internal/api/assets/asset.go +++ b/internal/api/assets/asset.go @@ -55,6 +55,12 @@ func AssetAPI(externalSecure bool) func(context.Context) string { } } +func AssetAPIFromDomain(externalSecure bool, externalPort uint16) func(context.Context) string { + return func(ctx context.Context) string { + return http_util.BuildHTTP(authz.GetInstance(ctx).RequestedDomain(), externalPort, externalSecure) + HandlerPrefix + } +} + type Uploader interface { UploadAsset(ctx context.Context, info string, asset *command.AssetUpload, commands *command.Commands) error ObjectName(data authz.CtxData) (string, error) diff --git a/internal/notification/projection.go b/internal/notification/projection.go index 17452e2d99..78fbfb3f06 100644 --- a/internal/notification/projection.go +++ b/internal/notification/projection.go @@ -178,7 +178,7 @@ func (p *notificationsProjection) reduceInitCodeAdded(event eventstore.Event) (* return nil, err } - origin, err := p.origin(ctx) + ctx, origin, err := p.origin(ctx) if err != nil { return nil, err } @@ -241,7 +241,7 @@ func (p *notificationsProjection) reduceEmailCodeAdded(event eventstore.Event) ( return nil, err } - origin, err := p.origin(ctx) + ctx, origin, err := p.origin(ctx) if err != nil { return nil, err } @@ -304,7 +304,7 @@ func (p *notificationsProjection) reducePasswordCodeAdded(event eventstore.Event return nil, err } - origin, err := p.origin(ctx) + ctx, origin, err := p.origin(ctx) if err != nil { return nil, err } @@ -375,7 +375,7 @@ func (p *notificationsProjection) reduceDomainClaimed(event eventstore.Event) (* return nil, err } - origin, err := p.origin(ctx) + ctx, origin, err := p.origin(ctx) if err != nil { return nil, err } @@ -436,7 +436,7 @@ func (p *notificationsProjection) reducePasswordlessCodeRequested(event eventsto return nil, err } - origin, err := p.origin(ctx) + ctx, origin, err := p.origin(ctx) if err != nil { return nil, err } @@ -494,7 +494,7 @@ func (p *notificationsProjection) reducePhoneCodeAdded(event eventstore.Event) ( return nil, err } - origin, err := p.origin(ctx) + ctx, origin, err := p.origin(ctx) if err != nil { return nil, err } @@ -640,21 +640,22 @@ func (p *notificationsProjection) getTranslatorWithOrgTexts(ctx context.Context, return translator, nil } -func (p *notificationsProjection) origin(ctx context.Context) (string, error) { +func (p *notificationsProjection) origin(ctx context.Context) (context.Context, string, error) { primary, err := query.NewInstanceDomainPrimarySearchQuery(true) if err != nil { - return "", err + return ctx, "", err } domains, err := p.queries.SearchInstanceDomains(ctx, &query.InstanceDomainSearchQueries{ Queries: []query.SearchQuery{primary}, }) if err != nil { - return "", err + return ctx, "", err } if len(domains.Domains) < 1 { - return "", errors.ThrowInternal(nil, "NOTIF-Ef3r1", "Errors.Notification.NoDomain") + return ctx, "", errors.ThrowInternal(nil, "NOTIF-Ef3r1", "Errors.Notification.NoDomain") } - return http_utils.BuildHTTP(domains.Domains[0].Domain, p.externalPort, p.externalSecure), nil + ctx = authz.WithRequestedDomain(ctx, domains.Domains[0].Domain) + return ctx, http_utils.BuildHTTP(domains.Domains[0].Domain, p.externalPort, p.externalSecure), nil } func setNotificationContext(event eventstore.Aggregate) context.Context {