1
0
mirror of https://github.com/zitadel/zitadel.git synced 2025-04-03 03:25:41 +00:00
zitadel/internal/command/instance_custom_text.go
Fabi 9d4f296c62
fix: rename iam to instance ()
* fix: rename iam command side to instance

* fix: rename iam command side to instance

* fix: rename iam command side to instance

* fix: rename iam command side to instance

* fix: rename orgiampolicy to domain policy

* fix: merge conflicts

* fix: protos

* fix: md files

* implement deprecated org iam policy again

Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2022-03-24 16:21:34 +00:00

62 lines
1.9 KiB
Go

package command
import (
"context"
"golang.org/x/text/language"
"github.com/caos/zitadel/internal/domain"
caos_errs "github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/repository/instance"
"github.com/caos/zitadel/internal/telemetry/tracing"
)
func (c *Commands) SetInstanceCustomText(ctx context.Context, customText *domain.CustomText) (*domain.CustomText, error) {
setText := NewInstanceCustomTextWriteModel(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(key, language)
err = c.eventstore.FilterToQueryReducer(ctx, writeModel)
if err != nil {
return nil, err
}
return writeModel, nil
}