mirror of
https://github.com/zitadel/zitadel.git
synced 2025-11-14 13:33:20 +00:00
feat: e-mail templates (#1158)
* View definition added * Get templates and texts from the database. * Fill in texts in templates * Fill in texts in templates * Client API added * Weekly backup * Weekly backup * Daily backup * Weekly backup * Tests added * Corrections from merge branch * Fixes from pull request review
This commit is contained in:
@@ -1153,3 +1153,121 @@ func (es *OrgEventstore) RemovePasswordLockoutPolicy(ctx context.Context, policy
|
||||
addAggregate := PasswordLockoutPolicyRemovedAggregate(es.Eventstore.AggregateCreator(), repoOrg)
|
||||
return es_sdk.Push(ctx, es.PushAggregates, repoOrg.AppendEvents, addAggregate)
|
||||
}
|
||||
|
||||
func (es *OrgEventstore) AddMailTemplate(ctx context.Context, template *iam_model.MailTemplate) (*iam_model.MailTemplate, error) {
|
||||
if template == nil || !template.IsValid() {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-nb66d", "Errors.Org.MailTemplateInvalid")
|
||||
}
|
||||
org, err := es.OrgByID(ctx, org_model.NewOrg(template.AggregateID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
repoOrg := model.OrgFromModel(org)
|
||||
repoMailTemplate := iam_es_model.MailTemplateFromModel(template)
|
||||
|
||||
addAggregate := MailTemplateAddedAggregate(es.Eventstore.AggregateCreator(), repoOrg, repoMailTemplate)
|
||||
err = es_sdk.Push(ctx, es.PushAggregates, repoOrg.AppendEvents, addAggregate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return iam_es_model.MailTemplateToModel(repoOrg.MailTemplate), nil
|
||||
}
|
||||
|
||||
func (es *OrgEventstore) ChangeMailTemplate(ctx context.Context, template *iam_model.MailTemplate) (*iam_model.MailTemplate, error) {
|
||||
if template == nil || !template.IsValid() {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-FV2qE", "Errors.Org.MailTemplateInvalid")
|
||||
}
|
||||
org, err := es.OrgByID(ctx, org_model.NewOrg(template.AggregateID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
repoOrg := model.OrgFromModel(org)
|
||||
repoMailTemplate := iam_es_model.MailTemplateFromModel(template)
|
||||
|
||||
addAggregate := MailTemplateChangedAggregate(es.Eventstore.AggregateCreator(), repoOrg, repoMailTemplate)
|
||||
err = es_sdk.Push(ctx, es.PushAggregates, repoOrg.AppendEvents, addAggregate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
repoOrg.MailTemplate.Template = repoMailTemplate.Template
|
||||
return iam_es_model.MailTemplateToModel(repoOrg.MailTemplate), nil
|
||||
}
|
||||
|
||||
func (es *OrgEventstore) RemoveMailTemplate(ctx context.Context, template *iam_model.MailTemplate) error {
|
||||
if template == nil || !template.IsValid() {
|
||||
return errors.ThrowPreconditionFailed(nil, "EVENT-LulaW", "Errors.Org.MailTemplate.Invalid")
|
||||
}
|
||||
org, err := es.OrgByID(ctx, org_model.NewOrg(template.AggregateID))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
repoOrg := model.OrgFromModel(org)
|
||||
|
||||
addAggregate := MailTemplateRemovedAggregate(es.Eventstore.AggregateCreator(), repoOrg)
|
||||
return es_sdk.Push(ctx, es.PushAggregates, repoOrg.AppendEvents, addAggregate)
|
||||
}
|
||||
|
||||
func (es *OrgEventstore) AddMailText(ctx context.Context, mailtext *iam_model.MailText) (*iam_model.MailText, error) {
|
||||
if mailtext == nil || !mailtext.IsValid() {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-108Iz", "Errors.Org.MailTextInvalid")
|
||||
}
|
||||
org, err := es.OrgByID(ctx, org_model.NewOrg(mailtext.AggregateID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
repoOrg := model.OrgFromModel(org)
|
||||
repoMailText := iam_es_model.MailTextFromModel(mailtext)
|
||||
|
||||
addAggregate := MailTextAddedAggregate(es.Eventstore.AggregateCreator(), repoOrg, repoMailText)
|
||||
err = es_sdk.Push(ctx, es.PushAggregates, repoOrg.AppendEvents, addAggregate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, r := iam_es_model.GetMailText(repoOrg.MailTexts, repoMailText.MailTextType, repoMailText.Language); r != nil {
|
||||
return iam_es_model.MailTextToModel(r), nil
|
||||
}
|
||||
return nil, errors.ThrowInternal(nil, "EVENT-oc1GN", "Errors.Internal")
|
||||
}
|
||||
|
||||
func (es *OrgEventstore) ChangeMailText(ctx context.Context, mailtext *iam_model.MailText) (*iam_model.MailText, error) {
|
||||
if mailtext == nil || !mailtext.IsValid() {
|
||||
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-fdbqE", "Errors.Org.MailTextInvalid")
|
||||
}
|
||||
org, err := es.OrgByID(ctx, org_model.NewOrg(mailtext.AggregateID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
repoOrg := model.OrgFromModel(org)
|
||||
repoMailText := iam_es_model.MailTextFromModel(mailtext)
|
||||
|
||||
addAggregate := MailTextChangedAggregate(es.Eventstore.AggregateCreator(), repoOrg, repoMailText)
|
||||
err = es_sdk.Push(ctx, es.PushAggregates, repoOrg.AppendEvents, addAggregate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, r := iam_es_model.GetMailText(repoOrg.MailTexts, mailtext.MailTextType, mailtext.Language); r != nil {
|
||||
return iam_es_model.MailTextToModel(r), nil
|
||||
}
|
||||
return nil, errors.ThrowInternal(nil, "EVENT-F2whI", "Errors.Internal")
|
||||
}
|
||||
|
||||
func (es *OrgEventstore) RemoveMailText(ctx context.Context, mailtext *iam_model.MailText) error {
|
||||
if mailtext == nil || !mailtext.IsValid() {
|
||||
return errors.ThrowPreconditionFailed(nil, "EVENT-LulaW", "Errors.Org.MailText.Invalid")
|
||||
}
|
||||
org, err := es.OrgByID(ctx, org_model.NewOrg(mailtext.AggregateID))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
repoOrg := model.OrgFromModel(org)
|
||||
repoMailText := iam_es_model.MailTextFromModel(mailtext)
|
||||
|
||||
addAggregate := MailTextRemovedAggregate(es.Eventstore.AggregateCreator(), repoOrg, repoMailText)
|
||||
return es_sdk.Push(ctx, es.PushAggregates, repoOrg.AppendEvents, addAggregate)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user