mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
f4fa3ecef3
* fix: separate tier of custom text (message and login) * fix: add migration * fix: build problems * fix: tests * Update internal/api/grpc/admin/features.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/api/grpc/admin/features.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * fix: rename sql file * fix: change sql files * fix: console * fix: console Co-authored-by: Livio Amstutz <livio.a@gmail.com>
73 lines
2.1 KiB
Go
73 lines
2.1 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
|
|
caos_errs "github.com/caos/zitadel/internal/errors"
|
|
"github.com/caos/zitadel/internal/repository/iam"
|
|
|
|
"github.com/caos/zitadel/internal/domain"
|
|
)
|
|
|
|
func (c *Commands) SetDefaultFeatures(ctx context.Context, features *domain.Features) (*domain.ObjectDetails, error) {
|
|
existingFeatures := NewIAMFeaturesWriteModel()
|
|
setEvent, err := c.setDefaultFeatures(ctx, existingFeatures, features)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pushedEvents, err := c.eventstore.PushEvents(ctx, setEvent)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
err = AppendAndReduce(existingFeatures, pushedEvents...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return writeModelToObjectDetails(&existingFeatures.WriteModel), nil
|
|
}
|
|
|
|
func (c *Commands) setDefaultFeatures(ctx context.Context, existingFeatures *IAMFeaturesWriteModel, features *domain.Features) (*iam.FeaturesSetEvent, error) {
|
|
err := c.eventstore.FilterToQueryReducer(ctx, existingFeatures)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
setEvent, hasChanged := existingFeatures.NewSetEvent(
|
|
ctx,
|
|
IAMAggregateFromWriteModel(&existingFeatures.FeaturesWriteModel.WriteModel),
|
|
features.TierName,
|
|
features.TierDescription,
|
|
features.State,
|
|
features.StateDescription,
|
|
features.AuditLogRetention,
|
|
features.LoginPolicyFactors,
|
|
features.LoginPolicyIDP,
|
|
features.LoginPolicyPasswordless,
|
|
features.LoginPolicyRegistration,
|
|
features.LoginPolicyUsernameLogin,
|
|
features.PasswordComplexityPolicy,
|
|
features.LabelPolicyPrivateLabel,
|
|
features.LabelPolicyWatermark,
|
|
features.CustomDomain,
|
|
features.PrivacyPolicy,
|
|
features.MetadataUser,
|
|
features.CustomTextMessage,
|
|
features.CustomTextLogin,
|
|
)
|
|
if !hasChanged {
|
|
return nil, caos_errs.ThrowPreconditionFailed(nil, "Features-GE4h2", "Errors.Features.NotChanged")
|
|
}
|
|
return setEvent, nil
|
|
}
|
|
|
|
func (c *Commands) getDefaultFeatures(ctx context.Context) (*domain.Features, error) {
|
|
existingFeatures := NewIAMFeaturesWriteModel()
|
|
err := c.eventstore.FilterToQueryReducer(ctx, existingFeatures)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
features := writeModelToFeatures(&existingFeatures.FeaturesWriteModel)
|
|
features.IsDefault = true
|
|
return features, nil
|
|
}
|