mirror of
https://github.com/zitadel/zitadel.git
synced 2025-01-06 13:07:52 +00:00
fix: reset custom texts to default (#6833)
* Revert "fix: add texts after template reset (#6237)" This reverts commit d937ee3dda0620cf764d7404d23105cd573411c9. * fix: reset of custom text template * add custom bulk limits from issue https://github.com/zitadel/zitadel/issues/6766#issuecomment-1778721782
This commit is contained in:
parent
8a991a3a5c
commit
0a1da1f02c
@ -201,6 +201,9 @@ Projections:
|
||||
Customizations:
|
||||
Projects:
|
||||
TransactionDuration: 2s
|
||||
custom_texts:
|
||||
TransactionDuration: 2s
|
||||
BulkLimit: 400
|
||||
# The Notifications projection is used for sending emails and SMS to users
|
||||
Notifications:
|
||||
# As notification projections don't result in database statements, retries don't have an effect
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -577,10 +577,15 @@ func (wm *CustomLoginTextReadModel) Reduce() error {
|
||||
continue
|
||||
}
|
||||
case *policy.CustomTextTemplateRemovedEvent:
|
||||
if e.Template != domain.LoginCustomText {
|
||||
if e.Template != domain.LoginCustomText || wm.Language != e.Language {
|
||||
continue
|
||||
}
|
||||
wm.State = domain.PolicyStateRemoved
|
||||
// Reset all values
|
||||
*wm = CustomLoginTextReadModel{
|
||||
WriteModel: wm.WriteModel,
|
||||
Language: wm.Language,
|
||||
State: domain.PolicyStateRemoved,
|
||||
}
|
||||
}
|
||||
}
|
||||
return wm.WriteModel.Reduce()
|
||||
|
@ -1,34 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
)
|
||||
|
||||
type CustomTextWriteModel struct {
|
||||
eventstore.WriteModel
|
||||
|
||||
Key string
|
||||
Language language.Tag
|
||||
Text string
|
||||
State domain.CustomTextState
|
||||
}
|
||||
|
||||
func (wm *CustomTextWriteModel) Reduce() error {
|
||||
for _, event := range wm.Events {
|
||||
switch e := event.(type) {
|
||||
case *policy.CustomTextSetEvent:
|
||||
if wm.Key != e.Key || wm.Language != e.Language {
|
||||
continue
|
||||
}
|
||||
wm.Text = e.Text
|
||||
wm.State = domain.CustomTextStateActive
|
||||
case *policy.CustomTextRemovedEvent:
|
||||
wm.State = domain.CustomTextStateRemoved
|
||||
}
|
||||
}
|
||||
return wm.WriteModel.Reduce()
|
||||
}
|
@ -86,16 +86,6 @@ func writeModelToMailTemplatePolicy(wm *MailTemplateWriteModel) *domain.MailTemp
|
||||
}
|
||||
}
|
||||
|
||||
func writeModelToCustomText(wm *CustomTextWriteModel) *domain.CustomText {
|
||||
return &domain.CustomText{
|
||||
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
||||
State: wm.State,
|
||||
Key: wm.Key,
|
||||
Language: wm.Language,
|
||||
Text: wm.Text,
|
||||
}
|
||||
}
|
||||
|
||||
func writeModelToPasswordAgePolicy(wm *PasswordAgePolicyWriteModel) *domain.PasswordAgePolicy {
|
||||
return &domain.PasswordAgePolicy{
|
||||
ObjectRoot: writeModelToObjectRoot(wm.WriteModel),
|
||||
|
@ -1,61 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
caos_errs "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||
)
|
||||
|
||||
func (c *Commands) SetInstanceCustomText(ctx context.Context, customText *domain.CustomText) (*domain.CustomText, error) {
|
||||
setText := NewInstanceCustomTextWriteModel(ctx, customText.Key, customText.Language)
|
||||
instanceAgg := InstanceAggregateFromWriteModel(&setText.CustomTextWriteModel.WriteModel)
|
||||
event, err := c.setDefaultCustomText(ctx, instanceAgg, setText, customText)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pushedEvents, err := c.eventstore.Push(ctx, event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = AppendAndReduce(setText, pushedEvents...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return writeModelToCustomText(&setText.CustomTextWriteModel), nil
|
||||
}
|
||||
|
||||
func (c *Commands) setDefaultCustomText(ctx context.Context, instanceAgg *eventstore.Aggregate, addedPolicy *InstanceCustomTextWriteModel, text *domain.CustomText) (eventstore.Command, error) {
|
||||
if !text.IsValid() {
|
||||
return nil, caos_errs.ThrowInvalidArgument(nil, "INSTANCE-3MN0s", "Errors.CustomText.Invalid")
|
||||
}
|
||||
err := c.eventstore.FilterToQueryReducer(ctx, addedPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return instance.NewCustomTextSetEvent(
|
||||
ctx,
|
||||
instanceAgg,
|
||||
text.Template,
|
||||
text.Key,
|
||||
text.Text,
|
||||
text.Language), nil
|
||||
}
|
||||
|
||||
func (c *Commands) defaultCustomTextWriteModelByID(ctx context.Context, key string, language language.Tag) (policy *InstanceCustomTextWriteModel, err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
writeModel := NewInstanceCustomTextWriteModel(ctx, key, language)
|
||||
err = c.eventstore.FilterToQueryReducer(ctx, writeModel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return writeModel, nil
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
type InstanceCustomTextWriteModel struct {
|
||||
CustomTextWriteModel
|
||||
}
|
||||
|
||||
func NewInstanceCustomTextWriteModel(ctx context.Context, key string, language language.Tag) *InstanceCustomTextWriteModel {
|
||||
return &InstanceCustomTextWriteModel{
|
||||
CustomTextWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: authz.GetInstance(ctx).InstanceID(),
|
||||
ResourceOwner: authz.GetInstance(ctx).InstanceID(),
|
||||
},
|
||||
Key: key,
|
||||
Language: language,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *InstanceCustomTextWriteModel) AppendEvents(events ...eventstore.Event) {
|
||||
for _, event := range events {
|
||||
switch e := event.(type) {
|
||||
case *instance.CustomTextSetEvent:
|
||||
wm.CustomTextWriteModel.AppendEvents(&e.CustomTextSetEvent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *InstanceCustomTextWriteModel) Reduce() error {
|
||||
return wm.CustomTextWriteModel.Reduce()
|
||||
}
|
||||
|
||||
func (wm *InstanceCustomTextWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
AggregateIDs(wm.CustomTextWriteModel.AggregateID).
|
||||
AggregateTypes(instance.AggregateType).
|
||||
EventTypes(
|
||||
instance.CustomTextSetEventType).
|
||||
Builder()
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user