mirror of
https://github.com/zitadel/zitadel.git
synced 2025-01-11 19:53:41 +00:00
fbc75d89b2
* 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>
68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
"reflect"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
|
"github.com/caos/zitadel/internal/v2/repository/org"
|
|
"github.com/caos/zitadel/internal/v2/repository/policy"
|
|
)
|
|
|
|
type OrgMailTemplateWriteModel struct {
|
|
MailTemplateWriteModel
|
|
}
|
|
|
|
func NewOrgMailTemplateWriteModel(orgID string) *OrgMailTemplateWriteModel {
|
|
return &OrgMailTemplateWriteModel{
|
|
MailTemplateWriteModel{
|
|
WriteModel: eventstore.WriteModel{
|
|
AggregateID: orgID,
|
|
ResourceOwner: orgID,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func (wm *OrgMailTemplateWriteModel) AppendEvents(events ...eventstore.EventReader) {
|
|
for _, event := range events {
|
|
switch e := event.(type) {
|
|
case *org.MailTemplateAddedEvent:
|
|
wm.MailTemplateWriteModel.AppendEvents(&e.MailTemplateAddedEvent)
|
|
case *org.MailTemplateChangedEvent:
|
|
wm.MailTemplateWriteModel.AppendEvents(&e.MailTemplateChangedEvent)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (wm *OrgMailTemplateWriteModel) Reduce() error {
|
|
return wm.MailTemplateWriteModel.Reduce()
|
|
}
|
|
|
|
func (wm *OrgMailTemplateWriteModel) Query() *eventstore.SearchQueryBuilder {
|
|
query := eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, org.AggregateType).
|
|
AggregateIDs(wm.MailTemplateWriteModel.AggregateID)
|
|
if wm.ResourceOwner != "" {
|
|
query.ResourceOwner(wm.ResourceOwner)
|
|
}
|
|
return query
|
|
}
|
|
|
|
func (wm *OrgMailTemplateWriteModel) NewChangedEvent(
|
|
ctx context.Context,
|
|
template []byte,
|
|
) (*org.MailTemplateChangedEvent, bool) {
|
|
changes := make([]policy.MailTemplateChanges, 0)
|
|
if !reflect.DeepEqual(wm.Template, template) {
|
|
changes = append(changes, policy.ChangeTemplate(template))
|
|
}
|
|
if len(changes) == 0 {
|
|
return nil, false
|
|
}
|
|
changedEvent, err := org.NewMailTemplateChangedEvent(ctx, changes)
|
|
if err != nil {
|
|
return nil, false
|
|
}
|
|
return changedEvent, true
|
|
}
|