mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-24 16:47:47 +00:00
bdf3887f9e
* feat: default custom message text * feat: org custom message text * feat: org custom message text * feat: custom messages query side * feat: default messages * feat: message text user fields * feat: check for inactive user * feat: fix send password reset * feat: fix custom org text * feat: add variables to docs * feat: custom text tests * feat: fix notifications * feat: add custom text feature * feat: add custom text feature * feat: feature in custom message texts * feat: add custom text feature in frontend * feat: merge main * feat: feature tests * feat: change phone message in setup * fix: remove unused code, add event translation * fix: merge main and fix problems * fix: english translation file * fix: migration versions * fix: setup * feat: fix pr requests * feat: fix phone code message * feat: migration * feat: setup * fix: remove unused tests Co-authored-by: Livio Amstutz <livio.a@gmail.com>
120 lines
2.9 KiB
Go
120 lines
2.9 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/caos/zitadel/internal/errors"
|
|
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
|
iam_model "github.com/caos/zitadel/internal/iam/model"
|
|
)
|
|
|
|
type MailText struct {
|
|
es_models.ObjectRoot
|
|
State int32 `json:"-"`
|
|
MailTextType string
|
|
Language string
|
|
Title string
|
|
PreHeader string
|
|
Subject string
|
|
Greeting string
|
|
Text string
|
|
ButtonText string
|
|
}
|
|
|
|
func GetMailText(mailTexts []*MailText, mailTextType string, language string) (int, *MailText) {
|
|
for i, m := range mailTexts {
|
|
if m.MailTextType == mailTextType && m.Language == language {
|
|
return i, m
|
|
}
|
|
}
|
|
return -1, nil
|
|
}
|
|
|
|
func MailTextsToModel(mailTexts []*MailText) []*iam_model.MailText {
|
|
convertedMailTexts := make([]*iam_model.MailText, len(mailTexts))
|
|
for i, m := range mailTexts {
|
|
convertedMailTexts[i] = MailTextToModel(m)
|
|
}
|
|
return convertedMailTexts
|
|
}
|
|
|
|
func MailTextToModel(mailText *MailText) *iam_model.MailText {
|
|
return &iam_model.MailText{
|
|
ObjectRoot: mailText.ObjectRoot,
|
|
State: iam_model.PolicyState(mailText.State),
|
|
MailTextType: mailText.MailTextType,
|
|
Language: mailText.Language,
|
|
Title: mailText.Title,
|
|
PreHeader: mailText.PreHeader,
|
|
Subject: mailText.Subject,
|
|
Greeting: mailText.Greeting,
|
|
Text: mailText.Text,
|
|
ButtonText: mailText.ButtonText,
|
|
}
|
|
}
|
|
|
|
func MailTextsFromModel(mailTexts []*iam_model.MailText) []*MailText {
|
|
convertedMailTexts := make([]*MailText, len(mailTexts))
|
|
for i, m := range mailTexts {
|
|
convertedMailTexts[i] = MailTextFromModel(m)
|
|
}
|
|
return convertedMailTexts
|
|
}
|
|
|
|
func MailTextFromModel(mailText *iam_model.MailText) *MailText {
|
|
return &MailText{
|
|
ObjectRoot: mailText.ObjectRoot,
|
|
State: int32(mailText.State),
|
|
MailTextType: mailText.MailTextType,
|
|
Language: mailText.Language,
|
|
Title: mailText.Title,
|
|
PreHeader: mailText.PreHeader,
|
|
Subject: mailText.Subject,
|
|
Greeting: mailText.Greeting,
|
|
Text: mailText.Text,
|
|
ButtonText: mailText.ButtonText,
|
|
}
|
|
}
|
|
|
|
func (p *MailText) Changes(changed *MailText) map[string]interface{} {
|
|
changes := make(map[string]interface{}, 8)
|
|
|
|
changes["mailTextType"] = changed.MailTextType
|
|
|
|
changes["language"] = changed.Language
|
|
|
|
if changed.Title != p.Title {
|
|
changes["title"] = changed.Title
|
|
}
|
|
|
|
if changed.PreHeader != p.PreHeader {
|
|
changes["preHeader"] = changed.PreHeader
|
|
}
|
|
|
|
if changed.Subject != p.Subject {
|
|
changes["subject"] = changed.Subject
|
|
}
|
|
|
|
if changed.Greeting != p.Greeting {
|
|
changes["greeting"] = changed.Greeting
|
|
}
|
|
|
|
if changed.Text != p.Text {
|
|
changes["text"] = changed.Text
|
|
}
|
|
|
|
if changed.ButtonText != p.ButtonText {
|
|
changes["buttonText"] = changed.ButtonText
|
|
}
|
|
|
|
return changes
|
|
}
|
|
|
|
func (p *MailText) SetDataLabel(event *es_models.Event) error {
|
|
err := json.Unmarshal(event.Data, p)
|
|
if err != nil {
|
|
return errors.ThrowInternal(err, "MODEL-3FUV5", "unable to unmarshal data")
|
|
}
|
|
return nil
|
|
}
|