From f3abbad1330f3c689c3d510a701e1573117ef682 Mon Sep 17 00:00:00 2001 From: Elio Bischof Date: Tue, 7 May 2024 18:24:53 +0200 Subject: [PATCH] fix(smtp): enable default instance config (#7925) * fix(smtp): enable default instance config * fix(smtp): enable default instance config * improve method signature --- internal/command/instance.go | 2 +- internal/command/smtp.go | 7 ++++++- internal/repository/instance/smtp_config.go | 20 +++++++++----------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/internal/command/instance.go b/internal/command/instance.go index 4bd3194706..a31c00aadf 100644 --- a/internal/command/instance.go +++ b/internal/command/instance.go @@ -389,7 +389,7 @@ func setupSMTPSettings(commands *Commands, validations *[]preparation.Validation return } *validations = append(*validations, - commands.prepareAddSMTPConfig( + commands.prepareAddAndActivateSMTPConfig( instanceAgg, smtpConfig.Description, smtpConfig.From, diff --git a/internal/command/smtp.go b/internal/command/smtp.go index fc51cabd59..87c8acb4f1 100644 --- a/internal/command/smtp.go +++ b/internal/command/smtp.go @@ -306,7 +306,7 @@ func (c *Commands) getSMTPConfig(ctx context.Context, instanceID, id, domain str } // TODO: SetUpInstance still uses this and would be removed as soon as deprecated PrepareCommands is removed -func (c *Commands) prepareAddSMTPConfig(a *instance.Aggregate, description, from, name, replyTo, hostAndPort, user string, password []byte, tls bool) preparation.Validation { +func (c *Commands) prepareAddAndActivateSMTPConfig(a *instance.Aggregate, description, from, name, replyTo, hostAndPort, user string, password []byte, tls bool) preparation.Validation { return func() (preparation.CreateCommands, error) { if from = strings.TrimSpace(from); from == "" { return nil, zerrors.ThrowInvalidArgument(nil, "INST-mruNY", "Errors.Invalid.Argument") @@ -358,6 +358,11 @@ func (c *Commands) prepareAddSMTPConfig(a *instance.Aggregate, description, from user, smtpPassword, ), + instance.NewSMTPConfigActivatedEvent( + ctx, + &a.Aggregate, + id, + ), }, nil }, nil } diff --git a/internal/repository/instance/smtp_config.go b/internal/repository/instance/smtp_config.go index 907375160b..3f08fc8e8a 100644 --- a/internal/repository/instance/smtp_config.go +++ b/internal/repository/instance/smtp_config.go @@ -4,7 +4,6 @@ import ( "context" "github.com/zitadel/zitadel/internal/crypto" - "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/eventstore" "github.com/zitadel/zitadel/internal/zerrors" ) @@ -22,16 +21,15 @@ const ( type SMTPConfigAddedEvent struct { eventstore.BaseEvent `json:"-"` - ID string `json:"id,omitempty"` - Description string `json:"description,omitempty"` - SenderAddress string `json:"senderAddress,omitempty"` - SenderName string `json:"senderName,omitempty"` - ReplyToAddress string `json:"replyToAddress,omitempty"` - TLS bool `json:"tls,omitempty"` - Host string `json:"host,omitempty"` - User string `json:"user,omitempty"` - Password *crypto.CryptoValue `json:"password,omitempty"` - State domain.SMTPConfigState `json:"state,omitempty"` + ID string `json:"id,omitempty"` + Description string `json:"description,omitempty"` + SenderAddress string `json:"senderAddress,omitempty"` + SenderName string `json:"senderName,omitempty"` + ReplyToAddress string `json:"replyToAddress,omitempty"` + TLS bool `json:"tls,omitempty"` + Host string `json:"host,omitempty"` + User string `json:"user,omitempty"` + Password *crypto.CryptoValue `json:"password,omitempty"` } func NewSMTPConfigAddedEvent(