mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:17:32 +00:00
feat: custom message text (#1801)
* 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>
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
)
|
||||
|
||||
func (o *Org) appendAddMailTextEvent(event *es_models.Event) error {
|
||||
mailText := &iam_es_model.MailText{}
|
||||
err := mailText.SetDataLabel(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mailText.ObjectRoot.CreationDate = event.CreationDate
|
||||
o.MailTexts = append(o.MailTexts, mailText)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendChangeMailTextEvent(event *es_models.Event) error {
|
||||
mailText := &iam_es_model.MailText{}
|
||||
err := mailText.SetDataLabel(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mailText.ObjectRoot.ChangeDate = event.CreationDate
|
||||
if n, m := iam_es_model.GetMailText(o.MailTexts, mailText.MailTextType, mailText.Language); m != nil {
|
||||
o.MailTexts[n] = mailText
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Org) appendRemoveMailTextEvent(event *es_models.Event) error {
|
||||
mailText := &iam_es_model.MailText{}
|
||||
err := mailText.SetDataLabel(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if n, m := iam_es_model.GetMailText(o.MailTexts, mailText.MailTextType, mailText.Language); m != nil {
|
||||
o.MailTexts[n] = o.MailTexts[len(o.MailTexts)-1]
|
||||
o.MailTexts[len(o.MailTexts)-1] = nil
|
||||
o.MailTexts = o.MailTexts[:len(o.MailTexts)-1]
|
||||
}
|
||||
return nil
|
||||
}
|
@@ -1,91 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
)
|
||||
|
||||
func TestAppendAddMailTextEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
mailText *iam_es_model.MailText
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append add mail text event",
|
||||
args: args{
|
||||
org: &Org{},
|
||||
mailText: &iam_es_model.MailText{MailTextType: "Type", Language: "DE"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{MailTexts: []*iam_es_model.MailText{&iam_es_model.MailText{MailTextType: "Type", Language: "DE"}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.mailText != nil {
|
||||
data, _ := json.Marshal(tt.args.mailText)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendAddMailTextEvent(tt.args.event)
|
||||
if len(tt.args.org.MailTexts) != 1 {
|
||||
t.Errorf("got wrong result should have one mailtext actual: %v ", len(tt.args.org.MailTexts))
|
||||
}
|
||||
if tt.result.MailTexts[0].Language != tt.args.org.MailTexts[0].Language {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.MailTexts[0].Language, tt.args.org.MailTexts[0].Language)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendChangeMailTextEvent(t *testing.T) {
|
||||
type args struct {
|
||||
org *Org
|
||||
mailText *iam_es_model.MailText
|
||||
event *es_models.Event
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
result *Org
|
||||
}{
|
||||
{
|
||||
name: "append change mail text event",
|
||||
args: args{
|
||||
org: &Org{MailTexts: []*iam_es_model.MailText{&iam_es_model.MailText{
|
||||
Language: "DE",
|
||||
MailTextType: "TypeX",
|
||||
}}},
|
||||
mailText: &iam_es_model.MailText{MailTextType: "Type", Language: "DE"},
|
||||
event: &es_models.Event{},
|
||||
},
|
||||
result: &Org{MailTexts: []*iam_es_model.MailText{&iam_es_model.MailText{
|
||||
Language: "DE",
|
||||
MailTextType: "Type",
|
||||
}}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.args.mailText != nil {
|
||||
data, _ := json.Marshal(tt.args.mailText)
|
||||
tt.args.event.Data = data
|
||||
}
|
||||
tt.args.org.appendChangeMailTextEvent(tt.args.event)
|
||||
if len(tt.args.org.MailTexts) != 1 {
|
||||
t.Errorf("got wrong result should have one mailtext actual: %v ", len(tt.args.org.MailTexts))
|
||||
}
|
||||
if tt.result.MailTexts[0].Language != tt.args.org.MailTexts[0].Language {
|
||||
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result.MailTexts[0].Language, tt.args.org.MailTexts[0].Language)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@@ -26,7 +26,6 @@ type Org struct {
|
||||
OrgIAMPolicy *iam_es_model.OrgIAMPolicy `json:"-"`
|
||||
LabelPolicy *iam_es_model.LabelPolicy `json:"-"`
|
||||
MailTemplate *iam_es_model.MailTemplate `json:"-"`
|
||||
MailTexts []*iam_es_model.MailText `json:"-"`
|
||||
IDPs []*iam_es_model.IDPConfig `json:"-"`
|
||||
LoginPolicy *iam_es_model.LoginPolicy `json:"-"`
|
||||
PasswordComplexityPolicy *iam_es_model.PasswordComplexityPolicy `json:"-"`
|
||||
@@ -34,44 +33,6 @@ type Org struct {
|
||||
PasswordLockoutPolicy *iam_es_model.PasswordLockoutPolicy `json:"-"`
|
||||
}
|
||||
|
||||
func OrgFromModel(org *org_model.Org) *Org {
|
||||
members := OrgMembersFromModel(org.Members)
|
||||
domains := OrgDomainsFromModel(org.Domains)
|
||||
idps := iam_es_model.IDPConfigsFromModel(org.IDPs)
|
||||
mailTexts := iam_es_model.MailTextsFromModel(org.MailTexts)
|
||||
converted := &Org{
|
||||
ObjectRoot: org.ObjectRoot,
|
||||
Name: org.Name,
|
||||
State: int32(org.State),
|
||||
Domains: domains,
|
||||
MailTexts: mailTexts,
|
||||
Members: members,
|
||||
IDPs: idps,
|
||||
}
|
||||
if org.OrgIamPolicy != nil {
|
||||
converted.OrgIAMPolicy = iam_es_model.OrgIAMPolicyFromModel(org.OrgIamPolicy)
|
||||
}
|
||||
if org.LoginPolicy != nil {
|
||||
converted.LoginPolicy = iam_es_model.LoginPolicyFromModel(org.LoginPolicy)
|
||||
}
|
||||
if org.LabelPolicy != nil {
|
||||
converted.LabelPolicy = iam_es_model.LabelPolicyFromModel(org.LabelPolicy)
|
||||
}
|
||||
if org.MailTemplate != nil {
|
||||
converted.MailTemplate = iam_es_model.MailTemplateFromModel(org.MailTemplate)
|
||||
}
|
||||
if org.PasswordComplexityPolicy != nil {
|
||||
converted.PasswordComplexityPolicy = iam_es_model.PasswordComplexityPolicyFromModel(org.PasswordComplexityPolicy)
|
||||
}
|
||||
if org.PasswordAgePolicy != nil {
|
||||
converted.PasswordAgePolicy = iam_es_model.PasswordAgePolicyFromModel(org.PasswordAgePolicy)
|
||||
}
|
||||
if org.PasswordLockoutPolicy != nil {
|
||||
converted.PasswordLockoutPolicy = iam_es_model.PasswordLockoutPolicyFromModel(org.PasswordLockoutPolicy)
|
||||
}
|
||||
return converted
|
||||
}
|
||||
|
||||
func OrgToModel(org *Org) *org_model.Org {
|
||||
converted := &org_model.Org{
|
||||
ObjectRoot: org.ObjectRoot,
|
||||
@@ -79,7 +40,6 @@ func OrgToModel(org *Org) *org_model.Org {
|
||||
State: org_model.OrgState(org.State),
|
||||
Domains: OrgDomainsToModel(org.Domains),
|
||||
Members: OrgMembersToModel(org.Members),
|
||||
MailTexts: iam_es_model.MailTextsToModel(org.MailTexts),
|
||||
IDPs: iam_es_model.IDPConfigsToModel(org.IDPs),
|
||||
}
|
||||
if org.OrgIAMPolicy != nil {
|
||||
@@ -216,12 +176,6 @@ func (o *Org) AppendEvent(event *es_models.Event) (err error) {
|
||||
err = o.appendChangeMailTemplateEvent(event)
|
||||
case MailTemplateRemoved:
|
||||
o.appendRemoveMailTemplateEvent(event)
|
||||
case MailTextAdded:
|
||||
err = o.appendAddMailTextEvent(event)
|
||||
case MailTextChanged:
|
||||
err = o.appendChangeMailTextEvent(event)
|
||||
case MailTextRemoved:
|
||||
o.appendRemoveMailTextEvent(event)
|
||||
case LoginPolicySecondFactorAdded:
|
||||
err = o.appendAddSecondFactorToLoginPolicyEvent(event)
|
||||
case LoginPolicySecondFactorRemoved:
|
||||
|
@@ -76,9 +76,10 @@ const (
|
||||
MailTemplateAdded models.EventType = "org.mail.template.added"
|
||||
MailTemplateChanged models.EventType = "org.mail.template.changed"
|
||||
MailTemplateRemoved models.EventType = "org.mail.template.removed"
|
||||
MailTextAdded models.EventType = "org.mail.text.added"
|
||||
MailTextChanged models.EventType = "org.mail.text.changed"
|
||||
MailTextRemoved models.EventType = "org.mail.text.removed"
|
||||
|
||||
CustomTextSet models.EventType = "org.customtext.set"
|
||||
CustomTextRemoved models.EventType = "org.customtext.removed"
|
||||
CustomTextMessageRemoved models.EventType = "org.customtext.template.removed"
|
||||
|
||||
PasswordComplexityPolicyAdded models.EventType = "org.policy.password.complexity.added"
|
||||
PasswordComplexityPolicyChanged models.EventType = "org.policy.password.complexity.changed"
|
||||
|
Reference in New Issue
Block a user