mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-24 00:28:18 +00:00
68bfab2fb3
* start feature flags * base feature events on domain const * setup default features * allow setting feature in system api * allow setting feature in admin api * set settings in login based on feature * fix rebasing * unit tests * i18n * update policy after domain discovery * some changes from review * check feature and value type * check feature and value type
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package feature
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/command"
|
|
"github.com/zitadel/zitadel/internal/command/preparation"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/repository/feature"
|
|
)
|
|
|
|
type Checker interface {
|
|
CheckInstanceBooleanFeature(ctx context.Context, f domain.Feature) (feature.Boolean, error)
|
|
}
|
|
|
|
func NewCheck(eventstore *eventstore.Eventstore) *Check {
|
|
return &Check{eventstore: eventstore}
|
|
}
|
|
|
|
type Check struct {
|
|
eventstore *eventstore.Eventstore
|
|
}
|
|
|
|
func (c *Check) CheckInstanceBooleanFeature(ctx context.Context, f domain.Feature) (feature.Boolean, error) {
|
|
return getInstanceFeature[feature.Boolean](ctx, f, c.eventstore.Filter)
|
|
}
|
|
|
|
func getInstanceFeature[T feature.SetEventType](ctx context.Context, f domain.Feature, filter preparation.FilterToQueryReducer) (T, error) {
|
|
instanceID := authz.GetInstance(ctx).InstanceID()
|
|
writeModel, err := command.NewInstanceFeatureWriteModel[T](instanceID, f)
|
|
if err != nil {
|
|
return writeModel.Value, err
|
|
}
|
|
events, err := filter(ctx, writeModel.Query())
|
|
if err != nil {
|
|
return writeModel.Value, err
|
|
}
|
|
writeModel.AppendEvents(events...)
|
|
if err = writeModel.Reduce(); err != nil {
|
|
return writeModel.Value, err
|
|
}
|
|
return writeModel.Value, nil
|
|
}
|