zitadel/internal/v2/command/policy_mail_text_model.go
Fabi fbc75d89b2
feat: mail tempaltes/texts and step 10 (#1266)
* feat: mail template/text events

* feat: mail template/text events

* feat: mail template/text on iam and org

* feat: setup step 10

* fix: add template event

* fix: add unique constraints

* Update internal/static/i18n/de.yaml

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* Update internal/static/i18n/de.yaml

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* Update internal/static/i18n/de.yaml

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* Update internal/static/i18n/de.yaml

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* Update internal/v2/command/iam_policy_mail_template.go

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* Update internal/v2/command/org_policy_mail_text.go

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* Update internal/v2/command/iam_policy_mail_template.go

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* Update internal/v2/command/iam_policy_mail_text.go

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* Update internal/v2/command/iam_policy_mail_text.go

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* Update internal/v2/command/org_policy_mail_template.go

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* Update internal/v2/command/org_policy_mail_template.go

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* Update internal/v2/command/org_policy_mail_text.go

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* fix: org iam policy

Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2021-02-10 10:48:40 +01:00

66 lines
1.4 KiB
Go

package command
import (
"github.com/caos/zitadel/internal/eventstore/v2"
"github.com/caos/zitadel/internal/v2/domain"
"github.com/caos/zitadel/internal/v2/repository/policy"
)
type MailTextWriteModel struct {
eventstore.WriteModel
MailTextType string
Language string
Title string
PreHeader string
Subject string
Greeting string
Text string
ButtonText string
State domain.PolicyState
}
func (wm *MailTextWriteModel) Reduce() error {
for _, event := range wm.Events {
switch e := event.(type) {
case *policy.MailTextAddedEvent:
if wm.MailTextType != e.MailTextType || wm.Language != e.Language {
continue
}
wm.Title = e.Title
wm.PreHeader = e.PreHeader
wm.Subject = e.Subject
wm.Greeting = e.Greeting
wm.Text = e.Text
wm.ButtonText = e.ButtonText
wm.State = domain.PolicyStateActive
case *policy.MailTextChangedEvent:
if wm.MailTextType != e.MailTextType || wm.Language != e.Language {
continue
}
if e.Title != nil {
wm.Title = *e.Title
}
if e.PreHeader != nil {
wm.PreHeader = *e.PreHeader
}
if e.Subject != nil {
wm.Subject = *e.Subject
}
if e.Greeting != nil {
wm.Greeting = *e.Greeting
}
if e.Text != nil {
wm.Text = *e.Text
}
if e.ButtonText != nil {
wm.ButtonText = *e.ButtonText
}
case *policy.MailTextRemovedEvent:
wm.State = domain.PolicyStateRemoved
}
}
return wm.WriteModel.Reduce()
}