mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 00:47:33 +00:00
feat(notification): new mail templates (#1579)
* fix: new template light only * add border radius to img * system first font, font weight * fix: change email template * fix: go mod * update ref * fix: template Co-authored-by: fabi <fabienne.gerschwiler@gmail.com>
This commit is contained in:
@@ -44,24 +44,10 @@ func (c *Commands) addDefaultMailTemplate(ctx context.Context, iamAgg *eventstor
|
||||
}
|
||||
|
||||
func (c *Commands) ChangeDefaultMailTemplate(ctx context.Context, policy *domain.MailTemplate) (*domain.MailTemplate, error) {
|
||||
if !policy.IsValid() {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "IAM-4m9ds", "Errors.IAM.MailTemplate.Invalid")
|
||||
}
|
||||
existingPolicy, err := c.defaultMailTemplateWriteModelByID(ctx)
|
||||
existingPolicy, changedEvent, err := c.changeDefaultMailTemplate(ctx, policy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "IAM-2N8fs", "Errors.IAM.MailTemplate.NotFound")
|
||||
}
|
||||
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.MailTemplateWriteModel.WriteModel)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, iamAgg, policy.Template)
|
||||
if !hasChanged {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-3nfsG", "Errors.IAM.MailTemplate.NotChanged")
|
||||
}
|
||||
|
||||
pushedEvents, err := c.eventstore.PushEvents(ctx, changedEvent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -73,6 +59,28 @@ func (c *Commands) ChangeDefaultMailTemplate(ctx context.Context, policy *domain
|
||||
return writeModelToMailTemplatePolicy(&existingPolicy.MailTemplateWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) changeDefaultMailTemplate(ctx context.Context, policy *domain.MailTemplate) (*IAMMailTemplateWriteModel, eventstore.EventPusher, error) {
|
||||
if !policy.IsValid() {
|
||||
return nil, nil, caos_errs.ThrowInvalidArgument(nil, "IAM-4m9ds", "Errors.IAM.MailTemplate.Invalid")
|
||||
}
|
||||
existingPolicy, err := c.defaultMailTemplateWriteModelByID(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if existingPolicy.State == domain.PolicyStateUnspecified || existingPolicy.State == domain.PolicyStateRemoved {
|
||||
return nil, nil, caos_errs.ThrowNotFound(nil, "IAM-2N8fs", "Errors.IAM.MailTemplate.NotFound")
|
||||
}
|
||||
|
||||
iamAgg := IAMAggregateFromWriteModel(&existingPolicy.MailTemplateWriteModel.WriteModel)
|
||||
changedEvent, hasChanged := existingPolicy.NewChangedEvent(ctx, iamAgg, policy.Template)
|
||||
if !hasChanged {
|
||||
return nil, nil, caos_errs.ThrowPreconditionFailed(nil, "IAM-3nfsG", "Errors.IAM.MailTemplate.NotChanged")
|
||||
}
|
||||
|
||||
return existingPolicy, changedEvent, nil
|
||||
}
|
||||
|
||||
func (c *Commands) defaultMailTemplateWriteModelByID(ctx context.Context) (policy *IAMMailTemplateWriteModel, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
32
internal/command/setup_step13.go
Normal file
32
internal/command/setup_step13.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/caos/logging"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
)
|
||||
|
||||
type Step13 struct {
|
||||
DefaultMailTemplate domain.MailTemplate
|
||||
}
|
||||
|
||||
func (s *Step13) Step() domain.Step {
|
||||
return domain.Step13
|
||||
}
|
||||
|
||||
func (s *Step13) execute(ctx context.Context, commandSide *Commands) error {
|
||||
return commandSide.SetupStep13(ctx, s)
|
||||
}
|
||||
|
||||
func (c *Commands) SetupStep13(ctx context.Context, step *Step13) error {
|
||||
fn := func(iam *IAMWriteModel) ([]eventstore.EventPusher, error) {
|
||||
_, mailTemplateEvent, err := c.changeDefaultMailTemplate(ctx, &step.DefaultMailTemplate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
logging.Log("SETUP-4insR").Info("default mail template/text set up")
|
||||
return []eventstore.EventPusher{mailTemplateEvent}, nil
|
||||
}
|
||||
return c.setup(ctx, step, fn)
|
||||
}
|
Reference in New Issue
Block a user