2024-02-28 08:55:54 +00:00
|
|
|
// Package feature implements the v1 feature repository.
|
|
|
|
// DEPRECATED: use ./feature_v2 instead.
|
2023-09-29 08:21:32 +00:00
|
|
|
package feature
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2024-02-28 08:55:54 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/feature/feature_v2"
|
2023-09-29 08:21:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2024-02-28 08:55:54 +00:00
|
|
|
DefaultLoginInstanceEventType = eventTypePrefix + eventstore.EventType(strings.ToLower("FeatureLoginDefaultOrg")) + setSuffix
|
2023-09-29 08:21:32 +00:00
|
|
|
)
|
|
|
|
|
2024-02-28 08:55:54 +00: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 15:12:49 +00: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 08:55:54 +00:00
|
|
|
v2e.BaseEvent.EventType = feature_v2.InstanceLoginDefaultOrgEventType
|
|
|
|
return v2e
|
2023-09-29 08:21:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type SetEvent[T SetEventType] struct {
|
2023-11-03 11:02:17 +00:00
|
|
|
*eventstore.BaseEvent `json:"-"`
|
2023-09-29 08:21:32 +00:00
|
|
|
|
|
|
|
Value T
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *SetEvent[T]) SetBaseEvent(b *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = b
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *SetEvent[T]) Payload() interface{} {
|
2023-09-29 08:21:32 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *SetEvent[T]) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-09-29 08:21:32 +00: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,
|
|
|
|
}
|
|
|
|
}
|