2024-02-28 10:55:54 +02:00
|
|
|
// Package feature implements the v1 feature repository.
|
|
|
|
// DEPRECATED: use ./feature_v2 instead.
|
2023-09-29 10:21:32 +02:00
|
|
|
package feature
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2024-02-28 10:55:54 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/feature/feature_v2"
|
2023-09-29 10:21:32 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2024-02-28 10:55:54 +02:00
|
|
|
DefaultLoginInstanceEventType = eventTypePrefix + eventstore.EventType(strings.ToLower("FeatureLoginDefaultOrg")) + setSuffix
|
2023-09-29 10:21:32 +02:00
|
|
|
)
|
|
|
|
|
2024-02-28 10:55:54 +02:00
|
|
|
// DefaultLoginInstanceEventToV2 upgrades the SetEvent to a V2 SetEvent so that
|
|
|
|
// the v2 reducers can handle the V1 events.
|
|
|
|
func DefaultLoginInstanceEventToV2(e *SetEvent[Boolean]) *feature_v2.SetEvent[bool] {
|
|
|
|
v2e := &feature_v2.SetEvent[bool]{
|
|
|
|
BaseEvent: e.BaseEvent,
|
|
|
|
Value: e.Value.Boolean,
|
|
|
|
}
|
2024-03-05 17:12:49 +02:00
|
|
|
|
|
|
|
// v1 used a random aggregate ID.
|
|
|
|
// v2 uses the instance ID as aggregate ID.
|
|
|
|
v2e.BaseEvent.Agg.ID = e.Agg.InstanceID
|
2024-02-28 10:55:54 +02:00
|
|
|
v2e.BaseEvent.EventType = feature_v2.InstanceLoginDefaultOrgEventType
|
|
|
|
return v2e
|
2023-09-29 10:21:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type SetEvent[T SetEventType] struct {
|
2023-11-03 13:02:17 +02:00
|
|
|
*eventstore.BaseEvent `json:"-"`
|
2023-09-29 10:21:32 +02:00
|
|
|
|
|
|
|
Value T
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *SetEvent[T]) SetBaseEvent(b *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = b
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (e *SetEvent[T]) Payload() interface{} {
|
2023-09-29 10:21:32 +02:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 12:19:10 +02:00
|
|
|
func (e *SetEvent[T]) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-09-29 10:21:32 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type SetEventType interface {
|
|
|
|
Boolean
|
|
|
|
FeatureType() domain.FeatureType
|
|
|
|
}
|
|
|
|
|
|
|
|
type EventType[T SetEventType] struct {
|
|
|
|
eventstore.EventType
|
|
|
|
}
|
|
|
|
|
|
|
|
type Boolean struct {
|
|
|
|
Boolean bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b Boolean) FeatureType() domain.FeatureType {
|
|
|
|
return domain.FeatureTypeBoolean
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSetEvent[T SetEventType](
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
eventType eventstore.EventType,
|
|
|
|
setType T,
|
|
|
|
) *SetEvent[T] {
|
|
|
|
return &SetEvent[T]{
|
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx, aggregate, eventType),
|
|
|
|
setType,
|
|
|
|
}
|
|
|
|
}
|