mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:07:30 +00:00
feat: SMTP Templates (#6932)
* feat: smtp templates poc * feat: add isActive & ProviderType to SMTP backend * feat: change providertype to uint32 and fix tests * feat: minimal smtp provider component * feat: woking on diiferent providers * feat: keep working on providers * feat: initial stepper for new provider * fix: settings list and working on stepper * feat: step 1 and 2 form inputs * feat: starter for smtp test step * fix: misspelled SMPT * fix: remove tests for now * feat: add tls toggle remove old google provider * feat: working on add smtp and table * fix: duplicated identifiers * fix: settings list * fix: add missing smtp config properties * fix: add configID to smtp config table * fix: working on listproviders * feat: working in listSMTPConfigs * fix: add count to listsmtpconfigs * fix: getting empty results from listSMTPConfigs * feat: table now shows real data * fix: remaining styles for smtp-table * fix: remove old notification-smtp-provider-component * feat: delete smtp configuration * feat: deactivate smtp config * feat: replace isActive with state for smtp config * feat: activate smtp config * fix: remaining errors after main merge * fix: list smtp providers panic and material mdc * feat: refactor to only one provider component * feat: current provider details view * fix: refactor AddSMTPConfig and ChangeSMTPConfig * fix: smtp config reduce issue * fix: recover domain in NewIAMSMTPConfigWriteModel * fix: add code needed by SetUpInstance * fix: go tests and warn about passing context to InstanceAggregateFromWriteModel * fix: i18n and add missing trans for fr, it, zh * fix: add e2e tests * docs: add smtp templates * fix: remove provider_type, add description * fix: remaining error from merge main * fix: add @stebenz change for primary key * fix: inactive placed after removed to prevent deleted configs to show as inactive * fix: smtp provider id can be empty (migrated) * feat: add mailchimp transactional template * feat: add Brevo (Sendinblue) template * feat: change brevo logo, add color to tls icon * fix: queries use resourceowner, id must not be empty * fix: deal with old smtp settings and tests * fix: resourceOwner is the instanceID * fix: remove aggregate_id, rename SMTPConfigByAggregateID with SMTPConfigActive * fix: add tests for multiple configs with different IDs * fix: conflict * fix: remove notification-smtp-provider * fix: add @peintnermax suggestions, rename module and fix e2e tests * fix: remove material legacy modules * fix: remove ctx as parameter for InstanceAggregateFromWriteModel * fix: add Id to SMTPConfigToPb * fix: change InstanceAggregateFromWriteModel to avoid linter errors * fix import * rm unused package-lock * update yarn lock --------- Co-authored-by: Elio Bischof <elio@zitadel.com> Co-authored-by: Max Peintner <max@caos.ch> Co-authored-by: Stefan Benz <46600784+stebenz@users.noreply.github.com>
This commit is contained in:
@@ -14,6 +14,8 @@ func init() {
|
||||
eventstore.RegisterFilterEventMapper(AggregateType, SecretGeneratorRemovedEventType, SecretGeneratorRemovedEventMapper)
|
||||
eventstore.RegisterFilterEventMapper(AggregateType, SMTPConfigAddedEventType, SMTPConfigAddedEventMapper)
|
||||
eventstore.RegisterFilterEventMapper(AggregateType, SMTPConfigChangedEventType, SMTPConfigChangedEventMapper)
|
||||
eventstore.RegisterFilterEventMapper(AggregateType, SMTPConfigActivatedEventType, SMTPConfigActivatedEventMapper)
|
||||
eventstore.RegisterFilterEventMapper(AggregateType, SMTPConfigDeactivatedEventType, SMTPConfigDeactivatedEventMapper)
|
||||
eventstore.RegisterFilterEventMapper(AggregateType, SMTPConfigPasswordChangedEventType, SMTPConfigPasswordChangedEventMapper)
|
||||
eventstore.RegisterFilterEventMapper(AggregateType, SMTPConfigRemovedEventType, SMTPConfigRemovedEventMapper)
|
||||
eventstore.RegisterFilterEventMapper(AggregateType, SMSConfigTwilioAddedEventType, SMSConfigTwilioAddedEventMapper)
|
||||
|
@@ -4,6 +4,7 @@ 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"
|
||||
)
|
||||
@@ -14,23 +15,29 @@ const (
|
||||
SMTPConfigChangedEventType = instanceEventTypePrefix + smtpConfigPrefix + "changed"
|
||||
SMTPConfigPasswordChangedEventType = instanceEventTypePrefix + smtpConfigPrefix + "password.changed"
|
||||
SMTPConfigRemovedEventType = instanceEventTypePrefix + smtpConfigPrefix + "removed"
|
||||
SMTPConfigActivatedEventType = instanceEventTypePrefix + smtpConfigPrefix + "activated"
|
||||
SMTPConfigDeactivatedEventType = instanceEventTypePrefix + smtpConfigPrefix + "deactivated"
|
||||
)
|
||||
|
||||
type SMTPConfigAddedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
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"`
|
||||
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"`
|
||||
}
|
||||
|
||||
func NewSMTPConfigAddedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
id, description string,
|
||||
tls bool,
|
||||
senderAddress,
|
||||
senderName,
|
||||
@@ -45,6 +52,8 @@ func NewSMTPConfigAddedEvent(
|
||||
aggregate,
|
||||
SMTPConfigAddedEventType,
|
||||
),
|
||||
ID: id,
|
||||
Description: description,
|
||||
TLS: tls,
|
||||
SenderAddress: senderAddress,
|
||||
SenderName: senderName,
|
||||
@@ -77,13 +86,15 @@ func SMTPConfigAddedEventMapper(event eventstore.Event) (eventstore.Event, error
|
||||
|
||||
type SMTPConfigChangedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
FromAddress *string `json:"senderAddress,omitempty"`
|
||||
FromName *string `json:"senderName,omitempty"`
|
||||
ReplyToAddress *string `json:"replyToAddress,omitempty"`
|
||||
TLS *bool `json:"tls,omitempty"`
|
||||
Host *string `json:"host,omitempty"`
|
||||
User *string `json:"user,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
FromAddress *string `json:"senderAddress,omitempty"`
|
||||
FromName *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 (e *SMTPConfigChangedEvent) Payload() interface{} {
|
||||
@@ -97,6 +108,7 @@ func (e *SMTPConfigChangedEvent) UniqueConstraints() []*eventstore.UniqueConstra
|
||||
func NewSMTPConfigChangeEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
id string,
|
||||
changes []SMTPConfigChanges,
|
||||
) (*SMTPConfigChangedEvent, error) {
|
||||
if len(changes) == 0 {
|
||||
@@ -108,6 +120,7 @@ func NewSMTPConfigChangeEvent(
|
||||
aggregate,
|
||||
SMTPConfigChangedEventType,
|
||||
),
|
||||
ID: id,
|
||||
}
|
||||
for _, change := range changes {
|
||||
change(changeEvent)
|
||||
@@ -117,6 +130,18 @@ func NewSMTPConfigChangeEvent(
|
||||
|
||||
type SMTPConfigChanges func(event *SMTPConfigChangedEvent)
|
||||
|
||||
func ChangeSMTPConfigID(id string) func(event *SMTPConfigChangedEvent) {
|
||||
return func(e *SMTPConfigChangedEvent) {
|
||||
e.ID = id
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeSMTPConfigDescription(description string) func(event *SMTPConfigChangedEvent) {
|
||||
return func(e *SMTPConfigChangedEvent) {
|
||||
e.Description = &description
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeSMTPConfigTLS(tls bool) func(event *SMTPConfigChangedEvent) {
|
||||
return func(e *SMTPConfigChangedEvent) {
|
||||
e.TLS = &tls
|
||||
@@ -153,6 +178,12 @@ func ChangeSMTPConfigSMTPUser(smtpUser string) func(event *SMTPConfigChangedEven
|
||||
}
|
||||
}
|
||||
|
||||
func ChangeSMTPConfigSMTPPassword(password *crypto.CryptoValue) func(event *SMTPConfigChangedEvent) {
|
||||
return func(e *SMTPConfigChangedEvent) {
|
||||
e.Password = password
|
||||
}
|
||||
}
|
||||
|
||||
func SMTPConfigChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
e := &SMTPConfigChangedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
@@ -168,13 +199,14 @@ func SMTPConfigChangedEventMapper(event eventstore.Event) (eventstore.Event, err
|
||||
|
||||
type SMTPConfigPasswordChangedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
|
||||
Password *crypto.CryptoValue `json:"password,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
Password *crypto.CryptoValue `json:"password,omitempty"`
|
||||
}
|
||||
|
||||
func NewSMTPConfigPasswordChangedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
id string,
|
||||
password *crypto.CryptoValue,
|
||||
) *SMTPConfigPasswordChangedEvent {
|
||||
return &SMTPConfigPasswordChangedEvent{
|
||||
@@ -196,24 +228,106 @@ func (e *SMTPConfigPasswordChangedEvent) UniqueConstraints() []*eventstore.Uniqu
|
||||
}
|
||||
|
||||
func SMTPConfigPasswordChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
smtpConfigPasswordChagned := &SMTPConfigPasswordChangedEvent{
|
||||
smtpConfigPasswordChanged := &SMTPConfigPasswordChangedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
err := event.Unmarshal(smtpConfigPasswordChagned)
|
||||
err := event.Unmarshal(smtpConfigPasswordChanged)
|
||||
if err != nil {
|
||||
return nil, zerrors.ThrowInternal(err, "IAM-99iNF", "unable to unmarshal smtp config password changed")
|
||||
}
|
||||
|
||||
return smtpConfigPasswordChagned, nil
|
||||
return smtpConfigPasswordChanged, nil
|
||||
}
|
||||
|
||||
type SMTPConfigActivatedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
ID string `json:"id,omitempty"`
|
||||
}
|
||||
|
||||
func NewSMTPConfigActivatedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
id string,
|
||||
) *SMTPConfigActivatedEvent {
|
||||
return &SMTPConfigActivatedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
aggregate,
|
||||
SMTPConfigActivatedEventType,
|
||||
),
|
||||
ID: id,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *SMTPConfigActivatedEvent) Payload() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *SMTPConfigActivatedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
func SMTPConfigActivatedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
smtpConfigActivated := &SMTPConfigActivatedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
err := event.Unmarshal(smtpConfigActivated)
|
||||
if err != nil {
|
||||
return nil, zerrors.ThrowInternal(err, "IAM-KPr5t", "unable to unmarshal smtp config removed")
|
||||
}
|
||||
|
||||
return smtpConfigActivated, nil
|
||||
}
|
||||
|
||||
type SMTPConfigDeactivatedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
ID string `json:"id,omitempty"`
|
||||
}
|
||||
|
||||
func NewSMTPConfigDeactivatedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
id string,
|
||||
) *SMTPConfigDeactivatedEvent {
|
||||
return &SMTPConfigDeactivatedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
ctx,
|
||||
aggregate,
|
||||
SMTPConfigDeactivatedEventType,
|
||||
),
|
||||
ID: id,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *SMTPConfigDeactivatedEvent) Payload() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *SMTPConfigDeactivatedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
func SMTPConfigDeactivatedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
smtpConfigDeactivated := &SMTPConfigDeactivatedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
err := event.Unmarshal(smtpConfigDeactivated)
|
||||
if err != nil {
|
||||
return nil, zerrors.ThrowInternal(err, "IAM-KPr5t", "unable to unmarshal smtp config removed")
|
||||
}
|
||||
|
||||
return smtpConfigDeactivated, nil
|
||||
}
|
||||
|
||||
type SMTPConfigRemovedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
ID string `json:"id,omitempty"`
|
||||
}
|
||||
|
||||
func NewSMTPConfigRemovedEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
id string,
|
||||
) *SMTPConfigRemovedEvent {
|
||||
return &SMTPConfigRemovedEvent{
|
||||
BaseEvent: *eventstore.NewBaseEventForPush(
|
||||
@@ -221,6 +335,7 @@ func NewSMTPConfigRemovedEvent(
|
||||
aggregate,
|
||||
SMTPConfigRemovedEventType,
|
||||
),
|
||||
ID: id,
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user