mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-26 22:38:45 +00:00
feat(eventstore): increase parallel write capabilities (#5940)
This implementation increases parallel write capabilities of the eventstore. Please have a look at the technical advisories: [05](https://zitadel.com/docs/support/advisory/a10005) and [06](https://zitadel.com/docs/support/advisory/a10006). The implementation of eventstore.push is rewritten and stored events are migrated to a new table `eventstore.events2`. If you are using cockroach: make sure that the database user of ZITADEL has `VIEWACTIVITY` grant. This is used to query events.
This commit is contained in:
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/action"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
@@ -29,43 +29,44 @@ const (
|
||||
ActionOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type actionProjection struct {
|
||||
crdb.StatementHandler
|
||||
type actionProjection struct{}
|
||||
|
||||
func newActionProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(actionProjection))
|
||||
}
|
||||
|
||||
func newActionProjection(ctx context.Context, config crdb.StatementHandlerConfig) *actionProjection {
|
||||
p := new(actionProjection)
|
||||
config.ProjectionName = ActionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(ActionIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ActionCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(ActionChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(ActionResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ActionInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ActionStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(ActionSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(ActionNameCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ActionScriptCol, crdb.ColumnTypeText, crdb.Default("")),
|
||||
crdb.NewColumn(ActionTimeoutCol, crdb.ColumnTypeInt64, crdb.Default(0)),
|
||||
crdb.NewColumn(ActionAllowedToFailCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(ActionOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*actionProjection) Name() string {
|
||||
return ActionTable
|
||||
}
|
||||
|
||||
func (*actionProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(ActionIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(ActionCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(ActionChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(ActionResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(ActionInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(ActionStateCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(ActionSequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(ActionNameCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(ActionScriptCol, handler.ColumnTypeText, handler.Default("")),
|
||||
handler.NewColumn(ActionTimeoutCol, handler.ColumnTypeInt64, handler.Default(0)),
|
||||
handler.NewColumn(ActionAllowedToFailCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(ActionOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(ActionInstanceIDCol, ActionIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("resource_owner", []string{ActionResourceOwnerCol})),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{ActionOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(ActionInstanceIDCol, ActionIDCol),
|
||||
handler.WithIndex(handler.NewIndex("resource_owner", []string{ActionResourceOwnerCol})),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{ActionOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *actionProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *actionProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: action.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: action.AddedEventType,
|
||||
Reduce: p.reduceActionAdded,
|
||||
@@ -90,7 +91,7 @@ func (p *actionProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.OrgRemovedEventType,
|
||||
Reduce: p.reduceOwnerRemoved,
|
||||
@@ -99,7 +100,7 @@ func (p *actionProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(ActionInstanceIDCol),
|
||||
@@ -114,7 +115,7 @@ func (p *actionProjection) reduceActionAdded(event eventstore.Event) (*handler.S
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Dff21", "reduce.wrong.event.type% s", action.AddedEventType)
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(ActionIDCol, e.Aggregate().ID),
|
||||
@@ -153,7 +154,7 @@ func (p *actionProjection) reduceActionChanged(event eventstore.Event) (*handler
|
||||
if e.AllowedToFail != nil {
|
||||
values = append(values, handler.NewCol(ActionAllowedToFailCol, *e.AllowedToFail))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
values,
|
||||
[]handler.Condition{
|
||||
@@ -168,7 +169,7 @@ func (p *actionProjection) reduceActionDeactivated(event eventstore.Event) (*han
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Fgh32", "reduce.wrong.event.type %s", action.DeactivatedEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(ActionChangeDateCol, e.CreationDate()),
|
||||
@@ -187,7 +188,7 @@ func (p *actionProjection) reduceActionReactivated(event eventstore.Event) (*han
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-hwdqa", "reduce.wrong.event.type %s", action.ReactivatedEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(ActionChangeDateCol, e.CreationDate()),
|
||||
@@ -206,7 +207,7 @@ func (p *actionProjection) reduceActionRemoved(event eventstore.Event) (*handler
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Dgh2d", "reduce.wrong.event.type %s", action.RemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ActionIDCol, e.Aggregate().ID),
|
||||
@@ -220,7 +221,7 @@ func (p *actionProjection) reduceOwnerRemoved(event eventstore.Event) (*handler.
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-mSmWM", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ActionInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -7,8 +7,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/action"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
@@ -27,17 +26,19 @@ func TestActionProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceActionAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(action.AddedEventType),
|
||||
action.AggregateType,
|
||||
[]byte(`{"name": "name", "script":"name(){}","timeout": 3000000000, "allowedToFail": true}`),
|
||||
), action.AddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
action.AddedEventType,
|
||||
action.AggregateType,
|
||||
[]byte(`{"name": "name", "script":"name(){}","timeout": 3000000000, "allowedToFail": true}`),
|
||||
),
|
||||
action.AddedEventMapper,
|
||||
),
|
||||
},
|
||||
reduce: (&actionProjection{}).reduceActionAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("action"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("action"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -63,17 +64,19 @@ func TestActionProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceActionChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(action.ChangedEventType),
|
||||
action.AggregateType,
|
||||
[]byte(`{"name": "name2", "script":"name2(){}"}`),
|
||||
), action.ChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
action.ChangedEventType,
|
||||
action.AggregateType,
|
||||
[]byte(`{"name": "name2", "script":"name2(){}"}`),
|
||||
),
|
||||
action.ChangedEventMapper,
|
||||
),
|
||||
},
|
||||
reduce: (&actionProjection{}).reduceActionChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("action"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("action"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -94,17 +97,19 @@ func TestActionProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceActionDeactivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(action.ChangedEventType),
|
||||
action.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), action.DeactivatedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
action.ChangedEventType,
|
||||
action.AggregateType,
|
||||
[]byte(`{}`),
|
||||
),
|
||||
action.DeactivatedEventMapper,
|
||||
),
|
||||
},
|
||||
reduce: (&actionProjection{}).reduceActionDeactivated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("action"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("action"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -124,17 +129,19 @@ func TestActionProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceActionReactivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(action.ChangedEventType),
|
||||
action.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), action.ReactivatedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
action.ChangedEventType,
|
||||
action.AggregateType,
|
||||
[]byte(`{}`),
|
||||
),
|
||||
action.ReactivatedEventMapper,
|
||||
),
|
||||
},
|
||||
reduce: (&actionProjection{}).reduceActionReactivated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("action"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("action"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -154,17 +161,19 @@ func TestActionProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceActionRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(action.ChangedEventType),
|
||||
action.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), action.RemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
action.ChangedEventType,
|
||||
action.AggregateType,
|
||||
[]byte(`{}`),
|
||||
),
|
||||
action.RemovedEventMapper,
|
||||
),
|
||||
},
|
||||
reduce: (&actionProjection{}).reduceActionRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("action"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("action"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -181,17 +190,19 @@ func TestActionProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceOwnerRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
),
|
||||
org.OrgRemovedEventMapper,
|
||||
),
|
||||
},
|
||||
reduce: (&actionProjection{}).reduceOwnerRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -208,17 +219,19 @@ func TestActionProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
),
|
||||
instance.InstanceRemovedEventMapper,
|
||||
),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(ActionInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
+124
-123
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/project"
|
||||
@@ -67,91 +67,92 @@ const (
|
||||
AppSAMLConfigColumnMetadataURL = "metadata_url"
|
||||
)
|
||||
|
||||
type appProjection struct {
|
||||
crdb.StatementHandler
|
||||
type appProjection struct{}
|
||||
|
||||
func newAppProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(appProjection))
|
||||
}
|
||||
|
||||
func newAppProjection(ctx context.Context, config crdb.StatementHandlerConfig) *appProjection {
|
||||
p := new(appProjection)
|
||||
config.ProjectionName = AppProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewMultiTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(AppColumnID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppColumnName, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppColumnProjectID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(AppColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(AppColumnResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppColumnState, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(AppColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(AppColumnOwnerRemoved, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*appProjection) Name() string {
|
||||
return AppProjectionTable
|
||||
}
|
||||
|
||||
func (*appProjection) Init() *old_handler.Check {
|
||||
return handler.NewMultiTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(AppColumnID, handler.ColumnTypeText),
|
||||
handler.NewColumn(AppColumnName, handler.ColumnTypeText),
|
||||
handler.NewColumn(AppColumnProjectID, handler.ColumnTypeText),
|
||||
handler.NewColumn(AppColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(AppColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(AppColumnResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(AppColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(AppColumnState, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(AppColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(AppColumnOwnerRemoved, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(AppColumnInstanceID, AppColumnID),
|
||||
crdb.WithIndex(crdb.NewIndex("project_id", []string{AppColumnProjectID})),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{AppColumnOwnerRemoved})),
|
||||
handler.NewPrimaryKey(AppColumnInstanceID, AppColumnID),
|
||||
handler.WithIndex(handler.NewIndex("project_id", []string{AppColumnProjectID})),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{AppColumnOwnerRemoved})),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(AppAPIConfigColumnAppID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppAPIConfigColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppAPIConfigColumnClientID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppAPIConfigColumnClientSecret, crdb.ColumnTypeJSONB, crdb.Nullable()),
|
||||
crdb.NewColumn(AppAPIConfigColumnAuthMethod, crdb.ColumnTypeEnum),
|
||||
handler.NewSuffixedTable([]*handler.InitColumn{
|
||||
handler.NewColumn(AppAPIConfigColumnAppID, handler.ColumnTypeText),
|
||||
handler.NewColumn(AppAPIConfigColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(AppAPIConfigColumnClientID, handler.ColumnTypeText),
|
||||
handler.NewColumn(AppAPIConfigColumnClientSecret, handler.ColumnTypeJSONB, handler.Nullable()),
|
||||
handler.NewColumn(AppAPIConfigColumnAuthMethod, handler.ColumnTypeEnum),
|
||||
},
|
||||
crdb.NewPrimaryKey(AppAPIConfigColumnInstanceID, AppAPIConfigColumnAppID),
|
||||
handler.NewPrimaryKey(AppAPIConfigColumnInstanceID, AppAPIConfigColumnAppID),
|
||||
appAPITableSuffix,
|
||||
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
|
||||
crdb.WithIndex(crdb.NewIndex("client_id", []string{AppAPIConfigColumnClientID})),
|
||||
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
|
||||
handler.WithIndex(handler.NewIndex("client_id", []string{AppAPIConfigColumnClientID})),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(AppOIDCConfigColumnAppID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppOIDCConfigColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppOIDCConfigColumnVersion, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(AppOIDCConfigColumnClientID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppOIDCConfigColumnClientSecret, crdb.ColumnTypeJSONB, crdb.Nullable()),
|
||||
crdb.NewColumn(AppOIDCConfigColumnRedirectUris, crdb.ColumnTypeTextArray, crdb.Nullable()),
|
||||
crdb.NewColumn(AppOIDCConfigColumnResponseTypes, crdb.ColumnTypeEnumArray, crdb.Nullable()),
|
||||
crdb.NewColumn(AppOIDCConfigColumnGrantTypes, crdb.ColumnTypeEnumArray, crdb.Nullable()),
|
||||
crdb.NewColumn(AppOIDCConfigColumnApplicationType, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(AppOIDCConfigColumnAuthMethodType, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(AppOIDCConfigColumnPostLogoutRedirectUris, crdb.ColumnTypeTextArray, crdb.Nullable()),
|
||||
crdb.NewColumn(AppOIDCConfigColumnDevMode, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(AppOIDCConfigColumnAccessTokenType, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(AppOIDCConfigColumnAccessTokenRoleAssertion, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(AppOIDCConfigColumnIDTokenRoleAssertion, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(AppOIDCConfigColumnIDTokenUserinfoAssertion, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(AppOIDCConfigColumnClockSkew, crdb.ColumnTypeInt64, crdb.Default(0)),
|
||||
crdb.NewColumn(AppOIDCConfigColumnAdditionalOrigins, crdb.ColumnTypeTextArray, crdb.Nullable()),
|
||||
crdb.NewColumn(AppOIDCConfigColumnSkipNativeAppSuccessPage, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
handler.NewSuffixedTable([]*handler.InitColumn{
|
||||
handler.NewColumn(AppOIDCConfigColumnAppID, handler.ColumnTypeText),
|
||||
handler.NewColumn(AppOIDCConfigColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(AppOIDCConfigColumnVersion, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(AppOIDCConfigColumnClientID, handler.ColumnTypeText),
|
||||
handler.NewColumn(AppOIDCConfigColumnClientSecret, handler.ColumnTypeJSONB, handler.Nullable()),
|
||||
handler.NewColumn(AppOIDCConfigColumnRedirectUris, handler.ColumnTypeTextArray, handler.Nullable()),
|
||||
handler.NewColumn(AppOIDCConfigColumnResponseTypes, handler.ColumnTypeEnumArray, handler.Nullable()),
|
||||
handler.NewColumn(AppOIDCConfigColumnGrantTypes, handler.ColumnTypeEnumArray, handler.Nullable()),
|
||||
handler.NewColumn(AppOIDCConfigColumnApplicationType, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(AppOIDCConfigColumnAuthMethodType, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(AppOIDCConfigColumnPostLogoutRedirectUris, handler.ColumnTypeTextArray, handler.Nullable()),
|
||||
handler.NewColumn(AppOIDCConfigColumnDevMode, handler.ColumnTypeBool),
|
||||
handler.NewColumn(AppOIDCConfigColumnAccessTokenType, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(AppOIDCConfigColumnAccessTokenRoleAssertion, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(AppOIDCConfigColumnIDTokenRoleAssertion, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(AppOIDCConfigColumnIDTokenUserinfoAssertion, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(AppOIDCConfigColumnClockSkew, handler.ColumnTypeInt64, handler.Default(0)),
|
||||
handler.NewColumn(AppOIDCConfigColumnAdditionalOrigins, handler.ColumnTypeTextArray, handler.Nullable()),
|
||||
handler.NewColumn(AppOIDCConfigColumnSkipNativeAppSuccessPage, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(AppOIDCConfigColumnInstanceID, AppOIDCConfigColumnAppID),
|
||||
handler.NewPrimaryKey(AppOIDCConfigColumnInstanceID, AppOIDCConfigColumnAppID),
|
||||
appOIDCTableSuffix,
|
||||
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
|
||||
crdb.WithIndex(crdb.NewIndex("client_id", []string{AppOIDCConfigColumnClientID})),
|
||||
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
|
||||
handler.WithIndex(handler.NewIndex("client_id", []string{AppOIDCConfigColumnClientID})),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(AppSAMLConfigColumnAppID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppSAMLConfigColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppSAMLConfigColumnEntityID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AppSAMLConfigColumnMetadata, crdb.ColumnTypeBytes),
|
||||
crdb.NewColumn(AppSAMLConfigColumnMetadataURL, crdb.ColumnTypeText),
|
||||
handler.NewSuffixedTable([]*handler.InitColumn{
|
||||
handler.NewColumn(AppSAMLConfigColumnAppID, handler.ColumnTypeText),
|
||||
handler.NewColumn(AppSAMLConfigColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(AppSAMLConfigColumnEntityID, handler.ColumnTypeText),
|
||||
handler.NewColumn(AppSAMLConfigColumnMetadata, handler.ColumnTypeBytes),
|
||||
handler.NewColumn(AppSAMLConfigColumnMetadataURL, handler.ColumnTypeText),
|
||||
},
|
||||
crdb.NewPrimaryKey(AppSAMLConfigColumnInstanceID, AppSAMLConfigColumnAppID),
|
||||
handler.NewPrimaryKey(AppSAMLConfigColumnInstanceID, AppSAMLConfigColumnAppID),
|
||||
appSAMLTableSuffix,
|
||||
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
|
||||
crdb.WithIndex(crdb.NewIndex("entity_id", []string{AppSAMLConfigColumnEntityID})),
|
||||
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
|
||||
handler.WithIndex(handler.NewIndex("entity_id", []string{AppSAMLConfigColumnEntityID})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *appProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *appProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: project.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: project.ApplicationAddedType,
|
||||
Reduce: p.reduceAppAdded,
|
||||
@@ -212,7 +213,7 @@ func (p *appProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.OrgRemovedEventType,
|
||||
Reduce: p.reduceOwnerRemoved,
|
||||
@@ -221,7 +222,7 @@ func (p *appProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(AppColumnInstanceID),
|
||||
@@ -236,7 +237,7 @@ func (p *appProjection) reduceAppAdded(event eventstore.Event) (*handler.Stateme
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-1xYE6", "reduce.wrong.event.type %s", project.ApplicationAddedType)
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(AppColumnID, e.AppID),
|
||||
@@ -258,9 +259,9 @@ func (p *appProjection) reduceAppChanged(event eventstore.Event) (*handler.State
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ZJ8JA", "reduce.wrong.event.type %s", project.ApplicationChangedType)
|
||||
}
|
||||
if e.Name == "" {
|
||||
return crdb.NewNoOpStatement(event), nil
|
||||
return handler.NewNoOpStatement(event), nil
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(AppColumnName, e.Name),
|
||||
@@ -279,7 +280,7 @@ func (p *appProjection) reduceAppDeactivated(event eventstore.Event) (*handler.S
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-MVWxZ", "reduce.wrong.event.type %s", project.ApplicationDeactivatedType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(AppColumnState, domain.AppStateInactive),
|
||||
@@ -298,7 +299,7 @@ func (p *appProjection) reduceAppReactivated(event eventstore.Event) (*handler.S
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-D0HZO", "reduce.wrong.event.type %s", project.ApplicationReactivatedType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(AppColumnState, domain.AppStateActive),
|
||||
@@ -317,7 +318,7 @@ func (p *appProjection) reduceAppRemoved(event eventstore.Event) (*handler.State
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Y99aq", "reduce.wrong.event.type %s", project.ApplicationRemovedType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(AppColumnID, e.AppID),
|
||||
@@ -331,7 +332,7 @@ func (p *appProjection) reduceProjectRemoved(event eventstore.Event) (*handler.S
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-DlUlO", "reduce.wrong.event.type %s", project.ProjectRemovedType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(AppColumnProjectID, e.Aggregate().ID),
|
||||
@@ -345,9 +346,9 @@ func (p *appProjection) reduceAPIConfigAdded(event eventstore.Event) (*handler.S
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Y99aq", "reduce.wrong.event.type %s", project.APIConfigAddedType)
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddCreateStatement(
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(AppAPIConfigColumnAppID, e.AppID),
|
||||
handler.NewCol(AppAPIConfigColumnInstanceID, e.Aggregate().InstanceID),
|
||||
@@ -355,9 +356,9 @@ func (p *appProjection) reduceAPIConfigAdded(event eventstore.Event) (*handler.S
|
||||
handler.NewCol(AppAPIConfigColumnClientSecret, e.ClientSecret),
|
||||
handler.NewCol(AppAPIConfigColumnAuthMethod, e.AuthMethodType),
|
||||
},
|
||||
crdb.WithTableSuffix(appAPITableSuffix),
|
||||
handler.WithTableSuffix(appAPITableSuffix),
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(AppColumnSequence, e.Sequence()),
|
||||
@@ -383,19 +384,19 @@ func (p *appProjection) reduceAPIConfigChanged(event eventstore.Event) (*handler
|
||||
cols = append(cols, handler.NewCol(AppAPIConfigColumnAuthMethod, *e.AuthMethodType))
|
||||
}
|
||||
if len(cols) == 0 {
|
||||
return crdb.NewNoOpStatement(e), nil
|
||||
return handler.NewNoOpStatement(e), nil
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(AppAPIConfigColumnAppID, e.AppID),
|
||||
handler.NewCond(AppAPIConfigColumnInstanceID, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(appAPITableSuffix),
|
||||
handler.WithTableSuffix(appAPITableSuffix),
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(AppColumnSequence, e.Sequence()),
|
||||
@@ -413,9 +414,9 @@ func (p *appProjection) reduceAPIConfigSecretChanged(event eventstore.Event) (*h
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ttb0I", "reduce.wrong.event.type %s", project.APIConfigSecretChangedType)
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(AppAPIConfigColumnClientSecret, e.ClientSecret),
|
||||
},
|
||||
@@ -423,9 +424,9 @@ func (p *appProjection) reduceAPIConfigSecretChanged(event eventstore.Event) (*h
|
||||
handler.NewCond(AppAPIConfigColumnAppID, e.AppID),
|
||||
handler.NewCond(AppAPIConfigColumnInstanceID, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(appAPITableSuffix),
|
||||
handler.WithTableSuffix(appAPITableSuffix),
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(AppColumnSequence, e.Sequence()),
|
||||
@@ -443,33 +444,33 @@ func (p *appProjection) reduceOIDCConfigAdded(event eventstore.Event) (*handler.
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-GNHU1", "reduce.wrong.event.type %s", project.OIDCConfigAddedType)
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddCreateStatement(
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(AppOIDCConfigColumnAppID, e.AppID),
|
||||
handler.NewCol(AppOIDCConfigColumnInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCol(AppOIDCConfigColumnVersion, e.Version),
|
||||
handler.NewCol(AppOIDCConfigColumnClientID, e.ClientID),
|
||||
handler.NewCol(AppOIDCConfigColumnClientSecret, e.ClientSecret),
|
||||
handler.NewCol(AppOIDCConfigColumnRedirectUris, database.StringArray(e.RedirectUris)),
|
||||
handler.NewCol(AppOIDCConfigColumnResponseTypes, database.EnumArray[domain.OIDCResponseType](e.ResponseTypes)),
|
||||
handler.NewCol(AppOIDCConfigColumnGrantTypes, database.EnumArray[domain.OIDCGrantType](e.GrantTypes)),
|
||||
handler.NewCol(AppOIDCConfigColumnRedirectUris, database.TextArray[string](e.RedirectUris)),
|
||||
handler.NewCol(AppOIDCConfigColumnResponseTypes, database.Array[domain.OIDCResponseType](e.ResponseTypes)),
|
||||
handler.NewCol(AppOIDCConfigColumnGrantTypes, database.Array[domain.OIDCGrantType](e.GrantTypes)),
|
||||
handler.NewCol(AppOIDCConfigColumnApplicationType, e.ApplicationType),
|
||||
handler.NewCol(AppOIDCConfigColumnAuthMethodType, e.AuthMethodType),
|
||||
handler.NewCol(AppOIDCConfigColumnPostLogoutRedirectUris, database.StringArray(e.PostLogoutRedirectUris)),
|
||||
handler.NewCol(AppOIDCConfigColumnPostLogoutRedirectUris, database.TextArray[string](e.PostLogoutRedirectUris)),
|
||||
handler.NewCol(AppOIDCConfigColumnDevMode, e.DevMode),
|
||||
handler.NewCol(AppOIDCConfigColumnAccessTokenType, e.AccessTokenType),
|
||||
handler.NewCol(AppOIDCConfigColumnAccessTokenRoleAssertion, e.AccessTokenRoleAssertion),
|
||||
handler.NewCol(AppOIDCConfigColumnIDTokenRoleAssertion, e.IDTokenRoleAssertion),
|
||||
handler.NewCol(AppOIDCConfigColumnIDTokenUserinfoAssertion, e.IDTokenUserinfoAssertion),
|
||||
handler.NewCol(AppOIDCConfigColumnClockSkew, e.ClockSkew),
|
||||
handler.NewCol(AppOIDCConfigColumnAdditionalOrigins, database.StringArray(e.AdditionalOrigins)),
|
||||
handler.NewCol(AppOIDCConfigColumnAdditionalOrigins, database.TextArray[string](e.AdditionalOrigins)),
|
||||
handler.NewCol(AppOIDCConfigColumnSkipNativeAppSuccessPage, e.SkipNativeAppSuccessPage),
|
||||
},
|
||||
crdb.WithTableSuffix(appOIDCTableSuffix),
|
||||
handler.WithTableSuffix(appOIDCTableSuffix),
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(AppColumnSequence, e.Sequence()),
|
||||
@@ -493,13 +494,13 @@ func (p *appProjection) reduceOIDCConfigChanged(event eventstore.Event) (*handle
|
||||
cols = append(cols, handler.NewCol(AppOIDCConfigColumnVersion, *e.Version))
|
||||
}
|
||||
if e.RedirectUris != nil {
|
||||
cols = append(cols, handler.NewCol(AppOIDCConfigColumnRedirectUris, database.StringArray(*e.RedirectUris)))
|
||||
cols = append(cols, handler.NewCol(AppOIDCConfigColumnRedirectUris, database.TextArray[string](*e.RedirectUris)))
|
||||
}
|
||||
if e.ResponseTypes != nil {
|
||||
cols = append(cols, handler.NewCol(AppOIDCConfigColumnResponseTypes, database.EnumArray[domain.OIDCResponseType](*e.ResponseTypes)))
|
||||
cols = append(cols, handler.NewCol(AppOIDCConfigColumnResponseTypes, database.Array[domain.OIDCResponseType](*e.ResponseTypes)))
|
||||
}
|
||||
if e.GrantTypes != nil {
|
||||
cols = append(cols, handler.NewCol(AppOIDCConfigColumnGrantTypes, database.EnumArray[domain.OIDCGrantType](*e.GrantTypes)))
|
||||
cols = append(cols, handler.NewCol(AppOIDCConfigColumnGrantTypes, database.Array[domain.OIDCGrantType](*e.GrantTypes)))
|
||||
}
|
||||
if e.ApplicationType != nil {
|
||||
cols = append(cols, handler.NewCol(AppOIDCConfigColumnApplicationType, *e.ApplicationType))
|
||||
@@ -508,7 +509,7 @@ func (p *appProjection) reduceOIDCConfigChanged(event eventstore.Event) (*handle
|
||||
cols = append(cols, handler.NewCol(AppOIDCConfigColumnAuthMethodType, *e.AuthMethodType))
|
||||
}
|
||||
if e.PostLogoutRedirectUris != nil {
|
||||
cols = append(cols, handler.NewCol(AppOIDCConfigColumnPostLogoutRedirectUris, database.StringArray(*e.PostLogoutRedirectUris)))
|
||||
cols = append(cols, handler.NewCol(AppOIDCConfigColumnPostLogoutRedirectUris, database.TextArray[string](*e.PostLogoutRedirectUris)))
|
||||
}
|
||||
if e.DevMode != nil {
|
||||
cols = append(cols, handler.NewCol(AppOIDCConfigColumnDevMode, *e.DevMode))
|
||||
@@ -529,27 +530,27 @@ func (p *appProjection) reduceOIDCConfigChanged(event eventstore.Event) (*handle
|
||||
cols = append(cols, handler.NewCol(AppOIDCConfigColumnClockSkew, *e.ClockSkew))
|
||||
}
|
||||
if e.AdditionalOrigins != nil {
|
||||
cols = append(cols, handler.NewCol(AppOIDCConfigColumnAdditionalOrigins, database.StringArray(*e.AdditionalOrigins)))
|
||||
cols = append(cols, handler.NewCol(AppOIDCConfigColumnAdditionalOrigins, database.TextArray[string](*e.AdditionalOrigins)))
|
||||
}
|
||||
if e.SkipNativeAppSuccessPage != nil {
|
||||
cols = append(cols, handler.NewCol(AppOIDCConfigColumnSkipNativeAppSuccessPage, *e.SkipNativeAppSuccessPage))
|
||||
}
|
||||
|
||||
if len(cols) == 0 {
|
||||
return crdb.NewNoOpStatement(e), nil
|
||||
return handler.NewNoOpStatement(e), nil
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(AppOIDCConfigColumnAppID, e.AppID),
|
||||
handler.NewCond(AppOIDCConfigColumnInstanceID, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(appOIDCTableSuffix),
|
||||
handler.WithTableSuffix(appOIDCTableSuffix),
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(AppColumnSequence, e.Sequence()),
|
||||
@@ -567,9 +568,9 @@ func (p *appProjection) reduceOIDCConfigSecretChanged(event eventstore.Event) (*
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-GNHU1", "reduce.wrong.event.type %s", project.OIDCConfigSecretChangedType)
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(AppOIDCConfigColumnClientSecret, e.ClientSecret),
|
||||
},
|
||||
@@ -577,9 +578,9 @@ func (p *appProjection) reduceOIDCConfigSecretChanged(event eventstore.Event) (*
|
||||
handler.NewCond(AppOIDCConfigColumnAppID, e.AppID),
|
||||
handler.NewCond(AppOIDCConfigColumnInstanceID, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(appOIDCTableSuffix),
|
||||
handler.WithTableSuffix(appOIDCTableSuffix),
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(AppColumnSequence, e.Sequence()),
|
||||
@@ -598,7 +599,7 @@ func (p *appProjection) reduceOwnerRemoved(event eventstore.Event) (*handler.Sta
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Hyd1f", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(AppColumnInstanceID, e.Aggregate().InstanceID),
|
||||
@@ -612,9 +613,9 @@ func (p *appProjection) reduceSAMLConfigAdded(event eventstore.Event) (*handler.
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgument(nil, "HANDL-GMHU1", "reduce.wrong.event.type")
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddCreateStatement(
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(AppSAMLConfigColumnAppID, e.AppID),
|
||||
handler.NewCol(AppSAMLConfigColumnInstanceID, e.Aggregate().InstanceID),
|
||||
@@ -622,9 +623,9 @@ func (p *appProjection) reduceSAMLConfigAdded(event eventstore.Event) (*handler.
|
||||
handler.NewCol(AppSAMLConfigColumnMetadata, e.Metadata),
|
||||
handler.NewCol(AppSAMLConfigColumnMetadataURL, e.MetadataURL),
|
||||
},
|
||||
crdb.WithTableSuffix(appSAMLTableSuffix),
|
||||
handler.WithTableSuffix(appSAMLTableSuffix),
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(AppColumnSequence, e.Sequence()),
|
||||
@@ -655,20 +656,20 @@ func (p *appProjection) reduceSAMLConfigChanged(event eventstore.Event) (*handle
|
||||
}
|
||||
|
||||
if len(cols) == 0 {
|
||||
return crdb.NewNoOpStatement(e), nil
|
||||
return handler.NewNoOpStatement(e), nil
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(AppSAMLConfigColumnAppID, e.AppID),
|
||||
handler.NewCond(AppSAMLConfigColumnInstanceID, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(appSAMLTableSuffix),
|
||||
handler.WithTableSuffix(appSAMLTableSuffix),
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(AppColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(AppColumnSequence, e.Sequence()),
|
||||
|
||||
@@ -8,8 +8,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/project"
|
||||
@@ -28,20 +27,22 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project reduceAppAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ApplicationAddedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ApplicationAddedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"appId": "app-id",
|
||||
"name": "my-app"
|
||||
}`),
|
||||
), project.ApplicationAddedEventMapper),
|
||||
),
|
||||
project.ApplicationAddedEventMapper,
|
||||
),
|
||||
},
|
||||
reduce: (&appProjection{}).reduceAppAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -65,20 +66,20 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project reduceAppChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ApplicationChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ApplicationChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"appId": "app-id",
|
||||
"name": "my-app"
|
||||
}`),
|
||||
), project.ApplicationChangedEventMapper),
|
||||
), project.ApplicationChangedEventMapper),
|
||||
},
|
||||
reduce: (&appProjection{}).reduceAppChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -98,19 +99,19 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project reduceAppChanged no change",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ApplicationChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ApplicationChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"appId": "app-id"
|
||||
}`),
|
||||
), project.ApplicationChangedEventMapper),
|
||||
), project.ApplicationChangedEventMapper),
|
||||
},
|
||||
reduce: (&appProjection{}).reduceAppChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{},
|
||||
},
|
||||
@@ -119,19 +120,19 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project reduceAppDeactivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ApplicationDeactivatedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ApplicationDeactivatedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"appId": "app-id"
|
||||
}`),
|
||||
), project.ApplicationDeactivatedEventMapper),
|
||||
), project.ApplicationDeactivatedEventMapper),
|
||||
},
|
||||
reduce: (&appProjection{}).reduceAppDeactivated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -151,19 +152,19 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project reduceAppReactivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ApplicationReactivatedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ApplicationReactivatedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"appId": "app-id"
|
||||
}`),
|
||||
), project.ApplicationReactivatedEventMapper),
|
||||
), project.ApplicationReactivatedEventMapper),
|
||||
},
|
||||
reduce: (&appProjection{}).reduceAppReactivated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -183,19 +184,19 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project reduceAppRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ApplicationRemovedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ApplicationRemovedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"appId": "app-id"
|
||||
}`),
|
||||
), project.ApplicationRemovedEventMapper),
|
||||
), project.ApplicationRemovedEventMapper),
|
||||
},
|
||||
reduce: (&appProjection{}).reduceAppRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -212,17 +213,17 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project reduceProjectRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ProjectRemovedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), project.ProjectRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ProjectRemovedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), project.ProjectRemovedEventMapper),
|
||||
},
|
||||
reduce: (&appProjection{}).reduceProjectRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -239,17 +240,17 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(AppColumnInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -265,22 +266,22 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project reduceAPIConfigAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.APIConfigAddedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.APIConfigAddedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"appId": "app-id",
|
||||
"clientId": "client-id",
|
||||
"clientSecret": {},
|
||||
"authMethodType": 1
|
||||
}`),
|
||||
), project.APIConfigAddedEventMapper),
|
||||
), project.APIConfigAddedEventMapper),
|
||||
},
|
||||
reduce: (&appProjection{}).reduceAPIConfigAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -309,22 +310,22 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project reduceAPIConfigChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.APIConfigChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.APIConfigChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"appId": "app-id",
|
||||
"clientId": "client-id",
|
||||
"clientSecret": {},
|
||||
"authMethodType": 1
|
||||
}`),
|
||||
), project.APIConfigChangedEventMapper),
|
||||
), project.APIConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&appProjection{}).reduceAPIConfigChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -352,19 +353,19 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project reduceAPIConfigChanged noop",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.APIConfigChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.APIConfigChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"appId": "app-id"
|
||||
}`),
|
||||
), project.APIConfigChangedEventMapper),
|
||||
), project.APIConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&appProjection{}).reduceAPIConfigChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{},
|
||||
},
|
||||
@@ -373,20 +374,20 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project reduceAPIConfigSecretChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.APIConfigSecretChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.APIConfigSecretChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"appId": "app-id",
|
||||
"client_secret": {}
|
||||
}`),
|
||||
), project.APIConfigSecretChangedEventMapper),
|
||||
), project.APIConfigSecretChangedEventMapper),
|
||||
},
|
||||
reduce: (&appProjection{}).reduceAPIConfigSecretChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -413,10 +414,11 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project reduceOIDCConfigAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.OIDCConfigAddedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.OIDCConfigAddedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"oidcVersion": 0,
|
||||
"appId": "app-id",
|
||||
"clientId": "client-id",
|
||||
@@ -436,13 +438,12 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
"additionalOrigins": ["origin.one.ch", "origin.two.ch"],
|
||||
"skipNativeAppSuccessPage": true
|
||||
}`),
|
||||
), project.OIDCConfigAddedEventMapper),
|
||||
), project.OIDCConfigAddedEventMapper),
|
||||
},
|
||||
reduce: (&appProjection{}).reduceOIDCConfigAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -453,19 +454,19 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
domain.OIDCVersionV1,
|
||||
"client-id",
|
||||
anyArg{},
|
||||
database.StringArray{"redirect.one.ch", "redirect.two.ch"},
|
||||
database.EnumArray[domain.OIDCResponseType]{1, 2},
|
||||
database.EnumArray[domain.OIDCGrantType]{1, 2},
|
||||
database.TextArray[string]{"redirect.one.ch", "redirect.two.ch"},
|
||||
database.Array[domain.OIDCResponseType]{1, 2},
|
||||
database.Array[domain.OIDCGrantType]{1, 2},
|
||||
domain.OIDCApplicationTypeNative,
|
||||
domain.OIDCAuthMethodTypeNone,
|
||||
database.StringArray{"logout.one.ch", "logout.two.ch"},
|
||||
database.TextArray[string]{"logout.one.ch", "logout.two.ch"},
|
||||
true,
|
||||
domain.OIDCTokenTypeJWT,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
1 * time.Microsecond,
|
||||
database.StringArray{"origin.one.ch", "origin.two.ch"},
|
||||
database.TextArray[string]{"origin.one.ch", "origin.two.ch"},
|
||||
true,
|
||||
},
|
||||
},
|
||||
@@ -485,10 +486,11 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project reduceOIDCConfigChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.OIDCConfigChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.OIDCConfigChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"oidcVersion": 0,
|
||||
"appId": "app-id",
|
||||
"redirectUris": ["redirect.one.ch", "redirect.two.ch"],
|
||||
@@ -507,32 +509,31 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
"skipNativeAppSuccessPage": true
|
||||
|
||||
}`),
|
||||
), project.OIDCConfigChangedEventMapper),
|
||||
), project.OIDCConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&appProjection{}).reduceOIDCConfigChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.apps5_oidc_configs SET (version, redirect_uris, response_types, grant_types, application_type, auth_method_type, post_logout_redirect_uris, is_dev_mode, access_token_type, access_token_role_assertion, id_token_role_assertion, id_token_userinfo_assertion, clock_skew, additional_origins, skip_native_app_success_page) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) WHERE (app_id = $16) AND (instance_id = $17)",
|
||||
expectedArgs: []interface{}{
|
||||
domain.OIDCVersionV1,
|
||||
database.StringArray{"redirect.one.ch", "redirect.two.ch"},
|
||||
database.EnumArray[domain.OIDCResponseType]{1, 2},
|
||||
database.EnumArray[domain.OIDCGrantType]{1, 2},
|
||||
database.TextArray[string]{"redirect.one.ch", "redirect.two.ch"},
|
||||
database.Array[domain.OIDCResponseType]{1, 2},
|
||||
database.Array[domain.OIDCGrantType]{1, 2},
|
||||
domain.OIDCApplicationTypeNative,
|
||||
domain.OIDCAuthMethodTypeNone,
|
||||
database.StringArray{"logout.one.ch", "logout.two.ch"},
|
||||
database.TextArray[string]{"logout.one.ch", "logout.two.ch"},
|
||||
true,
|
||||
domain.OIDCTokenTypeJWT,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
1 * time.Microsecond,
|
||||
database.StringArray{"origin.one.ch", "origin.two.ch"},
|
||||
database.TextArray[string]{"origin.one.ch", "origin.two.ch"},
|
||||
true,
|
||||
"app-id",
|
||||
"instance-id",
|
||||
@@ -554,19 +555,19 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project reduceOIDCConfigChanged noop",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.OIDCConfigChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.OIDCConfigChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"appId": "app-id"
|
||||
}`),
|
||||
), project.OIDCConfigChangedEventMapper),
|
||||
), project.OIDCConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&appProjection{}).reduceOIDCConfigChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{},
|
||||
},
|
||||
@@ -575,20 +576,20 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project reduceOIDCConfigSecretChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.OIDCConfigSecretChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.OIDCConfigSecretChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"appId": "app-id",
|
||||
"client_secret": {}
|
||||
}`),
|
||||
), project.OIDCConfigSecretChangedEventMapper),
|
||||
), project.OIDCConfigSecretChangedEventMapper),
|
||||
},
|
||||
reduce: (&appProjection{}).reduceOIDCConfigSecretChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -615,17 +616,17 @@ func TestAppProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project.reduceOwnerRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
reduce: (&appProjection{}).reduceOwnerRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/authrequest"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
@@ -31,44 +31,46 @@ const (
|
||||
AuthRequestColumnHintUserID = "hint_user_id"
|
||||
)
|
||||
|
||||
type authRequestProjection struct {
|
||||
crdb.StatementHandler
|
||||
type authRequestProjection struct{}
|
||||
|
||||
// Name implements handler.Projection.
|
||||
func (*authRequestProjection) Name() string {
|
||||
return AuthRequestsProjectionTable
|
||||
}
|
||||
|
||||
func newAuthRequestProjection(ctx context.Context, config crdb.StatementHandlerConfig) *authRequestProjection {
|
||||
p := new(authRequestProjection)
|
||||
config.ProjectionName = AuthRequestsProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewMultiTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(AuthRequestColumnID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AuthRequestColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(AuthRequestColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(AuthRequestColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(AuthRequestColumnResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AuthRequestColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AuthRequestColumnLoginClient, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AuthRequestColumnClientID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AuthRequestColumnRedirectURI, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AuthRequestColumnScope, crdb.ColumnTypeTextArray),
|
||||
crdb.NewColumn(AuthRequestColumnPrompt, crdb.ColumnTypeEnumArray, crdb.Nullable()),
|
||||
crdb.NewColumn(AuthRequestColumnUILocales, crdb.ColumnTypeTextArray, crdb.Nullable()),
|
||||
crdb.NewColumn(AuthRequestColumnMaxAge, crdb.ColumnTypeInt64, crdb.Nullable()),
|
||||
crdb.NewColumn(AuthRequestColumnLoginHint, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(AuthRequestColumnHintUserID, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
func newAuthRequestProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(authRequestProjection))
|
||||
}
|
||||
|
||||
func (*authRequestProjection) Init() *old_handler.Check {
|
||||
return handler.NewMultiTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(AuthRequestColumnID, handler.ColumnTypeText),
|
||||
handler.NewColumn(AuthRequestColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(AuthRequestColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(AuthRequestColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(AuthRequestColumnResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(AuthRequestColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(AuthRequestColumnLoginClient, handler.ColumnTypeText),
|
||||
handler.NewColumn(AuthRequestColumnClientID, handler.ColumnTypeText),
|
||||
handler.NewColumn(AuthRequestColumnRedirectURI, handler.ColumnTypeText),
|
||||
handler.NewColumn(AuthRequestColumnScope, handler.ColumnTypeTextArray),
|
||||
handler.NewColumn(AuthRequestColumnPrompt, handler.ColumnTypeEnumArray, handler.Nullable()),
|
||||
handler.NewColumn(AuthRequestColumnUILocales, handler.ColumnTypeTextArray, handler.Nullable()),
|
||||
handler.NewColumn(AuthRequestColumnMaxAge, handler.ColumnTypeInt64, handler.Nullable()),
|
||||
handler.NewColumn(AuthRequestColumnLoginHint, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(AuthRequestColumnHintUserID, handler.ColumnTypeText, handler.Nullable()),
|
||||
},
|
||||
crdb.NewPrimaryKey(AuthRequestColumnInstanceID, AuthRequestColumnID),
|
||||
handler.NewPrimaryKey(AuthRequestColumnInstanceID, AuthRequestColumnID),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *authRequestProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *authRequestProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: authrequest.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: authrequest.AddedType,
|
||||
Reduce: p.reduceAuthRequestAdded,
|
||||
@@ -85,7 +87,7 @@ func (p *authRequestProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(AuthRequestColumnInstanceID),
|
||||
@@ -101,7 +103,7 @@ func (p *authRequestProjection) reduceAuthRequestAdded(event eventstore.Event) (
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Sfwfa", "reduce.wrong.event.type %s", authrequest.AddedType)
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(AuthRequestColumnID, e.Aggregate().ID),
|
||||
@@ -132,7 +134,7 @@ func (p *authRequestProjection) reduceAuthRequestEnded(event eventstore.Event) (
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ASF3h", "reduce.wrong.event.type %s", []eventstore.EventType{authrequest.SucceededType, authrequest.FailedType})
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
event,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(AuthRequestColumnID, event.Aggregate().ID),
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/authrequest"
|
||||
)
|
||||
|
||||
@@ -34,9 +34,8 @@ func TestAuthRequestProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&authRequestProjection{}).reduceAuthRequestAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("auth_request"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("auth_request"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -74,9 +73,8 @@ func TestAuthRequestProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&authRequestProjection{}).reduceAuthRequestEnded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("auth_request"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("auth_request"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -101,9 +99,8 @@ func TestAuthRequestProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&authRequestProjection{}).reduceAuthRequestEnded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("auth_request"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("auth_request"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/project"
|
||||
@@ -33,46 +33,47 @@ const (
|
||||
AuthNKeyOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type authNKeyProjection struct {
|
||||
crdb.StatementHandler
|
||||
type authNKeyProjection struct{}
|
||||
|
||||
func newAuthNKeyProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(authNKeyProjection))
|
||||
}
|
||||
|
||||
func newAuthNKeyProjection(ctx context.Context, config crdb.StatementHandlerConfig) *authNKeyProjection {
|
||||
p := new(authNKeyProjection)
|
||||
config.ProjectionName = AuthNKeyTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(AuthNKeyIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AuthNKeyCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(AuthNKeyChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(AuthNKeyResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AuthNKeyInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AuthNKeyAggregateIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AuthNKeySequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(AuthNKeyObjectIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AuthNKeyExpirationCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(AuthNKeyIdentifierCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AuthNKeyPublicKeyCol, crdb.ColumnTypeBytes),
|
||||
crdb.NewColumn(AuthNKeyEnabledCol, crdb.ColumnTypeBool, crdb.Default(true)),
|
||||
crdb.NewColumn(AuthNKeyTypeCol, crdb.ColumnTypeEnum, crdb.Default(0)),
|
||||
crdb.NewColumn(AuthNKeyOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*authNKeyProjection) Name() string {
|
||||
return AuthNKeyTable
|
||||
}
|
||||
|
||||
func (*authNKeyProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(AuthNKeyIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(AuthNKeyCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(AuthNKeyChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(AuthNKeyResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(AuthNKeyInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(AuthNKeyAggregateIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(AuthNKeySequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(AuthNKeyObjectIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(AuthNKeyExpirationCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(AuthNKeyIdentifierCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(AuthNKeyPublicKeyCol, handler.ColumnTypeBytes),
|
||||
handler.NewColumn(AuthNKeyEnabledCol, handler.ColumnTypeBool, handler.Default(true)),
|
||||
handler.NewColumn(AuthNKeyTypeCol, handler.ColumnTypeEnum, handler.Default(0)),
|
||||
handler.NewColumn(AuthNKeyOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(AuthNKeyInstanceIDCol, AuthNKeyIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("enabled", []string{AuthNKeyEnabledCol})),
|
||||
crdb.WithIndex(crdb.NewIndex("identifier", []string{AuthNKeyIdentifierCol})),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{AuthNKeyOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(AuthNKeyInstanceIDCol, AuthNKeyIDCol),
|
||||
handler.WithIndex(handler.NewIndex("enabled", []string{AuthNKeyEnabledCol})),
|
||||
handler.WithIndex(handler.NewIndex("identifier", []string{AuthNKeyIdentifierCol})),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{AuthNKeyOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *authNKeyProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *authNKeyProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: project.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: project.ApplicationKeyAddedEventType,
|
||||
Reduce: p.reduceAuthNKeyAdded,
|
||||
@@ -101,7 +102,7 @@ func (p *authNKeyProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: user.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: user.MachineKeyAddedEventType,
|
||||
Reduce: p.reduceAuthNKeyAdded,
|
||||
@@ -118,7 +119,7 @@ func (p *authNKeyProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.OrgRemovedEventType,
|
||||
Reduce: p.reduceOwnerRemoved,
|
||||
@@ -127,7 +128,7 @@ func (p *authNKeyProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(AuthNKeyInstanceIDCol),
|
||||
@@ -167,7 +168,7 @@ func (p *authNKeyProjection) reduceAuthNKeyAdded(event eventstore.Event) (*handl
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Dgb32", "reduce.wrong.event.type %v", []eventstore.EventType{project.ApplicationKeyAddedEventType, user.MachineKeyAddedEventType})
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
&authNKeyEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(AuthNKeyIDCol, authNKeyEvent.keyID),
|
||||
@@ -194,7 +195,7 @@ func (p *authNKeyProjection) reduceAuthNKeyEnabledChanged(event eventstore.Event
|
||||
switch e := event.(type) {
|
||||
case *project.APIConfigChangedEvent:
|
||||
if e.AuthMethodType == nil {
|
||||
return crdb.NewNoOpStatement(event), nil
|
||||
return handler.NewNoOpStatement(event), nil
|
||||
}
|
||||
appID = e.AppID
|
||||
enabled = *e.AuthMethodType == domain.APIAuthMethodTypePrivateKeyJWT
|
||||
@@ -202,7 +203,7 @@ func (p *authNKeyProjection) reduceAuthNKeyEnabledChanged(event eventstore.Event
|
||||
sequence = e.Sequence()
|
||||
case *project.OIDCConfigChangedEvent:
|
||||
if e.AuthMethodType == nil {
|
||||
return crdb.NewNoOpStatement(event), nil
|
||||
return handler.NewNoOpStatement(event), nil
|
||||
}
|
||||
appID = e.AppID
|
||||
enabled = *e.AuthMethodType == domain.OIDCAuthMethodTypePrivateKeyJWT
|
||||
@@ -211,7 +212,7 @@ func (p *authNKeyProjection) reduceAuthNKeyEnabledChanged(event eventstore.Event
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Dbrt1", "reduce.wrong.event.type %v", []eventstore.EventType{project.APIConfigChangedType, project.OIDCConfigChangedType})
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(AuthNKeyChangeDateCol, changeDate),
|
||||
@@ -241,7 +242,7 @@ func (p *authNKeyProjection) reduceAuthNKeyRemoved(event eventstore.Event) (*han
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-BGge42", "reduce.wrong.event.type %v", []eventstore.EventType{project.ApplicationKeyRemovedEventType, project.ApplicationRemovedType, project.ProjectRemovedType, user.MachineKeyRemovedEventType, user.UserRemovedType})
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
event,
|
||||
[]handler.Condition{
|
||||
condition,
|
||||
@@ -256,7 +257,7 @@ func (p *authNKeyProjection) reduceOwnerRemoved(event eventstore.Event) (*handle
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Hyd1f", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(AuthNKeyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/project"
|
||||
@@ -27,17 +26,17 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAuthNKeyAdded app",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ApplicationKeyAddedEventType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"applicationId": "appId", "clientId":"clientId","keyId": "keyId", "type": 1, "expirationDate": "2021-11-30T15:00:00Z", "publicKey": "cHVibGljS2V5"}`),
|
||||
), project.ApplicationKeyAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ApplicationKeyAddedEventType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"applicationId": "appId", "clientId":"clientId","keyId": "keyId", "type": 1, "expirationDate": "2021-11-30T15:00:00Z", "publicKey": "cHVibGljS2V5"}`),
|
||||
), project.ApplicationKeyAddedEventMapper),
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -64,17 +63,17 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAuthNKeyAdded user",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.MachineKeyAddedEventType),
|
||||
user.AggregateType,
|
||||
[]byte(`{"keyId": "keyId", "type": 1, "expirationDate": "2021-11-30T15:00:00Z", "publicKey": "cHVibGljS2V5"}`),
|
||||
), user.MachineKeyAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.MachineKeyAddedEventType,
|
||||
user.AggregateType,
|
||||
[]byte(`{"keyId": "keyId", "type": 1, "expirationDate": "2021-11-30T15:00:00Z", "publicKey": "cHVibGljS2V5"}`),
|
||||
), user.MachineKeyAddedEventMapper),
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("user"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("user"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -101,17 +100,17 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAuthNKeyRemoved app key",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ApplicationKeyRemovedEventType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"keyId": "keyId"}`),
|
||||
), project.ApplicationKeyRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ApplicationKeyRemovedEventType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"keyId": "keyId"}`),
|
||||
), project.ApplicationKeyRemovedEventMapper),
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -128,17 +127,17 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAuthNKeyEnabledChanged api no change",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.APIConfigChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"appId": "appId"}`),
|
||||
), project.APIConfigChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.APIConfigChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"appId": "appId"}`),
|
||||
), project.APIConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyEnabledChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{},
|
||||
},
|
||||
@@ -147,17 +146,17 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAuthNKeyEnabledChanged api config basic",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.APIConfigChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"appId": "appId", "authMethodType": 0}`),
|
||||
), project.APIConfigChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.APIConfigChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"appId": "appId", "authMethodType": 0}`),
|
||||
), project.APIConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyEnabledChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -177,17 +176,17 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAuthNKeyEnabledChanged api config jwt",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.APIConfigChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"appId": "appId", "authMethodType": 1}`),
|
||||
), project.APIConfigChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.APIConfigChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"appId": "appId", "authMethodType": 1}`),
|
||||
), project.APIConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyEnabledChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -207,17 +206,17 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAuthNKeyRemoved app key",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.MachineKeyRemovedEventType),
|
||||
user.AggregateType,
|
||||
[]byte(`{"keyId": "keyId"}`),
|
||||
), user.MachineKeyRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.MachineKeyRemovedEventType,
|
||||
user.AggregateType,
|
||||
[]byte(`{"keyId": "keyId"}`),
|
||||
), user.MachineKeyRemovedEventMapper),
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("user"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("user"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -234,17 +233,17 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(AuthNKeyInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -260,17 +259,17 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAuthNKeyEnabledChanged oidc no change",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.OIDCConfigChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"appId": "appId"}`),
|
||||
), project.OIDCConfigChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.OIDCConfigChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"appId": "appId"}`),
|
||||
), project.OIDCConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyEnabledChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{},
|
||||
},
|
||||
@@ -279,17 +278,17 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAuthNKeyEnabledChanged oidc config basic",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.OIDCConfigChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"appId": "appId", "authMethodType": 0}`),
|
||||
), project.OIDCConfigChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.OIDCConfigChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"appId": "appId", "authMethodType": 0}`),
|
||||
), project.OIDCConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyEnabledChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -309,17 +308,17 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAuthNKeyEnabledChanged oidc config jwt",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.OIDCConfigChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"appId": "appId", "authMethodType": 3}`),
|
||||
), project.OIDCConfigChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.OIDCConfigChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"appId": "appId", "authMethodType": 3}`),
|
||||
), project.OIDCConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyEnabledChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -339,17 +338,17 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAuthNKeyRemoved app key removed",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ApplicationKeyRemovedEventType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"keyId": "keyId"}`),
|
||||
), project.ApplicationKeyRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ApplicationKeyRemovedEventType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"keyId": "keyId"}`),
|
||||
), project.ApplicationKeyRemovedEventMapper),
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -366,17 +365,17 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAuthNKeyRemoved app removed",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ApplicationRemovedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"appId": "appId"}`),
|
||||
), project.ApplicationRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ApplicationRemovedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"appId": "appId"}`),
|
||||
), project.ApplicationRemovedEventMapper),
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -393,17 +392,17 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAuthNKeyRemoved project removed",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ProjectRemovedType),
|
||||
project.AggregateType,
|
||||
nil,
|
||||
), project.ProjectRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ProjectRemovedType,
|
||||
project.AggregateType,
|
||||
nil,
|
||||
), project.ProjectRemovedEventMapper),
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -420,17 +419,17 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAuthNKeyRemoved machine key removed",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.MachineKeyRemovedEventType),
|
||||
user.AggregateType,
|
||||
[]byte(`{"keyId": "keyId"}`),
|
||||
), user.MachineKeyRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.MachineKeyRemovedEventType,
|
||||
user.AggregateType,
|
||||
[]byte(`{"keyId": "keyId"}`),
|
||||
), user.MachineKeyRemovedEventMapper),
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("user"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("user"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -447,17 +446,17 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAuthNKeyRemoved user removed",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.UserRemovedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{"keyId": "keyId"}`),
|
||||
), user.UserRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.UserRemovedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{"keyId": "keyId"}`),
|
||||
), user.UserRemovedEventMapper),
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceAuthNKeyRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("user"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("user"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -474,17 +473,17 @@ func TestAuthNKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceOwnerRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
reduce: (&authNKeyProjection{}).reduceOwnerRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -7,18 +7,20 @@ import (
|
||||
type Config struct {
|
||||
RequeueEvery time.Duration
|
||||
RetryFailedAfter time.Duration
|
||||
MaxFailureCount uint
|
||||
MaxFailureCount uint8
|
||||
ConcurrentInstances uint
|
||||
BulkLimit uint64
|
||||
Customizations map[string]CustomConfig
|
||||
HandleActiveInstances time.Duration
|
||||
TransactionDuration time.Duration
|
||||
}
|
||||
|
||||
type CustomConfig struct {
|
||||
RequeueEvery *time.Duration
|
||||
RetryFailedAfter *time.Duration
|
||||
MaxFailureCount *uint
|
||||
MaxFailureCount *uint8
|
||||
ConcurrentInstances *uint
|
||||
BulkLimit *uint64
|
||||
BulkLimit *uint16
|
||||
HandleActiveInstances *time.Duration
|
||||
TransactionDuration *time.Duration
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
@@ -28,41 +28,42 @@ const (
|
||||
CustomTextOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type customTextProjection struct {
|
||||
crdb.StatementHandler
|
||||
type customTextProjection struct{}
|
||||
|
||||
func newCustomTextProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(customTextProjection))
|
||||
}
|
||||
|
||||
func newCustomTextProjection(ctx context.Context, config crdb.StatementHandlerConfig) *customTextProjection {
|
||||
p := new(customTextProjection)
|
||||
config.ProjectionName = CustomTextTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(CustomTextAggregateIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(CustomTextInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(CustomTextCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(CustomTextChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(CustomTextSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(CustomTextIsDefaultCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(CustomTextTemplateCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(CustomTextLanguageCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(CustomTextKeyCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(CustomTextTextCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(CustomTextOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*customTextProjection) Name() string {
|
||||
return CustomTextTable
|
||||
}
|
||||
|
||||
func (*customTextProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(CustomTextAggregateIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(CustomTextInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(CustomTextCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(CustomTextChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(CustomTextSequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(CustomTextIsDefaultCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(CustomTextTemplateCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(CustomTextLanguageCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(CustomTextKeyCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(CustomTextTextCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(CustomTextOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(CustomTextInstanceIDCol, CustomTextAggregateIDCol, CustomTextTemplateCol, CustomTextKeyCol, CustomTextLanguageCol),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{CustomTextOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(CustomTextInstanceIDCol, CustomTextAggregateIDCol, CustomTextTemplateCol, CustomTextKeyCol, CustomTextLanguageCol),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{CustomTextOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *customTextProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *customTextProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.CustomTextSetEventType,
|
||||
Reduce: p.reduceSet,
|
||||
@@ -83,7 +84,7 @@ func (p *customTextProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.CustomTextSetEventType,
|
||||
Reduce: p.reduceSet,
|
||||
@@ -118,7 +119,7 @@ func (p *customTextProjection) reduceSet(event eventstore.Event) (*handler.State
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-KKfw4", "reduce.wrong.event.type %v", []eventstore.EventType{org.CustomTextSetEventType, instance.CustomTextSetEventType})
|
||||
}
|
||||
return crdb.NewUpsertStatement(
|
||||
return handler.NewUpsertStatement(
|
||||
&customTextEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(CustomTextInstanceIDCol, nil),
|
||||
@@ -151,7 +152,7 @@ func (p *customTextProjection) reduceRemoved(event eventstore.Event) (*handler.S
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-n9wJg", "reduce.wrong.event.type %v", []eventstore.EventType{org.CustomTextRemovedEventType, instance.CustomTextRemovedEventType})
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
&customTextEvent,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(CustomTextAggregateIDCol, customTextEvent.Aggregate().ID),
|
||||
@@ -172,7 +173,7 @@ func (p *customTextProjection) reduceTemplateRemoved(event eventstore.Event) (*h
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-29iPf", "reduce.wrong.event.type %v", []eventstore.EventType{org.CustomTextTemplateRemovedEventType, instance.CustomTextTemplateRemovedEventType})
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
&customTextEvent,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(CustomTextAggregateIDCol, customTextEvent.Aggregate().ID),
|
||||
@@ -188,7 +189,7 @@ func (p *customTextProjection) reduceOwnerRemoved(event eventstore.Event) (*hand
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-V2T3z", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(CustomTextInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -5,8 +5,7 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -24,22 +23,22 @@ func TestCustomTextProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceSet",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.CustomTextSetEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.CustomTextSetEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Text",
|
||||
"language": "en",
|
||||
"template": "InitCode",
|
||||
"text": "Test"
|
||||
}`),
|
||||
), org.CustomTextSetEventMapper),
|
||||
), org.CustomTextSetEventMapper),
|
||||
},
|
||||
reduce: (&customTextProjection{}).reduceSet,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -65,20 +64,20 @@ func TestCustomTextProjection_reduces(t *testing.T) {
|
||||
name: "org reduceRemoved",
|
||||
reduce: (&customTextProjection{}).reduceRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.CustomTextRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.CustomTextRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Text",
|
||||
"language": "en",
|
||||
"template": "InitCode"
|
||||
}`),
|
||||
), org.CustomTextRemovedEventMapper),
|
||||
), org.CustomTextRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -99,20 +98,20 @@ func TestCustomTextProjection_reduces(t *testing.T) {
|
||||
name: "org reduceTemplateRemoved",
|
||||
reduce: (&customTextProjection{}).reduceTemplateRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.CustomTextTemplateRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.CustomTextTemplateRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Text",
|
||||
"language": "en",
|
||||
"template": "InitCode"
|
||||
}`),
|
||||
), org.CustomTextTemplateRemovedEventMapper),
|
||||
), org.CustomTextTemplateRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -131,17 +130,17 @@ func TestCustomTextProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(CustomTextInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -158,21 +157,21 @@ func TestCustomTextProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceAdded",
|
||||
reduce: (&customTextProjection{}).reduceSet,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.CustomTextSetEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.CustomTextSetEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Text",
|
||||
"language": "en",
|
||||
"template": "InitCode",
|
||||
"text": "Test"
|
||||
}`),
|
||||
), instance.CustomTextSetEventMapper),
|
||||
), instance.CustomTextSetEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -198,20 +197,20 @@ func TestCustomTextProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceRemoved",
|
||||
reduce: (&customTextProjection{}).reduceRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.CustomTextTemplateRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.CustomTextTemplateRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Text",
|
||||
"language": "en",
|
||||
"template": "InitCode"
|
||||
}`),
|
||||
), instance.CustomTextRemovedEventMapper),
|
||||
), instance.CustomTextRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -232,20 +231,20 @@ func TestCustomTextProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceTemplateRemoved",
|
||||
reduce: (&customTextProjection{}).reduceTemplateRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.CustomTextTemplateRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.CustomTextTemplateRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Text",
|
||||
"language": "en",
|
||||
"template": "InitCode"
|
||||
}`),
|
||||
), instance.CustomTextTemplateRemovedEventMapper),
|
||||
), instance.CustomTextTemplateRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -265,16 +264,16 @@ func TestCustomTextProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (&customTextProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
@@ -27,38 +27,39 @@ const (
|
||||
DebugNotificationProviderCompactCol = "compact"
|
||||
)
|
||||
|
||||
type debugNotificationProviderProjection struct {
|
||||
crdb.StatementHandler
|
||||
type debugNotificationProviderProjection struct{}
|
||||
|
||||
func newDebugNotificationProviderProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(debugNotificationProviderProjection))
|
||||
}
|
||||
|
||||
func newDebugNotificationProviderProjection(ctx context.Context, config crdb.StatementHandlerConfig) *debugNotificationProviderProjection {
|
||||
p := &debugNotificationProviderProjection{}
|
||||
config.ProjectionName = DebugNotificationProviderTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(DebugNotificationProviderAggIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(DebugNotificationProviderCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(DebugNotificationProviderChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(DebugNotificationProviderSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(DebugNotificationProviderResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(DebugNotificationProviderInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(DebugNotificationProviderStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(DebugNotificationProviderTypeCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(DebugNotificationProviderCompactCol, crdb.ColumnTypeBool),
|
||||
func (*debugNotificationProviderProjection) Name() string {
|
||||
return DebugNotificationProviderTable
|
||||
}
|
||||
|
||||
func (*debugNotificationProviderProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(DebugNotificationProviderAggIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(DebugNotificationProviderCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(DebugNotificationProviderChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(DebugNotificationProviderSequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(DebugNotificationProviderResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(DebugNotificationProviderInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(DebugNotificationProviderStateCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(DebugNotificationProviderTypeCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(DebugNotificationProviderCompactCol, handler.ColumnTypeBool),
|
||||
},
|
||||
crdb.NewPrimaryKey(DebugNotificationProviderInstanceIDCol, DebugNotificationProviderAggIDCol, DebugNotificationProviderTypeCol),
|
||||
handler.NewPrimaryKey(DebugNotificationProviderInstanceIDCol, DebugNotificationProviderAggIDCol, DebugNotificationProviderTypeCol),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *debugNotificationProviderProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *debugNotificationProviderProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.DebugNotificationProviderFileAddedEventType,
|
||||
Reduce: p.reduceDebugNotificationProviderAdded,
|
||||
@@ -106,7 +107,7 @@ func (p *debugNotificationProviderProjection) reduceDebugNotificationProviderAdd
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-pYPxS", "reduce.wrong.event.type %v", []eventstore.EventType{instance.DebugNotificationProviderFileAddedEventType, instance.DebugNotificationProviderLogAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(&providerEvent, []handler.Column{
|
||||
return handler.NewCreateStatement(&providerEvent, []handler.Column{
|
||||
handler.NewCol(DebugNotificationProviderAggIDCol, providerEvent.Aggregate().ID),
|
||||
handler.NewCol(DebugNotificationProviderCreationDateCol, providerEvent.CreationDate()),
|
||||
handler.NewCol(DebugNotificationProviderChangeDateCol, providerEvent.CreationDate()),
|
||||
@@ -141,7 +142,7 @@ func (p *debugNotificationProviderProjection) reduceDebugNotificationProviderCha
|
||||
cols = append(cols, handler.NewCol(DebugNotificationProviderCompactCol, *providerEvent.Compact))
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&providerEvent,
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
@@ -166,7 +167,7 @@ func (p *debugNotificationProviderProjection) reduceDebugNotificationProviderRem
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-dow9f", "reduce.wrong.event.type %v", []eventstore.EventType{instance.DebugNotificationProviderFileRemovedEventType, instance.DebugNotificationProviderLogRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
&providerEvent,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(DebugNotificationProviderAggIDCol, providerEvent.Aggregate().ID),
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
@@ -25,18 +24,18 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceNotificationProviderFileAdded",
|
||||
reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderAdded,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.DebugNotificationProviderFileAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.DebugNotificationProviderFileAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"compact": true
|
||||
}`),
|
||||
), instance.DebugNotificationProviderFileAddedEventMapper),
|
||||
), instance.DebugNotificationProviderFileAddedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -61,18 +60,18 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceNotificationProviderFileChanged",
|
||||
reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderChanged,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.DebugNotificationProviderFileChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.DebugNotificationProviderFileChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"compact": true
|
||||
}`),
|
||||
), instance.DebugNotificationProviderFileChangedEventMapper),
|
||||
), instance.DebugNotificationProviderFileChangedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -94,16 +93,16 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceNotificationProviderFileRemoved",
|
||||
reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.DebugNotificationProviderFileRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.DebugNotificationProviderFileRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.DebugNotificationProviderFileRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.DebugNotificationProviderFileRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -122,18 +121,18 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceNotificationProviderLogAdded",
|
||||
reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderAdded,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.DebugNotificationProviderLogAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.DebugNotificationProviderLogAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"compact": true
|
||||
}`),
|
||||
), instance.DebugNotificationProviderLogAddedEventMapper),
|
||||
), instance.DebugNotificationProviderLogAddedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -158,18 +157,18 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceNotificationProviderLogChanged",
|
||||
reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderChanged,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.DebugNotificationProviderLogChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.DebugNotificationProviderLogChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"compact": true
|
||||
}`),
|
||||
), instance.DebugNotificationProviderLogChangedEventMapper),
|
||||
), instance.DebugNotificationProviderLogChangedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -191,16 +190,16 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceNotificationProviderLogRemoved",
|
||||
reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.DebugNotificationProviderLogRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.DebugNotificationProviderLogRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.DebugNotificationProviderLogRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.DebugNotificationProviderLogRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -218,17 +217,17 @@ func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(DebugNotificationProviderInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/deviceauth"
|
||||
)
|
||||
|
||||
@@ -29,44 +29,44 @@ const (
|
||||
DeviceAuthColumnInstanceID = "instance_id"
|
||||
)
|
||||
|
||||
type deviceAuthProjection struct {
|
||||
crdb.StatementHandler
|
||||
type deviceAuthProjection struct{}
|
||||
|
||||
func newDeviceAuthProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(deviceAuthProjection))
|
||||
}
|
||||
|
||||
func newDeviceAuthProjection(ctx context.Context, config crdb.StatementHandlerConfig) *deviceAuthProjection {
|
||||
p := new(deviceAuthProjection)
|
||||
config.ProjectionName = DeviceAuthProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(DeviceAuthColumnID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(DeviceAuthColumnClientID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(DeviceAuthColumnDeviceCode, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(DeviceAuthColumnUserCode, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(DeviceAuthColumnExpires, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(DeviceAuthColumnScopes, crdb.ColumnTypeTextArray),
|
||||
crdb.NewColumn(DeviceAuthColumnState, crdb.ColumnTypeEnum, crdb.Default(domain.DeviceAuthStateInitiated)),
|
||||
crdb.NewColumn(DeviceAuthColumnSubject, crdb.ColumnTypeText, crdb.Default("")),
|
||||
crdb.NewColumn(DeviceAuthColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(DeviceAuthColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(DeviceAuthColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(DeviceAuthColumnInstanceID, crdb.ColumnTypeText),
|
||||
func (*deviceAuthProjection) Name() string {
|
||||
return DeviceAuthProjectionTable
|
||||
}
|
||||
|
||||
func (*deviceAuthProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(DeviceAuthColumnID, handler.ColumnTypeText),
|
||||
handler.NewColumn(DeviceAuthColumnClientID, handler.ColumnTypeText),
|
||||
handler.NewColumn(DeviceAuthColumnDeviceCode, handler.ColumnTypeText),
|
||||
handler.NewColumn(DeviceAuthColumnUserCode, handler.ColumnTypeText),
|
||||
handler.NewColumn(DeviceAuthColumnExpires, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(DeviceAuthColumnScopes, handler.ColumnTypeTextArray),
|
||||
handler.NewColumn(DeviceAuthColumnState, handler.ColumnTypeEnum, handler.Default(domain.DeviceAuthStateInitiated)),
|
||||
handler.NewColumn(DeviceAuthColumnSubject, handler.ColumnTypeText, handler.Default("")),
|
||||
handler.NewColumn(DeviceAuthColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(DeviceAuthColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(DeviceAuthColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(DeviceAuthColumnInstanceID, handler.ColumnTypeText),
|
||||
},
|
||||
crdb.NewPrimaryKey(DeviceAuthColumnInstanceID, DeviceAuthColumnID),
|
||||
crdb.WithIndex(crdb.NewIndex("user_code", []string{DeviceAuthColumnInstanceID, DeviceAuthColumnUserCode})),
|
||||
crdb.WithIndex(crdb.NewIndex("device_code", []string{DeviceAuthColumnInstanceID, DeviceAuthColumnClientID, DeviceAuthColumnDeviceCode})),
|
||||
handler.NewPrimaryKey(DeviceAuthColumnInstanceID, DeviceAuthColumnID),
|
||||
handler.WithIndex(handler.NewIndex("user_code", []string{DeviceAuthColumnInstanceID, DeviceAuthColumnUserCode})),
|
||||
handler.WithIndex(handler.NewIndex("device_code", []string{DeviceAuthColumnInstanceID, DeviceAuthColumnClientID, DeviceAuthColumnDeviceCode})),
|
||||
),
|
||||
)
|
||||
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *deviceAuthProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *deviceAuthProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: deviceauth.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: deviceauth.AddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -93,7 +93,7 @@ func (p *deviceAuthProjection) reduceAdded(event eventstore.Event) (*handler.Sta
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-chu6O", "reduce.wrong.event.type %T != %s", event, deviceauth.AddedEventType)
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(DeviceAuthColumnID, e.Aggregate().ID),
|
||||
@@ -115,7 +115,7 @@ func (p *deviceAuthProjection) reduceAppoved(event eventstore.Event) (*handler.S
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-kei0A", "reduce.wrong.event.type %T != %s", event, deviceauth.ApprovedEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(e,
|
||||
return handler.NewUpdateStatement(e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(DeviceAuthColumnState, domain.DeviceAuthStateApproved),
|
||||
handler.NewCol(DeviceAuthColumnSubject, e.Subject),
|
||||
@@ -134,7 +134,7 @@ func (p *deviceAuthProjection) reduceCanceled(event eventstore.Event) (*handler.
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-eeS8d", "reduce.wrong.event.type %T != %s", event, deviceauth.CanceledEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(e,
|
||||
return handler.NewUpdateStatement(e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(DeviceAuthColumnState, e.Reason.State()),
|
||||
handler.NewCol(DeviceAuthColumnChangeDate, e.CreationDate()),
|
||||
@@ -152,7 +152,7 @@ func (p *deviceAuthProjection) reduceRemoved(event eventstore.Event) (*handler.S
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-AJi1u", "reduce.wrong.event.type %T != %s", event, deviceauth.RemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(e,
|
||||
return handler.NewDeleteStatement(e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(DeviceAuthColumnInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCond(DeviceAuthColumnID, e.Aggregate().ID),
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
@@ -30,42 +30,43 @@ const (
|
||||
DomainPolicyOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type domainPolicyProjection struct {
|
||||
crdb.StatementHandler
|
||||
type domainPolicyProjection struct{}
|
||||
|
||||
func newDomainPolicyProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(domainPolicyProjection))
|
||||
}
|
||||
|
||||
func newDomainPolicyProjection(ctx context.Context, config crdb.StatementHandlerConfig) *domainPolicyProjection {
|
||||
p := new(domainPolicyProjection)
|
||||
config.ProjectionName = DomainPolicyTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(DomainPolicyIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(DomainPolicyCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(DomainPolicyChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(DomainPolicySequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(DomainPolicyStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(DomainPolicyUserLoginMustBeDomainCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(DomainPolicyValidateOrgDomainsCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(DomainPolicySMTPSenderAddressMatchesInstanceDomainCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(DomainPolicyIsDefaultCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(DomainPolicyResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(DomainPolicyInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(DomainPolicyOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*domainPolicyProjection) Name() string {
|
||||
return DomainPolicyTable
|
||||
}
|
||||
|
||||
func (*domainPolicyProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(DomainPolicyIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(DomainPolicyCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(DomainPolicyChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(DomainPolicySequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(DomainPolicyStateCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(DomainPolicyUserLoginMustBeDomainCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(DomainPolicyValidateOrgDomainsCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(DomainPolicySMTPSenderAddressMatchesInstanceDomainCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(DomainPolicyIsDefaultCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(DomainPolicyResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(DomainPolicyInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(DomainPolicyOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(DomainPolicyInstanceIDCol, DomainPolicyIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{DomainPolicyOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(DomainPolicyInstanceIDCol, DomainPolicyIDCol),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{DomainPolicyOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *domainPolicyProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *domainPolicyProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.DomainPolicyAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -86,7 +87,7 @@ func (p *domainPolicyProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.DomainPolicyAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -117,7 +118,7 @@ func (p *domainPolicyProjection) reduceAdded(event eventstore.Event) (*handler.S
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-CSE7A", "reduce.wrong.event.type %v", []eventstore.EventType{org.DomainPolicyAddedEventType, instance.DomainPolicyAddedEventType})
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
&policyEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(DomainPolicyCreationDateCol, policyEvent.CreationDate()),
|
||||
@@ -157,7 +158,7 @@ func (p *domainPolicyProjection) reduceChanged(event eventstore.Event) (*handler
|
||||
if policyEvent.SMTPSenderAddressMatchesInstanceDomain != nil {
|
||||
cols = append(cols, handler.NewCol(DomainPolicySMTPSenderAddressMatchesInstanceDomainCol, *policyEvent.SMTPSenderAddressMatchesInstanceDomain))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&policyEvent,
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
@@ -171,7 +172,7 @@ func (p *domainPolicyProjection) reduceRemoved(event eventstore.Event) (*handler
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-JAENd", "reduce.wrong.event.type %s", org.DomainPolicyRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
policyEvent,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(DomainPolicyIDCol, policyEvent.Aggregate().ID),
|
||||
@@ -185,7 +186,7 @@ func (p *domainPolicyProjection) reduceOwnerRemoved(event eventstore.Event) (*ha
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-JYD2K", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(DomainPolicyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -25,21 +24,21 @@ func TestDomainPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.DomainPolicyAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.DomainPolicyAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"userLoginMustBeDomain": true,
|
||||
"validateOrgDomains": true,
|
||||
"smtpSenderAddressMatchesInstanceDomain": true
|
||||
}`),
|
||||
), org.DomainPolicyAddedEventMapper),
|
||||
), org.DomainPolicyAddedEventMapper),
|
||||
},
|
||||
reduce: (&domainPolicyProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -66,20 +65,20 @@ func TestDomainPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org reduceChanged",
|
||||
reduce: (&domainPolicyProjection{}).reduceChanged,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.DomainPolicyChangedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.DomainPolicyChangedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"userLoginMustBeDomain": true,
|
||||
"validateOrgDomains": true,
|
||||
"smtpSenderAddressMatchesInstanceDomain": true
|
||||
}`),
|
||||
), org.DomainPolicyChangedEventMapper),
|
||||
), org.DomainPolicyChangedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -102,16 +101,16 @@ func TestDomainPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org reduceRemoved",
|
||||
reduce: (&domainPolicyProjection{}).reduceRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.DomainPolicyRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.DomainPolicyRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.DomainPolicyRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.DomainPolicyRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -128,17 +127,17 @@ func TestDomainPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(DomainPolicyInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -155,20 +154,20 @@ func TestDomainPolicyProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceAdded",
|
||||
reduce: (&domainPolicyProjection{}).reduceAdded,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.DomainPolicyAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.DomainPolicyAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"userLoginMustBeDomain": true,
|
||||
"validateOrgDomains": true,
|
||||
"smtpSenderAddressMatchesInstanceDomain": true
|
||||
}`),
|
||||
), instance.DomainPolicyAddedEventMapper),
|
||||
), instance.DomainPolicyAddedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -195,20 +194,20 @@ func TestDomainPolicyProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceChanged",
|
||||
reduce: (&domainPolicyProjection{}).reduceChanged,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.DomainPolicyChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.DomainPolicyChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"userLoginMustBeDomain": true,
|
||||
"validateOrgDomains": true,
|
||||
"smtpSenderAddressMatchesInstanceDomain": true
|
||||
}`),
|
||||
), instance.DomainPolicyChangedEventMapper),
|
||||
), instance.DomainPolicyChangedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -231,16 +230,16 @@ func TestDomainPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (&domainPolicyProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -6,44 +6,41 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
)
|
||||
|
||||
func testEvent(
|
||||
eventType repository.EventType,
|
||||
aggregateType repository.AggregateType,
|
||||
eventType eventstore.EventType,
|
||||
aggregateType eventstore.AggregateType,
|
||||
data []byte,
|
||||
) *repository.Event {
|
||||
return timedTestEvent(eventType, aggregateType, data, time.Now())
|
||||
}
|
||||
|
||||
func toSystemEvent(event *repository.Event) *repository.Event {
|
||||
event.EditorService = "SYSTEM"
|
||||
event.EditorUser = "SYSTEM"
|
||||
return event
|
||||
}
|
||||
|
||||
func timedTestEvent(
|
||||
eventType repository.EventType,
|
||||
aggregateType repository.AggregateType,
|
||||
eventType eventstore.EventType,
|
||||
aggregateType eventstore.AggregateType,
|
||||
data []byte,
|
||||
creationDate time.Time,
|
||||
) *repository.Event {
|
||||
return &repository.Event{
|
||||
Sequence: 15,
|
||||
PreviousAggregateSequence: 10,
|
||||
PreviousAggregateTypeSequence: 10,
|
||||
CreationDate: creationDate,
|
||||
Type: eventType,
|
||||
AggregateType: aggregateType,
|
||||
Data: data,
|
||||
Version: "v1",
|
||||
AggregateID: "agg-id",
|
||||
ResourceOwner: sql.NullString{String: "ro-id", Valid: true},
|
||||
InstanceID: "instance-id",
|
||||
ID: "event-id",
|
||||
EditorService: "editor-svc",
|
||||
EditorUser: "editor-user",
|
||||
Seq: 15,
|
||||
CreationDate: creationDate,
|
||||
Typ: eventType,
|
||||
AggregateType: aggregateType,
|
||||
Data: data,
|
||||
Version: "v1",
|
||||
AggregateID: "agg-id",
|
||||
ResourceOwner: sql.NullString{String: "ro-id", Valid: true},
|
||||
InstanceID: "instance-id",
|
||||
ID: "event-id",
|
||||
EditorUser: "editor-user",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +48,7 @@ func baseEvent(*testing.T) eventstore.Event {
|
||||
return &eventstore.BaseEvent{}
|
||||
}
|
||||
|
||||
func getEvent(event *repository.Event, mapper func(*repository.Event) (eventstore.Event, error)) func(t *testing.T) eventstore.Event {
|
||||
func getEvent(event *repository.Event, mapper func(eventstore.Event) (eventstore.Event, error)) func(t *testing.T) eventstore.Event {
|
||||
return func(t *testing.T) eventstore.Event {
|
||||
e, err := mapper(event)
|
||||
if err != nil {
|
||||
@@ -62,11 +59,10 @@ func getEvent(event *repository.Event, mapper func(*repository.Event) (eventstor
|
||||
}
|
||||
|
||||
type wantReduce struct {
|
||||
aggregateType eventstore.AggregateType
|
||||
sequence uint64
|
||||
previousSequence uint64
|
||||
executer *testExecuter
|
||||
err func(error) bool
|
||||
aggregateType eventstore.AggregateType
|
||||
sequence uint64
|
||||
executer *testExecuter
|
||||
err func(error) bool
|
||||
}
|
||||
|
||||
func assertReduce(t *testing.T, stmt *handler.Statement, err error, projection string, want wantReduce) {
|
||||
@@ -82,10 +78,6 @@ func assertReduce(t *testing.T, stmt *handler.Statement, err error, projection s
|
||||
t.Errorf("wrong aggregate type: want: %q got: %q", want.aggregateType, stmt.AggregateType)
|
||||
}
|
||||
|
||||
if stmt.PreviousSequence != want.previousSequence {
|
||||
t.Errorf("wrong previous sequence: want: %d got: %d", want.previousSequence, stmt.PreviousSequence)
|
||||
}
|
||||
|
||||
if stmt.Sequence != want.sequence {
|
||||
t.Errorf("wrong sequence: want: %d got: %d", want.sequence, stmt.Sequence)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package projection
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
)
|
||||
|
||||
var _ handler.EventStore = (*mockEventStore)(nil)
|
||||
|
||||
type mockEventStore struct {
|
||||
instanceIDsResponse [][]string
|
||||
instanceIDCounter int
|
||||
filterResponse [][]eventstore.Event
|
||||
filterCounter int
|
||||
pushResponse [][]eventstore.Event
|
||||
pushCounter int
|
||||
}
|
||||
|
||||
func newMockEventStore() *mockEventStore {
|
||||
return new(mockEventStore)
|
||||
}
|
||||
|
||||
func (m *mockEventStore) appendFilterResponse(events []eventstore.Event) *mockEventStore {
|
||||
m.filterResponse = append(m.filterResponse, events)
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *mockEventStore) InstanceIDs(ctx context.Context, _ time.Duration, _ bool, query *eventstore.SearchQueryBuilder) ([]string, error) {
|
||||
m.instanceIDCounter++
|
||||
return m.instanceIDsResponse[m.instanceIDCounter-1], nil
|
||||
}
|
||||
|
||||
func (m *mockEventStore) Filter(ctx context.Context, queryFactory *eventstore.SearchQueryBuilder) ([]eventstore.Event, error) {
|
||||
m.filterCounter++
|
||||
return m.filterResponse[m.filterCounter-1], nil
|
||||
}
|
||||
|
||||
func (m *mockEventStore) Push(ctx context.Context, cmds ...eventstore.Command) ([]eventstore.Event, error) {
|
||||
m.pushCounter++
|
||||
return m.pushResponse[m.pushCounter-1], nil
|
||||
}
|
||||
@@ -25,6 +25,10 @@ type execution struct {
|
||||
type anyArg struct{}
|
||||
|
||||
func (e *testExecuter) Exec(stmt string, args ...interface{}) (sql.Result, error) {
|
||||
if stmt == "SAVEPOINT stmt_exec" || stmt == "RELEASE SAVEPOINT stmt_exec" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if e.execIdx >= len(e.executions) {
|
||||
return nil, errors.ThrowInternal(nil, "PROJE-8TNoE", "too many executions")
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -24,39 +24,40 @@ const (
|
||||
FlowOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type flowProjection struct {
|
||||
crdb.StatementHandler
|
||||
type flowProjection struct{}
|
||||
|
||||
func newFlowProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(flowProjection))
|
||||
}
|
||||
|
||||
func newFlowProjection(ctx context.Context, config crdb.StatementHandlerConfig) *flowProjection {
|
||||
p := new(flowProjection)
|
||||
config.ProjectionName = FlowTriggerTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(FlowTypeCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(FlowChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(FlowSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(FlowTriggerTypeCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(FlowResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(FlowInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(FlowActionTriggerSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(FlowActionIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(FlowOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*flowProjection) Name() string {
|
||||
return FlowTriggerTable
|
||||
}
|
||||
|
||||
func (*flowProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(FlowTypeCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(FlowChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(FlowSequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(FlowTriggerTypeCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(FlowResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(FlowInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(FlowActionTriggerSequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(FlowActionIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(FlowOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(FlowInstanceIDCol, FlowTypeCol, FlowTriggerTypeCol, FlowResourceOwnerCol, FlowActionIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{FlowOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(FlowInstanceIDCol, FlowTypeCol, FlowTriggerTypeCol, FlowResourceOwnerCol, FlowActionIDCol),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{FlowOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *flowProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *flowProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.TriggerActionsSetEventType,
|
||||
Reduce: p.reduceTriggerActionsSetEventType,
|
||||
@@ -73,7 +74,7 @@ func (p *flowProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(FlowInstanceIDCol),
|
||||
@@ -88,8 +89,8 @@ func (p *flowProjection) reduceTriggerActionsSetEventType(event eventstore.Event
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-uYq4r", "reduce.wrong.event.type %s", org.TriggerActionsSetEventType)
|
||||
}
|
||||
stmts := make([]func(reader eventstore.Event) crdb.Exec, len(e.ActionIDs)+1)
|
||||
stmts[0] = crdb.AddDeleteStatement(
|
||||
stmts := make([]func(reader eventstore.Event) handler.Exec, len(e.ActionIDs)+1)
|
||||
stmts[0] = handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(FlowTypeCol, e.FlowType),
|
||||
handler.NewCond(FlowTriggerTypeCol, e.TriggerType),
|
||||
@@ -98,7 +99,7 @@ func (p *flowProjection) reduceTriggerActionsSetEventType(event eventstore.Event
|
||||
},
|
||||
)
|
||||
for i, id := range e.ActionIDs {
|
||||
stmts[i+1] = crdb.AddCreateStatement(
|
||||
stmts[i+1] = handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(FlowResourceOwnerCol, e.Aggregate().ResourceOwner),
|
||||
handler.NewCol(FlowInstanceIDCol, e.Aggregate().InstanceID),
|
||||
@@ -111,7 +112,7 @@ func (p *flowProjection) reduceTriggerActionsSetEventType(event eventstore.Event
|
||||
},
|
||||
)
|
||||
}
|
||||
return crdb.NewMultiStatement(e, stmts...), nil
|
||||
return handler.NewMultiStatement(e, stmts...), nil
|
||||
}
|
||||
|
||||
func (p *flowProjection) reduceFlowClearedEventType(event eventstore.Event) (*handler.Statement, error) {
|
||||
@@ -119,7 +120,7 @@ func (p *flowProjection) reduceFlowClearedEventType(event eventstore.Event) (*ha
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-uYq4r", "reduce.wrong.event.type %s", org.FlowClearedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(FlowTypeCol, e.FlowType),
|
||||
@@ -135,7 +136,7 @@ func (p *flowProjection) reduceOwnerRemoved(event eventstore.Event) (*handler.St
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Yd7WC", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(FlowInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -25,17 +24,17 @@ func TestFlowProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceTriggerActionsSetEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.TriggerActionsSetEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"flowType": 1, "triggerType": 1, "actionIDs": ["id1", "id2"]}`),
|
||||
), org.TriggerActionsSetEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.TriggerActionsSetEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"flowType": 1, "triggerType": 1, "actionIDs": ["id1", "id2"]}`),
|
||||
), org.TriggerActionsSetEventMapper),
|
||||
},
|
||||
reduce: (&flowProjection{}).reduceTriggerActionsSetEventType,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -80,17 +79,17 @@ func TestFlowProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceFlowClearedEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.FlowClearedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"flowType": 1}`),
|
||||
), org.FlowClearedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.FlowClearedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"flowType": 1}`),
|
||||
), org.FlowClearedEventMapper),
|
||||
},
|
||||
reduce: (&flowProjection{}).reduceFlowClearedEventType,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -109,16 +108,16 @@ func TestFlowProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (&flowProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -135,17 +134,17 @@ func TestFlowProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(FlowInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/idpconfig"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
@@ -55,72 +55,73 @@ const (
|
||||
JWTConfigEndpointCol = "endpoint"
|
||||
)
|
||||
|
||||
type idpProjection struct {
|
||||
crdb.StatementHandler
|
||||
type idpProjection struct{}
|
||||
|
||||
func newIDPProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(idpProjection))
|
||||
}
|
||||
|
||||
func newIDPProjection(ctx context.Context, config crdb.StatementHandlerConfig) *idpProjection {
|
||||
p := new(idpProjection)
|
||||
config.ProjectionName = IDPTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewMultiTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(IDPIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(IDPChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(IDPSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(IDPResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(IDPNameCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPStylingTypeCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(IDPOwnerTypeCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(IDPAutoRegisterCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(IDPTypeCol, crdb.ColumnTypeEnum, crdb.Nullable()),
|
||||
crdb.NewColumn(IDPOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*idpProjection) Name() string {
|
||||
return IDPTable
|
||||
}
|
||||
|
||||
func (*idpProjection) Init() *old_handler.Check {
|
||||
return handler.NewMultiTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(IDPIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(IDPCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(IDPChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(IDPSequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(IDPResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(IDPInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(IDPStateCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(IDPNameCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(IDPStylingTypeCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(IDPOwnerTypeCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(IDPAutoRegisterCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(IDPTypeCol, handler.ColumnTypeEnum, handler.Nullable()),
|
||||
handler.NewColumn(IDPOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(IDPInstanceIDCol, IDPIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("resource_owner", []string{IDPResourceOwnerCol})),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{IDPOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(IDPInstanceIDCol, IDPIDCol),
|
||||
handler.WithIndex(handler.NewIndex("resource_owner", []string{IDPResourceOwnerCol})),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{IDPOwnerRemovedCol})),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(OIDCConfigIDPIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OIDCConfigInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OIDCConfigClientIDCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(OIDCConfigClientSecretCol, crdb.ColumnTypeJSONB, crdb.Nullable()),
|
||||
crdb.NewColumn(OIDCConfigIssuerCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(OIDCConfigScopesCol, crdb.ColumnTypeTextArray, crdb.Nullable()),
|
||||
crdb.NewColumn(OIDCConfigDisplayNameMappingCol, crdb.ColumnTypeEnum, crdb.Nullable()),
|
||||
crdb.NewColumn(OIDCConfigUsernameMappingCol, crdb.ColumnTypeEnum, crdb.Nullable()),
|
||||
crdb.NewColumn(OIDCConfigAuthorizationEndpointCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(OIDCConfigTokenEndpointCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
handler.NewSuffixedTable([]*handler.InitColumn{
|
||||
handler.NewColumn(OIDCConfigIDPIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(OIDCConfigInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(OIDCConfigClientIDCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(OIDCConfigClientSecretCol, handler.ColumnTypeJSONB, handler.Nullable()),
|
||||
handler.NewColumn(OIDCConfigIssuerCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(OIDCConfigScopesCol, handler.ColumnTypeTextArray, handler.Nullable()),
|
||||
handler.NewColumn(OIDCConfigDisplayNameMappingCol, handler.ColumnTypeEnum, handler.Nullable()),
|
||||
handler.NewColumn(OIDCConfigUsernameMappingCol, handler.ColumnTypeEnum, handler.Nullable()),
|
||||
handler.NewColumn(OIDCConfigAuthorizationEndpointCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(OIDCConfigTokenEndpointCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
},
|
||||
crdb.NewPrimaryKey(OIDCConfigInstanceIDCol, OIDCConfigIDPIDCol),
|
||||
handler.NewPrimaryKey(OIDCConfigInstanceIDCol, OIDCConfigIDPIDCol),
|
||||
IDPOIDCSuffix,
|
||||
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
|
||||
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(JWTConfigIDPIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(JWTConfigInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(JWTConfigIssuerCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(JWTConfigKeysEndpointCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(JWTConfigHeaderNameCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(JWTConfigEndpointCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
handler.NewSuffixedTable([]*handler.InitColumn{
|
||||
handler.NewColumn(JWTConfigIDPIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(JWTConfigInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(JWTConfigIssuerCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(JWTConfigKeysEndpointCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(JWTConfigHeaderNameCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(JWTConfigEndpointCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
},
|
||||
crdb.NewPrimaryKey(JWTConfigInstanceIDCol, JWTConfigIDPIDCol),
|
||||
handler.NewPrimaryKey(JWTConfigInstanceIDCol, JWTConfigIDPIDCol),
|
||||
IDPJWTSuffix,
|
||||
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
|
||||
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *idpProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *idpProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.IDPConfigAddedEventType,
|
||||
Reduce: p.reduceIDPAdded,
|
||||
@@ -165,7 +166,7 @@ func (p *idpProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.IDPConfigAddedEventType,
|
||||
Reduce: p.reduceIDPAdded,
|
||||
@@ -225,7 +226,7 @@ func (p *idpProjection) reduceIDPAdded(event eventstore.Event) (*handler.Stateme
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-fcUdQ", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigAddedEventType, instance.IDPConfigAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
&idpEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPIDCol, idpEvent.ConfigID),
|
||||
@@ -265,7 +266,7 @@ func (p *idpProjection) reduceIDPChanged(event eventstore.Event) (*handler.State
|
||||
cols = append(cols, handler.NewCol(IDPAutoRegisterCol, *idpEvent.AutoRegister))
|
||||
}
|
||||
if len(cols) == 0 {
|
||||
return crdb.NewNoOpStatement(&idpEvent), nil
|
||||
return handler.NewNoOpStatement(&idpEvent), nil
|
||||
}
|
||||
|
||||
cols = append(cols,
|
||||
@@ -273,7 +274,7 @@ func (p *idpProjection) reduceIDPChanged(event eventstore.Event) (*handler.State
|
||||
handler.NewCol(IDPSequenceCol, idpEvent.Sequence()),
|
||||
)
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&idpEvent,
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
@@ -294,7 +295,7 @@ func (p *idpProjection) reduceIDPDeactivated(event eventstore.Event) (*handler.S
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-94O5l", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigDeactivatedEventType, instance.IDPConfigDeactivatedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&idpEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPStateCol, domain.IDPConfigStateInactive),
|
||||
@@ -319,7 +320,7 @@ func (p *idpProjection) reduceIDPReactivated(event eventstore.Event) (*handler.S
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-I8QyS", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigReactivatedEventType, instance.IDPConfigReactivatedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&idpEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPStateCol, domain.IDPConfigStateActive),
|
||||
@@ -344,7 +345,7 @@ func (p *idpProjection) reduceIDPRemoved(event eventstore.Event) (*handler.State
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-B4zy8", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigRemovedEventType, instance.IDPConfigRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
&idpEvent,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPIDCol, idpEvent.ConfigID),
|
||||
@@ -364,8 +365,8 @@ func (p *idpProjection) reduceOIDCConfigAdded(event eventstore.Event) (*handler.
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-2FuAA", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPOIDCConfigAddedEventType, instance.IDPOIDCConfigAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(&idpEvent,
|
||||
crdb.AddUpdateStatement(
|
||||
return handler.NewMultiStatement(&idpEvent,
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPChangeDateCol, idpEvent.CreationDate()),
|
||||
handler.NewCol(IDPSequenceCol, idpEvent.Sequence()),
|
||||
@@ -376,20 +377,20 @@ func (p *idpProjection) reduceOIDCConfigAdded(event eventstore.Event) (*handler.
|
||||
handler.NewCond(IDPInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
crdb.AddCreateStatement(
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(OIDCConfigIDPIDCol, idpEvent.IDPConfigID),
|
||||
handler.NewCol(OIDCConfigInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
handler.NewCol(OIDCConfigClientIDCol, idpEvent.ClientID),
|
||||
handler.NewCol(OIDCConfigClientSecretCol, idpEvent.ClientSecret),
|
||||
handler.NewCol(OIDCConfigIssuerCol, idpEvent.Issuer),
|
||||
handler.NewCol(OIDCConfigScopesCol, database.StringArray(idpEvent.Scopes)),
|
||||
handler.NewCol(OIDCConfigScopesCol, database.TextArray[string](idpEvent.Scopes)),
|
||||
handler.NewCol(OIDCConfigDisplayNameMappingCol, idpEvent.IDPDisplayNameMapping),
|
||||
handler.NewCol(OIDCConfigUsernameMappingCol, idpEvent.UserNameMapping),
|
||||
handler.NewCol(OIDCConfigAuthorizationEndpointCol, idpEvent.AuthorizationEndpoint),
|
||||
handler.NewCol(OIDCConfigTokenEndpointCol, idpEvent.TokenEndpoint),
|
||||
},
|
||||
crdb.WithTableSuffix(IDPOIDCSuffix),
|
||||
handler.WithTableSuffix(IDPOIDCSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -423,7 +424,7 @@ func (p *idpProjection) reduceOIDCConfigChanged(event eventstore.Event) (*handle
|
||||
cols = append(cols, handler.NewCol(OIDCConfigTokenEndpointCol, *idpEvent.TokenEndpoint))
|
||||
}
|
||||
if idpEvent.Scopes != nil {
|
||||
cols = append(cols, handler.NewCol(OIDCConfigScopesCol, database.StringArray(idpEvent.Scopes)))
|
||||
cols = append(cols, handler.NewCol(OIDCConfigScopesCol, database.TextArray[string](idpEvent.Scopes)))
|
||||
}
|
||||
if idpEvent.IDPDisplayNameMapping != nil {
|
||||
cols = append(cols, handler.NewCol(OIDCConfigDisplayNameMappingCol, *idpEvent.IDPDisplayNameMapping))
|
||||
@@ -433,11 +434,11 @@ func (p *idpProjection) reduceOIDCConfigChanged(event eventstore.Event) (*handle
|
||||
}
|
||||
|
||||
if len(cols) == 0 {
|
||||
return crdb.NewNoOpStatement(&idpEvent), nil
|
||||
return handler.NewNoOpStatement(&idpEvent), nil
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(&idpEvent,
|
||||
crdb.AddUpdateStatement(
|
||||
return handler.NewMultiStatement(&idpEvent,
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPChangeDateCol, idpEvent.CreationDate()),
|
||||
handler.NewCol(IDPSequenceCol, idpEvent.Sequence()),
|
||||
@@ -447,13 +448,13 @@ func (p *idpProjection) reduceOIDCConfigChanged(event eventstore.Event) (*handle
|
||||
handler.NewCond(IDPInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(OIDCConfigIDPIDCol, idpEvent.IDPConfigID),
|
||||
handler.NewCond(OIDCConfigInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(IDPOIDCSuffix),
|
||||
handler.WithTableSuffix(IDPOIDCSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -469,8 +470,8 @@ func (p *idpProjection) reduceJWTConfigAdded(event eventstore.Event) (*handler.S
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-qvPdb", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPJWTConfigAddedEventType, instance.IDPJWTConfigAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(&idpEvent,
|
||||
crdb.AddUpdateStatement(
|
||||
return handler.NewMultiStatement(&idpEvent,
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPChangeDateCol, idpEvent.CreationDate()),
|
||||
handler.NewCol(IDPSequenceCol, idpEvent.Sequence()),
|
||||
@@ -482,7 +483,7 @@ func (p *idpProjection) reduceJWTConfigAdded(event eventstore.Event) (*handler.S
|
||||
},
|
||||
),
|
||||
|
||||
crdb.AddCreateStatement(
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(JWTConfigIDPIDCol, idpEvent.IDPConfigID),
|
||||
handler.NewCol(JWTConfigInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
@@ -491,7 +492,7 @@ func (p *idpProjection) reduceJWTConfigAdded(event eventstore.Event) (*handler.S
|
||||
handler.NewCol(JWTConfigKeysEndpointCol, idpEvent.KeysEndpoint),
|
||||
handler.NewCol(JWTConfigHeaderNameCol, idpEvent.HeaderName),
|
||||
},
|
||||
crdb.WithTableSuffix(IDPJWTSuffix),
|
||||
handler.WithTableSuffix(IDPJWTSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -523,11 +524,11 @@ func (p *idpProjection) reduceJWTConfigChanged(event eventstore.Event) (*handler
|
||||
}
|
||||
|
||||
if len(cols) == 0 {
|
||||
return crdb.NewNoOpStatement(&idpEvent), nil
|
||||
return handler.NewNoOpStatement(&idpEvent), nil
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(&idpEvent,
|
||||
crdb.AddUpdateStatement(
|
||||
return handler.NewMultiStatement(&idpEvent,
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPChangeDateCol, idpEvent.CreationDate()),
|
||||
handler.NewCol(IDPSequenceCol, idpEvent.Sequence()),
|
||||
@@ -537,13 +538,13 @@ func (p *idpProjection) reduceJWTConfigChanged(event eventstore.Event) (*handler
|
||||
handler.NewCond(IDPInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(JWTConfigIDPIDCol, idpEvent.IDPConfigID),
|
||||
handler.NewCond(JWTConfigInstanceIDCol, idpEvent.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(IDPJWTSuffix),
|
||||
handler.WithTableSuffix(IDPJWTSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -554,7 +555,7 @@ func (p *idpProjection) reduceOwnerRemoved(event eventstore.Event) (*handler.Sta
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-YsbQC", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
@@ -27,40 +27,41 @@ const (
|
||||
IDPLoginPolicyLinkOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type idpLoginPolicyLinkProjection struct {
|
||||
crdb.StatementHandler
|
||||
type idpLoginPolicyLinkProjection struct{}
|
||||
|
||||
func newIDPLoginPolicyLinkProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(idpLoginPolicyLinkProjection))
|
||||
}
|
||||
|
||||
func newIDPLoginPolicyLinkProjection(ctx context.Context, config crdb.StatementHandlerConfig) *idpLoginPolicyLinkProjection {
|
||||
p := new(idpLoginPolicyLinkProjection)
|
||||
config.ProjectionName = IDPLoginPolicyLinkTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(IDPLoginPolicyLinkIDPIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPLoginPolicyLinkAggregateIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPLoginPolicyLinkCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(IDPLoginPolicyLinkChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(IDPLoginPolicyLinkSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(IDPLoginPolicyLinkResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPLoginPolicyLinkInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPLoginPolicyLinkProviderTypeCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(IDPLoginPolicyLinkOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*idpLoginPolicyLinkProjection) Name() string {
|
||||
return IDPLoginPolicyLinkTable
|
||||
}
|
||||
|
||||
func (*idpLoginPolicyLinkProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(IDPLoginPolicyLinkIDPIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(IDPLoginPolicyLinkAggregateIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(IDPLoginPolicyLinkCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(IDPLoginPolicyLinkChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(IDPLoginPolicyLinkSequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(IDPLoginPolicyLinkResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(IDPLoginPolicyLinkInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(IDPLoginPolicyLinkProviderTypeCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(IDPLoginPolicyLinkOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(IDPLoginPolicyLinkInstanceIDCol, IDPLoginPolicyLinkAggregateIDCol, IDPLoginPolicyLinkIDPIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("resource_owner", []string{IDPLoginPolicyLinkResourceOwnerCol})),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{IDPLoginPolicyLinkOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(IDPLoginPolicyLinkInstanceIDCol, IDPLoginPolicyLinkAggregateIDCol, IDPLoginPolicyLinkIDPIDCol),
|
||||
handler.WithIndex(handler.NewIndex("resource_owner", []string{IDPLoginPolicyLinkResourceOwnerCol})),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{IDPLoginPolicyLinkOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *idpLoginPolicyLinkProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *idpLoginPolicyLinkProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.LoginPolicyIDPProviderAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -93,7 +94,7 @@ func (p *idpLoginPolicyLinkProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.LoginPolicyIDPProviderAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -140,7 +141,7 @@ func (p *idpLoginPolicyLinkProjection) reduceAdded(event eventstore.Event) (*han
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Nlp55", "reduce.wrong.event.type %v", []eventstore.EventType{org.LoginPolicyIDPProviderAddedEventType, instance.LoginPolicyIDPProviderAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(&idp,
|
||||
return handler.NewCreateStatement(&idp,
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPLoginPolicyLinkIDPIDCol, idp.IDPConfigID),
|
||||
handler.NewCol(IDPLoginPolicyLinkAggregateIDCol, idp.Aggregate().ID),
|
||||
@@ -166,7 +167,7 @@ func (p *idpLoginPolicyLinkProjection) reduceRemoved(event eventstore.Event) (*h
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-tUMYY", "reduce.wrong.event.type %v", []eventstore.EventType{org.LoginPolicyIDPProviderRemovedEventType, instance.LoginPolicyIDPProviderRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(&idp,
|
||||
return handler.NewDeleteStatement(&idp,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPLoginPolicyLinkIDPIDCol, idp.IDPConfigID),
|
||||
handler.NewCond(IDPLoginPolicyLinkAggregateIDCol, idp.Aggregate().ID),
|
||||
@@ -187,7 +188,7 @@ func (p *idpLoginPolicyLinkProjection) reduceCascadeRemoved(event eventstore.Eve
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-iCKSj", "reduce.wrong.event.type %v", []eventstore.EventType{org.LoginPolicyIDPProviderCascadeRemovedEventType, instance.LoginPolicyIDPProviderCascadeRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(&idp,
|
||||
return handler.NewDeleteStatement(&idp,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPLoginPolicyLinkIDPIDCol, idp.IDPConfigID),
|
||||
handler.NewCond(IDPLoginPolicyLinkAggregateIDCol, idp.Aggregate().ID),
|
||||
@@ -215,7 +216,7 @@ func (p *idpLoginPolicyLinkProjection) reduceIDPConfigRemoved(event eventstore.E
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-u6tze", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigRemovedEventType, instance.IDPConfigRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(event, conditions), nil
|
||||
return handler.NewDeleteStatement(event, conditions), nil
|
||||
}
|
||||
|
||||
func (p *idpLoginPolicyLinkProjection) reduceIDPRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
@@ -237,7 +238,7 @@ func (p *idpLoginPolicyLinkProjection) reduceIDPRemoved(event eventstore.Event)
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-SFED3", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPRemovedEventType, instance.IDPRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(event, conditions), nil
|
||||
return handler.NewDeleteStatement(event, conditions), nil
|
||||
}
|
||||
|
||||
func (p *idpLoginPolicyLinkProjection) reducePolicyRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
@@ -245,7 +246,7 @@ func (p *idpLoginPolicyLinkProjection) reducePolicyRemoved(event eventstore.Even
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-SF3dg", "reduce.wrong.event.type %s", org.LoginPolicyRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(e,
|
||||
return handler.NewDeleteStatement(e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPLoginPolicyLinkAggregateIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(IDPLoginPolicyLinkInstanceIDCol, event.Aggregate().InstanceID),
|
||||
@@ -259,7 +260,7 @@ func (p *idpLoginPolicyLinkProjection) reduceOwnerRemoved(event eventstore.Event
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-YbhOv", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPLoginPolicyLinkInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -25,20 +24,20 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "iam reduceAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LoginPolicyIDPProviderAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LoginPolicyIDPProviderAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"idpProviderType": 1
|
||||
}`),
|
||||
), instance.IdentityProviderAddedEventMapper),
|
||||
), instance.IdentityProviderAddedEventMapper),
|
||||
},
|
||||
reduce: (&idpLoginPolicyLinkProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -61,20 +60,20 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "iam reduceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LoginPolicyIDPProviderRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LoginPolicyIDPProviderRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"idpProviderType": 1
|
||||
}`),
|
||||
), instance.IdentityProviderRemovedEventMapper),
|
||||
), instance.IdentityProviderRemovedEventMapper),
|
||||
},
|
||||
reduce: (&idpLoginPolicyLinkProjection{}).reduceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -92,20 +91,20 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "iam reduceCascadeRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LoginPolicyIDPProviderCascadeRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LoginPolicyIDPProviderCascadeRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"idpProviderType": 1
|
||||
}`),
|
||||
), instance.IdentityProviderCascadeRemovedEventMapper),
|
||||
), instance.IdentityProviderCascadeRemovedEventMapper),
|
||||
},
|
||||
reduce: (&idpLoginPolicyLinkProjection{}).reduceCascadeRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -123,20 +122,20 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LoginPolicyIDPProviderAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LoginPolicyIDPProviderAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"idpProviderType": 1
|
||||
}`),
|
||||
), org.IdentityProviderAddedEventMapper),
|
||||
), org.IdentityProviderAddedEventMapper),
|
||||
},
|
||||
reduce: (&idpLoginPolicyLinkProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -159,20 +158,20 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LoginPolicyIDPProviderRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LoginPolicyIDPProviderRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"idpProviderType": 1
|
||||
}`),
|
||||
), org.IdentityProviderRemovedEventMapper),
|
||||
), org.IdentityProviderRemovedEventMapper),
|
||||
},
|
||||
reduce: (&idpLoginPolicyLinkProjection{}).reduceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -190,17 +189,17 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(IDPUserLinkInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -216,20 +215,20 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceCascadeRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LoginPolicyIDPProviderCascadeRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LoginPolicyIDPProviderCascadeRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"idpProviderType": 1
|
||||
}`),
|
||||
), org.IdentityProviderCascadeRemovedEventMapper),
|
||||
), org.IdentityProviderCascadeRemovedEventMapper),
|
||||
},
|
||||
reduce: (&idpLoginPolicyLinkProjection{}).reduceCascadeRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -247,17 +246,17 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reducePolicyRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LoginPolicyRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.LoginPolicyRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LoginPolicyRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.LoginPolicyRemovedEventMapper),
|
||||
},
|
||||
reduce: (&idpLoginPolicyLinkProjection{}).reducePolicyRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -274,19 +273,19 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org IDPConfigRemovedEvent",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.IDPConfigRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.IDPConfigRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id"
|
||||
}`),
|
||||
), org.IDPConfigRemovedEventMapper),
|
||||
), org.IDPConfigRemovedEventMapper),
|
||||
},
|
||||
reduce: (&idpLoginPolicyLinkProjection{}).reduceIDPConfigRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -304,19 +303,19 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "iam IDPConfigRemovedEvent",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.IDPConfigRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.IDPConfigRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id"
|
||||
}`),
|
||||
), instance.IDPConfigRemovedEventMapper),
|
||||
), instance.IDPConfigRemovedEventMapper),
|
||||
},
|
||||
reduce: (&idpLoginPolicyLinkProjection{}).reduceIDPConfigRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -333,19 +332,19 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org IDPRemovedEvent",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.IDPRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.IDPRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "id"
|
||||
}`),
|
||||
), org.IDPRemovedEventMapper),
|
||||
), org.IDPRemovedEventMapper),
|
||||
},
|
||||
reduce: (&idpLoginPolicyLinkProjection{}).reduceIDPRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -363,19 +362,19 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "iam IDPRemovedEvent",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.IDPRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.IDPRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "id"
|
||||
}`),
|
||||
), instance.IDPRemovedEventMapper),
|
||||
), instance.IDPRemovedEventMapper),
|
||||
},
|
||||
reduce: (&idpLoginPolicyLinkProjection{}).reduceIDPRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -393,16 +392,16 @@ func TestIDPLoginPolicyLinkProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (&idpLoginPolicyLinkProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -7,8 +7,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -26,23 +25,23 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceIDPAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.IDPConfigAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.IDPConfigAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"name": "custom-zitadel-instance",
|
||||
"idpType": 0,
|
||||
"stylingType": 0,
|
||||
"autoRegister": true
|
||||
}`),
|
||||
), instance.IDPConfigAddedEventMapper),
|
||||
), instance.IDPConfigAddedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceIDPAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -68,22 +67,22 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceIDPChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.IDPConfigChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.IDPConfigChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"name": "custom-zitadel-instance",
|
||||
"stylingType": 1,
|
||||
"autoRegister": true
|
||||
}`),
|
||||
), instance.IDPConfigChangedEventMapper),
|
||||
), instance.IDPConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceIDPChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -105,19 +104,19 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceIDPDeactivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.IDPConfigDeactivatedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.IDPConfigDeactivatedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id"
|
||||
}`),
|
||||
), instance.IDPConfigDeactivatedEventMapper),
|
||||
), instance.IDPConfigDeactivatedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceIDPDeactivated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -137,19 +136,19 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceIDPReactivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.IDPConfigReactivatedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.IDPConfigReactivatedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id"
|
||||
}`),
|
||||
), instance.IDPConfigReactivatedEventMapper),
|
||||
), instance.IDPConfigReactivatedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceIDPReactivated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -169,19 +168,19 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceIDPRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.IDPConfigRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.IDPConfigRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id"
|
||||
}`),
|
||||
), instance.IDPConfigRemovedEventMapper),
|
||||
), instance.IDPConfigRemovedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceIDPRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -198,17 +197,17 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(IDPInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -224,10 +223,11 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceOIDCConfigAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.IDPOIDCConfigAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.IDPOIDCConfigAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"clientId": "client-id",
|
||||
"clientSecret": {
|
||||
@@ -242,13 +242,12 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
"idpDisplayNameMapping": 0,
|
||||
"usernameMapping": 1
|
||||
}`),
|
||||
), instance.IDPOIDCConfigAddedEventMapper),
|
||||
), instance.IDPOIDCConfigAddedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceOIDCConfigAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -269,7 +268,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
"client-id",
|
||||
anyArg{},
|
||||
"issuer",
|
||||
database.StringArray{"profile"},
|
||||
database.TextArray[string]{"profile"},
|
||||
domain.OIDCMappingFieldUnspecified,
|
||||
domain.OIDCMappingFieldPreferredLoginName,
|
||||
"https://api.zitadel.ch/authorize",
|
||||
@@ -283,10 +282,11 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceOIDCConfigChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.IDPOIDCConfigChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.IDPOIDCConfigChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"clientId": "client-id",
|
||||
"clientSecret": {
|
||||
@@ -301,13 +301,12 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
"idpDisplayNameMapping": 0,
|
||||
"usernameMapping": 1
|
||||
}`),
|
||||
), instance.IDPOIDCConfigChangedEventMapper),
|
||||
), instance.IDPOIDCConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceOIDCConfigChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -327,7 +326,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
"issuer",
|
||||
"https://api.zitadel.ch/authorize",
|
||||
"https://api.zitadel.ch/token",
|
||||
database.StringArray{"profile"},
|
||||
database.TextArray[string]{"profile"},
|
||||
domain.OIDCMappingFieldUnspecified,
|
||||
domain.OIDCMappingFieldPreferredLoginName,
|
||||
"idp-config-id",
|
||||
@@ -341,17 +340,17 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceOIDCConfigChanged: no op",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.IDPOIDCConfigChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte("{}"),
|
||||
), instance.IDPOIDCConfigChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.IDPOIDCConfigChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte("{}"),
|
||||
), instance.IDPOIDCConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceOIDCConfigChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{},
|
||||
},
|
||||
@@ -360,23 +359,23 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceJWTConfigAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.IDPJWTConfigAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.IDPJWTConfigAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"jwtEndpoint": "https://api.zitadel.ch/jwt",
|
||||
"issuer": "issuer",
|
||||
"keysEndpoint": "https://api.zitadel.ch/keys",
|
||||
"headerName": "hodor"
|
||||
}`),
|
||||
), instance.IDPJWTConfigAddedEventMapper),
|
||||
), instance.IDPJWTConfigAddedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceJWTConfigAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -407,23 +406,23 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceJWTConfigChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.IDPJWTConfigChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.IDPJWTConfigChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"jwtEndpoint": "https://api.zitadel.ch/jwt",
|
||||
"issuer": "issuer",
|
||||
"keysEndpoint": "https://api.zitadel.ch/keys",
|
||||
"headerName": "hodor"
|
||||
}`),
|
||||
), instance.IDPJWTConfigChangedEventMapper),
|
||||
), instance.IDPJWTConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceJWTConfigChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -453,17 +452,17 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceJWTConfigChanged: no op",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.IDPJWTConfigChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), instance.IDPJWTConfigChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.IDPJWTConfigChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), instance.IDPJWTConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceJWTConfigChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{},
|
||||
},
|
||||
@@ -472,23 +471,23 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceIDPAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.IDPConfigAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.IDPConfigAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"name": "custom-zitadel-instance",
|
||||
"idpType": 0,
|
||||
"stylingType": 0,
|
||||
"autoRegister": true
|
||||
}`),
|
||||
), org.IDPConfigAddedEventMapper),
|
||||
), org.IDPConfigAddedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceIDPAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -514,22 +513,22 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceIDPChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.IDPConfigChangedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.IDPConfigChangedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"name": "custom-zitadel-instance",
|
||||
"stylingType": 1,
|
||||
"autoRegister": true
|
||||
}`),
|
||||
), org.IDPConfigChangedEventMapper),
|
||||
), org.IDPConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceIDPChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -551,19 +550,19 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceIDPDeactivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.IDPConfigDeactivatedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.IDPConfigDeactivatedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id"
|
||||
}`),
|
||||
), org.IDPConfigDeactivatedEventMapper),
|
||||
), org.IDPConfigDeactivatedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceIDPDeactivated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -583,19 +582,19 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceIDPReactivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.IDPConfigReactivatedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.IDPConfigReactivatedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id"
|
||||
}`),
|
||||
), org.IDPConfigReactivatedEventMapper),
|
||||
), org.IDPConfigReactivatedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceIDPReactivated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -615,19 +614,19 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceIDPRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.IDPConfigRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.IDPConfigRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id"
|
||||
}`),
|
||||
), org.IDPConfigRemovedEventMapper),
|
||||
), org.IDPConfigRemovedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceIDPRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -644,10 +643,11 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceOIDCConfigAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.IDPOIDCConfigAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.IDPOIDCConfigAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"clientId": "client-id",
|
||||
"clientSecret": {
|
||||
@@ -662,13 +662,12 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
"idpDisplayNameMapping": 0,
|
||||
"usernameMapping": 1
|
||||
}`),
|
||||
), org.IDPOIDCConfigAddedEventMapper),
|
||||
), org.IDPOIDCConfigAddedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceOIDCConfigAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -689,7 +688,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
"client-id",
|
||||
anyArg{},
|
||||
"issuer",
|
||||
database.StringArray{"profile"},
|
||||
database.TextArray[string]{"profile"},
|
||||
domain.OIDCMappingFieldUnspecified,
|
||||
domain.OIDCMappingFieldPreferredLoginName,
|
||||
"https://api.zitadel.ch/authorize",
|
||||
@@ -703,10 +702,11 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceOIDCConfigChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.IDPOIDCConfigChangedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.IDPOIDCConfigChangedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"clientId": "client-id",
|
||||
"clientSecret": {
|
||||
@@ -721,13 +721,12 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
"idpDisplayNameMapping": 0,
|
||||
"usernameMapping": 1
|
||||
}`),
|
||||
), org.IDPOIDCConfigChangedEventMapper),
|
||||
), org.IDPOIDCConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceOIDCConfigChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -747,7 +746,7 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
"issuer",
|
||||
"https://api.zitadel.ch/authorize",
|
||||
"https://api.zitadel.ch/token",
|
||||
database.StringArray{"profile"},
|
||||
database.TextArray[string]{"profile"},
|
||||
domain.OIDCMappingFieldUnspecified,
|
||||
domain.OIDCMappingFieldPreferredLoginName,
|
||||
"idp-config-id",
|
||||
@@ -761,17 +760,17 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceOIDCConfigChanged: no op",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.IDPOIDCConfigChangedEventType),
|
||||
org.AggregateType,
|
||||
[]byte("{}"),
|
||||
), org.IDPOIDCConfigChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.IDPOIDCConfigChangedEventType,
|
||||
org.AggregateType,
|
||||
[]byte("{}"),
|
||||
), org.IDPOIDCConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceOIDCConfigChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{},
|
||||
},
|
||||
@@ -780,23 +779,23 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceJWTConfigAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.IDPJWTConfigAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.IDPJWTConfigAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"jwtEndpoint": "https://api.zitadel.ch/jwt",
|
||||
"issuer": "issuer",
|
||||
"keysEndpoint": "https://api.zitadel.ch/keys",
|
||||
"headerName": "hodor"
|
||||
}`),
|
||||
), org.IDPJWTConfigAddedEventMapper),
|
||||
), org.IDPJWTConfigAddedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceJWTConfigAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -827,23 +826,23 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceJWTConfigChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.IDPJWTConfigChangedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.IDPJWTConfigChangedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"jwtEndpoint": "https://api.zitadel.ch/jwt",
|
||||
"issuer": "issuer",
|
||||
"keysEndpoint": "https://api.zitadel.ch/keys",
|
||||
"headerName": "hodor"
|
||||
}`),
|
||||
), org.IDPJWTConfigChangedEventMapper),
|
||||
), org.IDPJWTConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceJWTConfigChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -873,17 +872,17 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceJWTConfigChanged: no op",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.IDPJWTConfigChangedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), org.IDPJWTConfigChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.IDPJWTConfigChangedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), org.IDPJWTConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&idpProjection{}).reduceJWTConfigChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{},
|
||||
},
|
||||
@@ -893,16 +892,16 @@ func TestIDPProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (&idpProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/user"
|
||||
@@ -26,41 +26,42 @@ const (
|
||||
IDPUserLinkOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type idpUserLinkProjection struct {
|
||||
crdb.StatementHandler
|
||||
type idpUserLinkProjection struct{}
|
||||
|
||||
func newIDPUserLinkProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(idpUserLinkProjection))
|
||||
}
|
||||
|
||||
func newIDPUserLinkProjection(ctx context.Context, config crdb.StatementHandlerConfig) *idpUserLinkProjection {
|
||||
p := new(idpUserLinkProjection)
|
||||
config.ProjectionName = IDPUserLinkTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(IDPUserLinkIDPIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPUserLinkUserIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPUserLinkExternalUserIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPUserLinkCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(IDPUserLinkChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(IDPUserLinkSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(IDPUserLinkResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPUserLinkInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPUserLinkDisplayNameCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(IDPUserLinkOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*idpUserLinkProjection) Name() string {
|
||||
return IDPUserLinkTable
|
||||
}
|
||||
|
||||
func (*idpUserLinkProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(IDPUserLinkIDPIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(IDPUserLinkUserIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(IDPUserLinkExternalUserIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(IDPUserLinkCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(IDPUserLinkChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(IDPUserLinkSequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(IDPUserLinkResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(IDPUserLinkInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(IDPUserLinkDisplayNameCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(IDPUserLinkOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(IDPUserLinkInstanceIDCol, IDPUserLinkIDPIDCol, IDPUserLinkExternalUserIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("user_id", []string{IDPUserLinkUserIDCol})),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{IDPUserLinkOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(IDPUserLinkInstanceIDCol, IDPUserLinkIDPIDCol, IDPUserLinkExternalUserIDCol),
|
||||
handler.WithIndex(handler.NewIndex("user_id", []string{IDPUserLinkUserIDCol})),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{IDPUserLinkOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *idpUserLinkProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *idpUserLinkProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: user.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: user.UserIDPLinkAddedType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -85,7 +86,7 @@ func (p *idpUserLinkProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.IDPConfigRemovedEventType,
|
||||
Reduce: p.reduceIDPConfigRemoved,
|
||||
@@ -98,7 +99,7 @@ func (p *idpUserLinkProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.IDPConfigRemovedEventType,
|
||||
Reduce: p.reduceIDPConfigRemoved,
|
||||
@@ -118,7 +119,7 @@ func (p *idpUserLinkProjection) reduceAdded(event eventstore.Event) (*handler.St
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-DpmXq", "reduce.wrong.event.type %s", user.UserIDPLinkAddedType)
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(e,
|
||||
return handler.NewCreateStatement(e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPUserLinkIDPIDCol, e.IDPConfigID),
|
||||
handler.NewCol(IDPUserLinkUserIDCol, e.Aggregate().ID),
|
||||
@@ -139,7 +140,7 @@ func (p *idpUserLinkProjection) reduceRemoved(event eventstore.Event) (*handler.
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-AZmfJ", "reduce.wrong.event.type %s", user.UserIDPLinkRemovedType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(e,
|
||||
return handler.NewDeleteStatement(e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPUserLinkIDPIDCol, e.IDPConfigID),
|
||||
handler.NewCond(IDPUserLinkUserIDCol, e.Aggregate().ID),
|
||||
@@ -155,7 +156,7 @@ func (p *idpUserLinkProjection) reduceCascadeRemoved(event eventstore.Event) (*h
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-jQpv9", "reduce.wrong.event.type %s", user.UserIDPLinkCascadeRemovedType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(e,
|
||||
return handler.NewDeleteStatement(e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPUserLinkIDPIDCol, e.IDPConfigID),
|
||||
handler.NewCond(IDPUserLinkUserIDCol, e.Aggregate().ID),
|
||||
@@ -171,7 +172,7 @@ func (p *idpUserLinkProjection) reduceOwnerRemoved(event eventstore.Event) (*han
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-PGiAY", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPUserLinkResourceOwnerCol, e.Aggregate().ID),
|
||||
@@ -186,7 +187,7 @@ func (p *idpUserLinkProjection) reduceUserRemoved(event eventstore.Event) (*hand
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-uwlWE", "reduce.wrong.event.type %s", user.UserRemovedType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(e,
|
||||
return handler.NewDeleteStatement(e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPUserLinkUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(IDPUserLinkInstanceIDCol, e.Aggregate().InstanceID),
|
||||
@@ -200,7 +201,7 @@ func (p *idpUserLinkProjection) reduceExternalIDMigrated(event eventstore.Event)
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-AS3th", "reduce.wrong.event.type %s", user.UserIDPExternalIDMigratedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(e,
|
||||
return handler.NewUpdateStatement(e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(IDPUserLinkChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(IDPUserLinkSequenceCol, e.Sequence()),
|
||||
@@ -227,7 +228,7 @@ func (p *idpUserLinkProjection) reduceIDPConfigRemoved(event eventstore.Event) (
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-iCKSj", "reduce.wrong.event.type %v", []eventstore.EventType{org.IDPConfigRemovedEventType, instance.IDPConfigRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(event,
|
||||
return handler.NewDeleteStatement(event,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(IDPUserLinkIDPIDCol, idpID),
|
||||
handler.NewCond(IDPUserLinkResourceOwnerCol, event.Aggregate().ResourceOwner),
|
||||
|
||||
@@ -5,8 +5,7 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/user"
|
||||
@@ -25,21 +24,21 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.UserIDPLinkAddedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.UserIDPLinkAddedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"userId": "external-user-id",
|
||||
"displayName": "[email protected]"
|
||||
}`),
|
||||
), user.UserIDPLinkAddedEventMapper),
|
||||
), user.UserIDPLinkAddedEventMapper),
|
||||
},
|
||||
reduce: (&idpUserLinkProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -63,20 +62,20 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.UserIDPLinkRemovedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.UserIDPLinkRemovedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"userId": "external-user-id"
|
||||
}`),
|
||||
), user.UserIDPLinkRemovedEventMapper),
|
||||
), user.UserIDPLinkRemovedEventMapper),
|
||||
},
|
||||
reduce: (&idpUserLinkProjection{}).reduceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -95,20 +94,20 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceCascadeRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.UserIDPLinkCascadeRemovedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.UserIDPLinkCascadeRemovedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
"userId": "external-user-id"
|
||||
}`),
|
||||
), user.UserIDPLinkCascadeRemovedEventMapper),
|
||||
), user.UserIDPLinkCascadeRemovedEventMapper),
|
||||
},
|
||||
reduce: (&idpUserLinkProjection{}).reduceCascadeRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -127,17 +126,17 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceOwnerRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
reduce: (&idpUserLinkProjection{}).reduceOwnerRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -154,17 +153,17 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(IDPUserLinkInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -180,17 +179,17 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceUserRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.UserRemovedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), user.UserRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.UserRemovedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), user.UserRemovedEventMapper),
|
||||
},
|
||||
reduce: (&idpUserLinkProjection{}).reduceUserRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -208,7 +207,7 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
|
||||
name: "reduceExternalIDMigrated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.UserIDPExternalIDMigratedType),
|
||||
user.UserIDPExternalIDMigratedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id",
|
||||
@@ -219,9 +218,8 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&idpUserLinkProjection{}).reduceExternalIDMigrated,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -243,19 +241,19 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org IDPConfigRemovedEvent",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.IDPConfigRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.IDPConfigRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id"
|
||||
}`),
|
||||
), org.IDPConfigRemovedEventMapper),
|
||||
), org.IDPConfigRemovedEventMapper),
|
||||
},
|
||||
reduce: (&idpUserLinkProjection{}).reduceIDPConfigRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -273,19 +271,19 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "iam IDPConfigRemovedEvent",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.IDPConfigRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.IDPConfigRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"idpConfigId": "idp-config-id"
|
||||
}`),
|
||||
), instance.IDPConfigRemovedEventMapper),
|
||||
), instance.IDPConfigRemovedEventMapper),
|
||||
},
|
||||
reduce: (&idpUserLinkProjection{}).reduceIDPConfigRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
@@ -25,39 +25,40 @@ const (
|
||||
InstanceColumnDefaultLanguage = "default_language"
|
||||
)
|
||||
|
||||
type instanceProjection struct {
|
||||
crdb.StatementHandler
|
||||
type instanceProjection struct{}
|
||||
|
||||
func newInstanceProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(instanceProjection))
|
||||
}
|
||||
|
||||
func newInstanceProjection(ctx context.Context, config crdb.StatementHandlerConfig) *instanceProjection {
|
||||
p := new(instanceProjection)
|
||||
config.ProjectionName = InstanceProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(InstanceColumnID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(InstanceColumnName, crdb.ColumnTypeText, crdb.Default("")),
|
||||
crdb.NewColumn(InstanceColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(InstanceColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(InstanceColumnDefaultOrgID, crdb.ColumnTypeText, crdb.Default("")),
|
||||
crdb.NewColumn(InstanceColumnProjectID, crdb.ColumnTypeText, crdb.Default("")),
|
||||
crdb.NewColumn(InstanceColumnConsoleID, crdb.ColumnTypeText, crdb.Default("")),
|
||||
crdb.NewColumn(InstanceColumnConsoleAppID, crdb.ColumnTypeText, crdb.Default("")),
|
||||
crdb.NewColumn(InstanceColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(InstanceColumnDefaultLanguage, crdb.ColumnTypeText, crdb.Default("")),
|
||||
func (*instanceProjection) Name() string {
|
||||
return InstanceProjectionTable
|
||||
}
|
||||
|
||||
func (*instanceProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(InstanceColumnID, handler.ColumnTypeText),
|
||||
handler.NewColumn(InstanceColumnName, handler.ColumnTypeText, handler.Default("")),
|
||||
handler.NewColumn(InstanceColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(InstanceColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(InstanceColumnDefaultOrgID, handler.ColumnTypeText, handler.Default("")),
|
||||
handler.NewColumn(InstanceColumnProjectID, handler.ColumnTypeText, handler.Default("")),
|
||||
handler.NewColumn(InstanceColumnConsoleID, handler.ColumnTypeText, handler.Default("")),
|
||||
handler.NewColumn(InstanceColumnConsoleAppID, handler.ColumnTypeText, handler.Default("")),
|
||||
handler.NewColumn(InstanceColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(InstanceColumnDefaultLanguage, handler.ColumnTypeText, handler.Default("")),
|
||||
},
|
||||
crdb.NewPrimaryKey(InstanceColumnID),
|
||||
handler.NewPrimaryKey(InstanceColumnID),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *instanceProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *instanceProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceAddedEventType,
|
||||
Reduce: p.reduceInstanceAdded,
|
||||
@@ -96,7 +97,7 @@ func (p *instanceProjection) reduceInstanceAdded(event eventstore.Event) (*handl
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-29nlS", "reduce.wrong.event.type %s", instance.InstanceAddedEventType)
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(InstanceColumnID, e.Aggregate().InstanceID),
|
||||
@@ -114,7 +115,7 @@ func reduceInstanceRemovedHelper(instanceIDCol string) func(event eventstore.Eve
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-22nlS", "reduce.wrong.event.type %s", instance.InstanceRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(instanceIDCol, e.Aggregate().ID),
|
||||
@@ -128,7 +129,7 @@ func (p *instanceProjection) reduceInstanceChanged(event eventstore.Event) (*han
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-so2am1", "reduce.wrong.event.type %s", instance.InstanceChangedEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(InstanceColumnName, e.Name),
|
||||
@@ -146,7 +147,7 @@ func (p *instanceProjection) reduceDefaultOrgSet(event eventstore.Event) (*handl
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-2n9f2", "reduce.wrong.event.type %s", instance.DefaultOrgSetEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(InstanceColumnChangeDate, e.CreationDate()),
|
||||
@@ -164,7 +165,7 @@ func (p *instanceProjection) reduceIAMProjectSet(event eventstore.Event) (*handl
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-30o0e", "reduce.wrong.event.type %s", instance.ProjectSetEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(InstanceColumnChangeDate, e.CreationDate()),
|
||||
@@ -182,7 +183,7 @@ func (p *instanceProjection) reduceConsoleSet(event eventstore.Event) (*handler.
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Dgf11", "reduce.wrong.event.type %s", instance.ConsoleSetEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(InstanceColumnChangeDate, e.CreationDate()),
|
||||
@@ -201,7 +202,7 @@ func (p *instanceProjection) reduceDefaultLanguageSet(event eventstore.Event) (*
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-30o0e", "reduce.wrong.event.type %s", instance.DefaultLanguageSetEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(InstanceColumnChangeDate, e.CreationDate()),
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
@@ -22,37 +22,42 @@ const (
|
||||
InstanceDomainIsPrimaryCol = "is_primary"
|
||||
)
|
||||
|
||||
type instanceDomainProjection struct {
|
||||
crdb.StatementHandler
|
||||
type instanceDomainProjection struct{}
|
||||
|
||||
func newInstanceDomainProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(instanceDomainProjection))
|
||||
}
|
||||
|
||||
func newInstanceDomainProjection(ctx context.Context, config crdb.StatementHandlerConfig) *instanceDomainProjection {
|
||||
p := new(instanceDomainProjection)
|
||||
config.ProjectionName = InstanceDomainTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(InstanceDomainInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(InstanceDomainCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(InstanceDomainChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(InstanceDomainSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(InstanceDomainDomainCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(InstanceDomainIsGeneratedCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(InstanceDomainIsPrimaryCol, crdb.ColumnTypeBool),
|
||||
func (*instanceDomainProjection) Name() string {
|
||||
return InstanceDomainTable
|
||||
}
|
||||
|
||||
func (*instanceDomainProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(InstanceDomainInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(InstanceDomainCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(InstanceDomainChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(InstanceDomainSequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(InstanceDomainDomainCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(InstanceDomainIsGeneratedCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(InstanceDomainIsPrimaryCol, handler.ColumnTypeBool),
|
||||
},
|
||||
crdb.NewPrimaryKey(InstanceDomainInstanceIDCol, InstanceDomainDomainCol),
|
||||
crdb.WithIndex(crdb.NewIndex("instance_domain", []string{InstanceDomainDomainCol})),
|
||||
handler.NewPrimaryKey(InstanceDomainInstanceIDCol, InstanceDomainDomainCol),
|
||||
handler.WithIndex(
|
||||
handler.NewIndex("instance_domain", []string{InstanceDomainDomainCol},
|
||||
handler.WithInclude(InstanceDomainCreationDateCol, InstanceDomainChangeDateCol, InstanceDomainSequenceCol, InstanceDomainIsGeneratedCol, InstanceDomainIsPrimaryCol),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *instanceDomainProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *instanceDomainProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceDomainAddedEventType,
|
||||
Reduce: p.reduceDomainAdded,
|
||||
@@ -79,7 +84,7 @@ func (p *instanceDomainProjection) reduceDomainAdded(event eventstore.Event) (*h
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-38nNf", "reduce.wrong.event.type %s", instance.InstanceDomainAddedEventType)
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(InstanceDomainCreationDateCol, e.CreationDate()),
|
||||
@@ -98,9 +103,9 @@ func (p *instanceDomainProjection) reduceDomainPrimarySet(event eventstore.Event
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-f8nlw", "reduce.wrong.event.type %s", instance.InstanceDomainPrimarySetEventType)
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(InstanceDomainChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(InstanceDomainSequenceCol, e.Sequence()),
|
||||
@@ -111,7 +116,7 @@ func (p *instanceDomainProjection) reduceDomainPrimarySet(event eventstore.Event
|
||||
handler.NewCond(InstanceDomainIsPrimaryCol, true),
|
||||
},
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(InstanceDomainChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(InstanceDomainSequenceCol, e.Sequence()),
|
||||
@@ -130,7 +135,7 @@ func (p *instanceDomainProjection) reduceDomainRemoved(event eventstore.Event) (
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-388Nk", "reduce.wrong.event.type %s", instance.InstanceDomainRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(InstanceDomainDomainCol, e.Domain),
|
||||
|
||||
@@ -5,8 +5,7 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
@@ -23,17 +22,17 @@ func TestInstanceDomainProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceDomainAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceDomainAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"domain": "domain.new", "generated": true}`),
|
||||
), instance.DomainAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceDomainAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"domain": "domain.new", "generated": true}`),
|
||||
), instance.DomainAddedEventMapper),
|
||||
},
|
||||
reduce: (&instanceDomainProjection{}).reduceDomainAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -55,17 +54,17 @@ func TestInstanceDomainProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceDomainRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceDomainRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"domain": "domain.new"}`),
|
||||
), instance.DomainRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceDomainRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"domain": "domain.new"}`),
|
||||
), instance.DomainRemovedEventMapper),
|
||||
},
|
||||
reduce: (&instanceDomainProjection{}).reduceDomainRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -82,17 +81,17 @@ func TestInstanceDomainProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(InstanceDomainInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/user"
|
||||
@@ -19,31 +19,46 @@ const (
|
||||
)
|
||||
|
||||
type instanceMemberProjection struct {
|
||||
crdb.StatementHandler
|
||||
es handler.EventStore
|
||||
}
|
||||
|
||||
func newInstanceMemberProjection(ctx context.Context, config crdb.StatementHandlerConfig) *instanceMemberProjection {
|
||||
p := new(instanceMemberProjection)
|
||||
config.ProjectionName = InstanceMemberProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable(
|
||||
append(memberColumns, crdb.NewColumn(InstanceColumnID, crdb.ColumnTypeText)),
|
||||
crdb.NewPrimaryKey(MemberInstanceID, InstanceColumnID, MemberUserIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("user_id", []string{MemberUserIDCol})),
|
||||
crdb.WithIndex(crdb.NewIndex("user_owner_removed", []string{MemberUserOwnerRemoved})),
|
||||
func newInstanceMemberProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, &instanceMemberProjection{es: config.Eventstore})
|
||||
}
|
||||
|
||||
func (*instanceMemberProjection) Name() string {
|
||||
return InstanceMemberProjectionTable
|
||||
}
|
||||
|
||||
func (*instanceMemberProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable(
|
||||
append(memberColumns, handler.NewColumn(InstanceColumnID, handler.ColumnTypeText)),
|
||||
handler.NewPrimaryKey(MemberInstanceID, InstanceColumnID, MemberUserIDCol),
|
||||
handler.WithIndex(handler.NewIndex("user_id", []string{MemberUserIDCol})),
|
||||
handler.WithIndex(handler.NewIndex("user_owner_removed", []string{MemberUserOwnerRemoved})),
|
||||
handler.WithIndex(
|
||||
handler.NewIndex("im_instance", []string{MemberInstanceID},
|
||||
handler.WithInclude(
|
||||
MemberCreationDate,
|
||||
MemberChangeDate,
|
||||
MemberUserOwnerRemoved,
|
||||
MemberRolesCol,
|
||||
MemberSequence,
|
||||
MemberResourceOwner,
|
||||
MemberOwnerRemoved,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *instanceMemberProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *instanceMemberProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.MemberAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -68,7 +83,7 @@ func (p *instanceMemberProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.OrgRemovedEventType,
|
||||
Reduce: p.reduceUserOwnerRemoved,
|
||||
@@ -77,7 +92,7 @@ func (p *instanceMemberProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: user.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: user.UserRemovedType,
|
||||
Reduce: p.reduceUserRemoved,
|
||||
@@ -93,7 +108,7 @@ func (p *instanceMemberProjection) reduceAdded(event eventstore.Event) (*handler
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-pGNCu", "reduce.wrong.event.type %s", instance.MemberAddedEventType)
|
||||
}
|
||||
ctx := setMemberContext(e.Aggregate())
|
||||
userOwner, err := getResourceOwnerOfUser(ctx, p.Eventstore, e.Aggregate().InstanceID, e.UserID)
|
||||
userOwner, err := getResourceOwnerOfUser(ctx, p.es, e.Aggregate().InstanceID, e.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -10,8 +10,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/user"
|
||||
@@ -30,34 +29,37 @@ func TestInstanceMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance MemberAddedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.MemberAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.MemberAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"userId": "user-id",
|
||||
"roles": ["role"]
|
||||
}`),
|
||||
), instance.MemberAddedEventMapper),
|
||||
), instance.MemberAddedEventMapper),
|
||||
},
|
||||
reduce: (&instanceMemberProjection{
|
||||
StatementHandler: getStatementHandlerWithFilters(
|
||||
user.NewHumanAddedEvent(context.Background(),
|
||||
&user.NewAggregate("user-id", "org1").Aggregate,
|
||||
"username1",
|
||||
"firstname1",
|
||||
"lastname1",
|
||||
"nickname1",
|
||||
"displayname1",
|
||||
language.German,
|
||||
domain.GenderMale,
|
||||
"email1",
|
||||
true,
|
||||
),
|
||||
)(t)}).reduceAdded,
|
||||
es: newMockEventStore().appendFilterResponse(
|
||||
[]eventstore.Event{
|
||||
user.NewHumanAddedEvent(context.Background(),
|
||||
&user.NewAggregate("user-id", "org1").Aggregate,
|
||||
"username1",
|
||||
"firstname1",
|
||||
"lastname1",
|
||||
"nickname1",
|
||||
"displayname1",
|
||||
language.German,
|
||||
domain.GenderMale,
|
||||
"email1",
|
||||
true,
|
||||
),
|
||||
},
|
||||
),
|
||||
}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -66,7 +68,7 @@ func TestInstanceMemberProjection_reduces(t *testing.T) {
|
||||
"user-id",
|
||||
"org1",
|
||||
false,
|
||||
database.StringArray{"role"},
|
||||
database.TextArray[string]{"role"},
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -83,26 +85,26 @@ func TestInstanceMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance MemberChangedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.MemberChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.MemberChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"userId": "user-id",
|
||||
"roles": ["role", "changed"]
|
||||
}`),
|
||||
), instance.MemberChangedEventMapper),
|
||||
), instance.MemberChangedEventMapper),
|
||||
},
|
||||
reduce: (&instanceMemberProjection{}).reduceChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.instance_members3 SET (roles, change_date, sequence) = ($1, $2, $3) WHERE (instance_id = $4) AND (user_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
database.StringArray{"role", "changed"},
|
||||
database.TextArray[string]{"role", "changed"},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"instance-id",
|
||||
@@ -116,19 +118,19 @@ func TestInstanceMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance MemberCascadeRemovedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.MemberCascadeRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.MemberCascadeRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"userId": "user-id"
|
||||
}`),
|
||||
), instance.MemberCascadeRemovedEventMapper),
|
||||
), instance.MemberCascadeRemovedEventMapper),
|
||||
},
|
||||
reduce: (&instanceMemberProjection{}).reduceCascadeRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -145,19 +147,19 @@ func TestInstanceMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance MemberRemovedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.MemberRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.MemberRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"userId": "user-id"
|
||||
}`),
|
||||
), instance.MemberRemovedEventMapper),
|
||||
), instance.MemberRemovedEventMapper),
|
||||
},
|
||||
reduce: (&instanceMemberProjection{}).reduceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: instance.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -174,17 +176,17 @@ func TestInstanceMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "user UserRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.UserRemovedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), user.UserRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.UserRemovedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), user.UserRemovedEventMapper),
|
||||
},
|
||||
reduce: (&instanceMemberProjection{}).reduceUserRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -201,17 +203,17 @@ func TestInstanceMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org.OrgRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
reduce: (&instanceMemberProjection{}).reduceUserOwnerRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -228,17 +230,17 @@ func TestInstanceMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(MemberInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -5,8 +5,7 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
@@ -23,17 +22,17 @@ func TestInstanceProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceInstanceAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"name": "Name"}`),
|
||||
), instance.InstanceAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"name": "Name"}`),
|
||||
), instance.InstanceAddedEventMapper),
|
||||
},
|
||||
reduce: (&instanceProjection{}).reduceInstanceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -53,17 +52,17 @@ func TestInstanceProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(InstanceColumnID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -79,17 +78,17 @@ func TestInstanceProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceDefaultOrgSet",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.DefaultOrgSetEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"orgId": "orgid"}`),
|
||||
), instance.DefaultOrgSetMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.DefaultOrgSetEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"orgId": "orgid"}`),
|
||||
), instance.DefaultOrgSetMapper),
|
||||
},
|
||||
reduce: (&instanceProjection{}).reduceDefaultOrgSet,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -108,17 +107,17 @@ func TestInstanceProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectIDSet",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.ProjectSetEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"iamProjectId": "project-id"}`),
|
||||
), instance.ProjectSetMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.ProjectSetEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"iamProjectId": "project-id"}`),
|
||||
), instance.ProjectSetMapper),
|
||||
},
|
||||
reduce: (&instanceProjection{}).reduceIAMProjectSet,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -137,17 +136,17 @@ func TestInstanceProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceDefaultLanguageSet",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.DefaultLanguageSetEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"language": "en"}`),
|
||||
), instance.DefaultLanguageSetMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.DefaultLanguageSetEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"language": "en"}`),
|
||||
), instance.DefaultLanguageSetMapper),
|
||||
},
|
||||
reduce: (&instanceProjection{}).reduceDefaultLanguageSet,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/keypair"
|
||||
)
|
||||
@@ -48,71 +48,74 @@ const (
|
||||
)
|
||||
|
||||
type keyProjection struct {
|
||||
crdb.StatementHandler
|
||||
encryptionAlgorithm crypto.EncryptionAlgorithm
|
||||
certEncryptionAlgorithm crypto.EncryptionAlgorithm
|
||||
}
|
||||
|
||||
func newKeyProjection(ctx context.Context, config crdb.StatementHandlerConfig, keyEncryptionAlgorithm crypto.EncryptionAlgorithm, certEncryptionAlgorithm crypto.EncryptionAlgorithm) *keyProjection {
|
||||
p := new(keyProjection)
|
||||
config.ProjectionName = KeyProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewMultiTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(KeyColumnID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(KeyColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(KeyColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(KeyColumnResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(KeyColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(KeyColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(KeyColumnAlgorithm, crdb.ColumnTypeText, crdb.Default("")),
|
||||
crdb.NewColumn(KeyColumnUse, crdb.ColumnTypeEnum, crdb.Default(0)),
|
||||
},
|
||||
crdb.NewPrimaryKey(KeyColumnInstanceID, KeyColumnID),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(KeyPrivateColumnID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(KeyPrivateColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(KeyPrivateColumnExpiry, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(KeyPrivateColumnKey, crdb.ColumnTypeJSONB),
|
||||
},
|
||||
crdb.NewPrimaryKey(KeyPrivateColumnInstanceID, KeyPrivateColumnID),
|
||||
privateKeyTableSuffix,
|
||||
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(KeyPublicColumnID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(KeyPublicColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(KeyPublicColumnExpiry, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(KeyPublicColumnKey, crdb.ColumnTypeBytes),
|
||||
},
|
||||
crdb.NewPrimaryKey(KeyPublicColumnInstanceID, KeyPublicColumnID),
|
||||
publicKeyTableSuffix,
|
||||
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(CertificateColumnID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(CertificateColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(CertificateColumnExpiry, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(CertificateColumnCertificate, crdb.ColumnTypeBytes),
|
||||
},
|
||||
crdb.NewPrimaryKey(CertificateColumnInstanceID, CertificateColumnID),
|
||||
certificateTableSuffix,
|
||||
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
|
||||
),
|
||||
)
|
||||
p.encryptionAlgorithm = keyEncryptionAlgorithm
|
||||
p.certEncryptionAlgorithm = certEncryptionAlgorithm
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
|
||||
return p
|
||||
func newKeyProjection(ctx context.Context, config handler.Config, keyEncryptionAlgorithm, certEncryptionAlgorithm crypto.EncryptionAlgorithm) *handler.Handler {
|
||||
p := &keyProjection{
|
||||
encryptionAlgorithm: keyEncryptionAlgorithm,
|
||||
certEncryptionAlgorithm: certEncryptionAlgorithm,
|
||||
}
|
||||
return handler.NewHandler(ctx, &config, p)
|
||||
}
|
||||
|
||||
func (p *keyProjection) reducers() []handler.AggregateReducer {
|
||||
func (*keyProjection) Name() string {
|
||||
return KeyProjectionTable
|
||||
}
|
||||
|
||||
func (*keyProjection) Init() *old_handler.Check {
|
||||
return handler.NewMultiTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(KeyColumnID, handler.ColumnTypeText),
|
||||
handler.NewColumn(KeyColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(KeyColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(KeyColumnResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(KeyColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(KeyColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(KeyColumnAlgorithm, handler.ColumnTypeText, handler.Default("")),
|
||||
handler.NewColumn(KeyColumnUse, handler.ColumnTypeEnum, handler.Default(0)),
|
||||
},
|
||||
handler.NewPrimaryKey(KeyColumnInstanceID, KeyColumnID),
|
||||
),
|
||||
handler.NewSuffixedTable([]*handler.InitColumn{
|
||||
handler.NewColumn(KeyPrivateColumnID, handler.ColumnTypeText),
|
||||
handler.NewColumn(KeyPrivateColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(KeyPrivateColumnExpiry, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(KeyPrivateColumnKey, handler.ColumnTypeJSONB),
|
||||
},
|
||||
handler.NewPrimaryKey(KeyPrivateColumnInstanceID, KeyPrivateColumnID),
|
||||
privateKeyTableSuffix,
|
||||
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
|
||||
),
|
||||
handler.NewSuffixedTable([]*handler.InitColumn{
|
||||
handler.NewColumn(KeyPublicColumnID, handler.ColumnTypeText),
|
||||
handler.NewColumn(KeyPublicColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(KeyPublicColumnExpiry, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(KeyPublicColumnKey, handler.ColumnTypeBytes),
|
||||
},
|
||||
handler.NewPrimaryKey(KeyPublicColumnInstanceID, KeyPublicColumnID),
|
||||
publicKeyTableSuffix,
|
||||
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
|
||||
),
|
||||
handler.NewSuffixedTable([]*handler.InitColumn{
|
||||
handler.NewColumn(CertificateColumnID, handler.ColumnTypeText),
|
||||
handler.NewColumn(CertificateColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(CertificateColumnExpiry, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(CertificateColumnCertificate, handler.ColumnTypeBytes),
|
||||
},
|
||||
handler.NewPrimaryKey(CertificateColumnInstanceID, CertificateColumnID),
|
||||
certificateTableSuffix,
|
||||
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
func (p *keyProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: keypair.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: keypair.AddedEventType,
|
||||
Reduce: p.reduceKeyPairAdded,
|
||||
@@ -125,7 +128,7 @@ func (p *keyProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(KeyColumnInstanceID),
|
||||
@@ -141,10 +144,10 @@ func (p *keyProjection) reduceKeyPairAdded(event eventstore.Event) (*handler.Sta
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-SAbr2", "reduce.wrong.event.type %s", keypair.AddedEventType)
|
||||
}
|
||||
if e.PrivateKey.Expiry.Before(time.Now()) && e.PublicKey.Expiry.Before(time.Now()) {
|
||||
return crdb.NewNoOpStatement(e), nil
|
||||
return handler.NewNoOpStatement(e), nil
|
||||
}
|
||||
creates := []func(eventstore.Event) crdb.Exec{
|
||||
crdb.AddCreateStatement(
|
||||
creates := []func(eventstore.Event) handler.Exec{
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(KeyColumnID, e.Aggregate().ID),
|
||||
handler.NewCol(KeyColumnCreationDate, e.CreationDate()),
|
||||
@@ -158,14 +161,14 @@ func (p *keyProjection) reduceKeyPairAdded(event eventstore.Event) (*handler.Sta
|
||||
),
|
||||
}
|
||||
if e.PrivateKey.Expiry.After(time.Now()) {
|
||||
creates = append(creates, crdb.AddCreateStatement(
|
||||
creates = append(creates, handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(KeyPrivateColumnID, e.Aggregate().ID),
|
||||
handler.NewCol(KeyPrivateColumnInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCol(KeyPrivateColumnExpiry, e.PrivateKey.Expiry),
|
||||
handler.NewCol(KeyPrivateColumnKey, e.PrivateKey.Key),
|
||||
},
|
||||
crdb.WithTableSuffix(privateKeyTableSuffix),
|
||||
handler.WithTableSuffix(privateKeyTableSuffix),
|
||||
))
|
||||
}
|
||||
if e.PublicKey.Expiry.After(time.Now()) {
|
||||
@@ -173,18 +176,18 @@ func (p *keyProjection) reduceKeyPairAdded(event eventstore.Event) (*handler.Sta
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "HANDL-DAg2f", "cannot decrypt public key")
|
||||
}
|
||||
creates = append(creates, crdb.AddCreateStatement(
|
||||
creates = append(creates, handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(KeyPublicColumnID, e.Aggregate().ID),
|
||||
handler.NewCol(KeyPublicColumnInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCol(KeyPublicColumnExpiry, e.PublicKey.Expiry),
|
||||
handler.NewCol(KeyPublicColumnKey, publicKey),
|
||||
},
|
||||
crdb.WithTableSuffix(publicKeyTableSuffix),
|
||||
handler.WithTableSuffix(publicKeyTableSuffix),
|
||||
))
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(e, creates...), nil
|
||||
return handler.NewMultiStatement(e, creates...), nil
|
||||
}
|
||||
|
||||
func (p *keyProjection) reduceCertificateAdded(event eventstore.Event) (*handler.Statement, error) {
|
||||
@@ -194,7 +197,7 @@ func (p *keyProjection) reduceCertificateAdded(event eventstore.Event) (*handler
|
||||
}
|
||||
|
||||
if e.Certificate.Expiry.Before(time.Now()) {
|
||||
return crdb.NewNoOpStatement(e), nil
|
||||
return handler.NewNoOpStatement(e), nil
|
||||
}
|
||||
|
||||
certificate, err := crypto.Decrypt(e.Certificate.Key, p.certEncryptionAlgorithm)
|
||||
@@ -202,15 +205,15 @@ func (p *keyProjection) reduceCertificateAdded(event eventstore.Event) (*handler
|
||||
return nil, errors.ThrowInternal(err, "HANDL-Dajwig2f", "cannot decrypt certificate")
|
||||
}
|
||||
|
||||
creates := []func(eventstore.Event) crdb.Exec{crdb.AddCreateStatement(
|
||||
creates := []func(eventstore.Event) handler.Exec{handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(CertificateColumnID, e.Aggregate().ID),
|
||||
handler.NewCol(CertificateColumnInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCol(CertificateColumnExpiry, e.Certificate.Expiry),
|
||||
handler.NewCol(CertificateColumnCertificate, certificate),
|
||||
},
|
||||
crdb.WithTableSuffix(certificateTableSuffix),
|
||||
handler.WithTableSuffix(certificateTableSuffix),
|
||||
)}
|
||||
|
||||
return crdb.NewMultiStatement(e, creates...), nil
|
||||
return handler.NewMultiStatement(e, creates...), nil
|
||||
}
|
||||
|
||||
@@ -11,8 +11,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/keypair"
|
||||
)
|
||||
@@ -30,17 +29,17 @@ func TestKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceKeyPairAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(keypair.AddedEventType),
|
||||
keypair.AggregateType,
|
||||
keypairAddedEventData(domain.KeyUsageSigning, time.Now().Add(time.Hour)),
|
||||
), keypair.AddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
keypair.AddedEventType,
|
||||
keypair.AggregateType,
|
||||
keypairAddedEventData(domain.KeyUsageSigning, time.Now().Add(time.Hour)),
|
||||
), keypair.AddedEventMapper),
|
||||
},
|
||||
reduce: (&keyProjection{encryptionAlgorithm: crypto.CreateMockEncryptionAlg(gomock.NewController(t))}).reduceKeyPairAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("key_pair"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("key_pair"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -86,34 +85,34 @@ func TestKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceKeyPairAdded expired",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(keypair.AddedEventType),
|
||||
keypair.AggregateType,
|
||||
keypairAddedEventData(domain.KeyUsageSigning, time.Now().Add(-time.Hour)),
|
||||
), keypair.AddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
keypair.AddedEventType,
|
||||
keypair.AggregateType,
|
||||
keypairAddedEventData(domain.KeyUsageSigning, time.Now().Add(-time.Hour)),
|
||||
), keypair.AddedEventMapper),
|
||||
},
|
||||
reduce: (&keyProjection{}).reduceKeyPairAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("key_pair"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
executer: &testExecuter{},
|
||||
aggregateType: eventstore.AggregateType("key_pair"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(KeyColumnInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -129,17 +128,17 @@ func TestKeyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceCertificateAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(keypair.AddedCertificateEventType),
|
||||
keypair.AggregateType,
|
||||
certificateAddedEventData(domain.KeyUsageSAMLMetadataSigning, time.Now().Add(time.Hour)),
|
||||
), keypair.AddedCertificateEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
keypair.AddedCertificateEventType,
|
||||
keypair.AggregateType,
|
||||
certificateAddedEventData(domain.KeyUsageSAMLMetadataSigning, time.Now().Add(time.Hour)),
|
||||
), keypair.AddedCertificateEventMapper),
|
||||
},
|
||||
reduce: (&keyProjection{certEncryptionAlgorithm: crypto.CreateMockEncryptionAlg(gomock.NewController(t))}).reduceCertificateAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("key_pair"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("key_pair"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
@@ -45,55 +45,56 @@ const (
|
||||
LabelPolicyDarkIconURLCol = "dark_icon_url"
|
||||
)
|
||||
|
||||
type labelPolicyProjection struct {
|
||||
crdb.StatementHandler
|
||||
type labelPolicyProjection struct{}
|
||||
|
||||
func newLabelPolicyProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(labelPolicyProjection))
|
||||
}
|
||||
|
||||
func newLabelPolicyProjection(ctx context.Context, config crdb.StatementHandlerConfig) *labelPolicyProjection {
|
||||
p := new(labelPolicyProjection)
|
||||
config.ProjectionName = LabelPolicyTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(LabelPolicyIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LabelPolicyCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(LabelPolicyChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(LabelPolicySequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(LabelPolicyStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(LabelPolicyIsDefaultCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(LabelPolicyResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LabelPolicyInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LabelPolicyHideLoginNameSuffixCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(LabelPolicyWatermarkDisabledCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(LabelPolicyShouldErrorPopupCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(LabelPolicyFontURLCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyLightPrimaryColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyLightWarnColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyLightBackgroundColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyLightFontColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyLightLogoURLCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyLightIconURLCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyDarkPrimaryColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyDarkWarnColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyDarkBackgroundColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyDarkFontColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyDarkLogoURLCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyDarkIconURLCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*labelPolicyProjection) Name() string {
|
||||
return LabelPolicyTable
|
||||
}
|
||||
|
||||
func (*labelPolicyProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(LabelPolicyIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LabelPolicyCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(LabelPolicyChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(LabelPolicySequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(LabelPolicyStateCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(LabelPolicyIsDefaultCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(LabelPolicyResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LabelPolicyInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LabelPolicyHideLoginNameSuffixCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(LabelPolicyWatermarkDisabledCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(LabelPolicyShouldErrorPopupCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(LabelPolicyFontURLCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyLightPrimaryColorCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyLightWarnColorCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyLightBackgroundColorCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyLightFontColorCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyLightLogoURLCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyLightIconURLCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyDarkPrimaryColorCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyDarkWarnColorCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyDarkBackgroundColorCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyDarkFontColorCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyDarkLogoURLCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyDarkIconURLCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(LabelPolicyInstanceIDCol, LabelPolicyIDCol, LabelPolicyStateCol),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{LabelPolicyOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(LabelPolicyInstanceIDCol, LabelPolicyIDCol, LabelPolicyStateCol),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{LabelPolicyOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *labelPolicyProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *labelPolicyProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.LabelPolicyAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -162,7 +163,7 @@ func (p *labelPolicyProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.LabelPolicyAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -241,11 +242,11 @@ func (p *labelPolicyProjection) reduceAdded(event eventstore.Event) (*handler.St
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-CSE7A", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyAddedEventType, instance.LabelPolicyAddedEventType})
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
&policyEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyCreationDateCol, policyEvent.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, policyEvent.CreationDate()),
|
||||
handler.NewCol(LabelPolicyCreationDateCol, policyEvent.CreatedAt()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, policyEvent.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, policyEvent.Sequence()),
|
||||
handler.NewCol(LabelPolicyIDCol, policyEvent.Aggregate().ID),
|
||||
handler.NewCol(LabelPolicyStateCol, domain.LabelPolicyStatePreview),
|
||||
@@ -277,7 +278,7 @@ func (p *labelPolicyProjection) reduceChanged(event eventstore.Event) (*handler.
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-qgVug", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyChangedEventType, instance.LabelPolicyChangedEventType})
|
||||
}
|
||||
cols := []handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, policyEvent.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, policyEvent.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, policyEvent.Sequence()),
|
||||
}
|
||||
if policyEvent.PrimaryColor != nil {
|
||||
@@ -313,7 +314,7 @@ func (p *labelPolicyProjection) reduceChanged(event eventstore.Event) (*handler.
|
||||
if policyEvent.DisableWatermark != nil {
|
||||
cols = append(cols, handler.NewCol(LabelPolicyWatermarkDisabledCol, *policyEvent.DisableWatermark))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&policyEvent,
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
@@ -328,7 +329,7 @@ func (p *labelPolicyProjection) reduceRemoved(event eventstore.Event) (*handler.
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-ATMBz", "reduce.wrong.event.type %s", org.LabelPolicyRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
policyEvent,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LabelPolicyIDCol, policyEvent.Aggregate().ID),
|
||||
@@ -343,7 +344,7 @@ func (p *labelPolicyProjection) reduceActivated(event eventstore.Event) (*handle
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-dldEU", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyActivatedEventType, instance.LabelPolicyActivatedEventType})
|
||||
}
|
||||
return crdb.NewCopyStatement(
|
||||
return handler.NewCopyStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyInstanceIDCol, nil),
|
||||
@@ -351,7 +352,7 @@ func (p *labelPolicyProjection) reduceActivated(event eventstore.Event) (*handle
|
||||
handler.NewCol(LabelPolicyStateCol, nil),
|
||||
},
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, event.Sequence()),
|
||||
handler.NewCol(LabelPolicyStateCol, domain.LabelPolicyStateActive),
|
||||
handler.NewCol(LabelPolicyCreationDateCol, nil),
|
||||
@@ -424,10 +425,10 @@ func (p *labelPolicyProjection) reduceLogoAdded(event eventstore.Event) (*handle
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-4wbOI", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyLogoAddedEventType, instance.LabelPolicyLogoAddedEventType, org.LabelPolicyLogoDarkAddedEventType, instance.LabelPolicyLogoDarkAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, event.Sequence()),
|
||||
storeKey,
|
||||
},
|
||||
@@ -453,10 +454,10 @@ func (p *labelPolicyProjection) reduceLogoRemoved(event eventstore.Event) (*hand
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-kg8H4", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyLogoRemovedEventType, instance.LabelPolicyLogoRemovedEventType, org.LabelPolicyLogoDarkRemovedEventType, instance.LabelPolicyLogoDarkRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, event.Sequence()),
|
||||
handler.NewCol(col, nil),
|
||||
},
|
||||
@@ -482,10 +483,10 @@ func (p *labelPolicyProjection) reduceIconAdded(event eventstore.Event) (*handle
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-e2JFz", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyIconAddedEventType, instance.LabelPolicyIconAddedEventType, org.LabelPolicyIconDarkAddedEventType, instance.LabelPolicyIconDarkAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, event.Sequence()),
|
||||
storeKey,
|
||||
},
|
||||
@@ -511,10 +512,10 @@ func (p *labelPolicyProjection) reduceIconRemoved(event eventstore.Event) (*hand
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-gfgbY", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyIconRemovedEventType, instance.LabelPolicyIconRemovedEventType, org.LabelPolicyIconDarkRemovedEventType, instance.LabelPolicyIconDarkRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, event.Sequence()),
|
||||
handler.NewCol(col, nil),
|
||||
},
|
||||
@@ -536,10 +537,10 @@ func (p *labelPolicyProjection) reduceFontAdded(event eventstore.Event) (*handle
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-65i9W", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyFontAddedEventType, instance.LabelPolicyFontAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, event.Sequence()),
|
||||
storeKey,
|
||||
},
|
||||
@@ -561,10 +562,10 @@ func (p *labelPolicyProjection) reduceFontRemoved(event eventstore.Event) (*hand
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-xf32J", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyFontRemovedEventType, instance.LabelPolicyFontRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, event.Sequence()),
|
||||
handler.NewCol(col, nil),
|
||||
},
|
||||
@@ -583,10 +584,10 @@ func (p *labelPolicyProjection) reduceAssetsRemoved(event eventstore.Event) (*ha
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-qi39A", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyAssetsRemovedEventType, instance.LabelPolicyAssetsRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, event.Sequence()),
|
||||
handler.NewCol(LabelPolicyLightLogoURLCol, nil),
|
||||
handler.NewCol(LabelPolicyLightIconURLCol, nil),
|
||||
@@ -607,7 +608,7 @@ func (p *labelPolicyProjection) reduceOwnerRemoved(event eventstore.Event) (*han
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Su6pX", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LabelPolicyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -25,17 +24,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LabelPolicyAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"backgroundColor": "#141735", "fontColor": "#ffffff", "primaryColor": "#5282c1", "warnColor": "#ff3b5b"}`),
|
||||
), org.LabelPolicyAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LabelPolicyAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"backgroundColor": "#141735", "fontColor": "#ffffff", "primaryColor": "#5282c1", "warnColor": "#ff3b5b"}`),
|
||||
), org.LabelPolicyAddedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -69,17 +68,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LabelPolicyChangedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"backgroundColor": "#141735", "fontColor": "#ffffff", "primaryColor": "#5282c1", "warnColor": "#ff3b5b"}`),
|
||||
), org.LabelPolicyChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LabelPolicyChangedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"backgroundColor": "#141735", "fontColor": "#ffffff", "primaryColor": "#5282c1", "warnColor": "#ff3b5b"}`),
|
||||
), org.LabelPolicyChangedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -103,17 +102,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LabelPolicyRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.LabelPolicyRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LabelPolicyRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.LabelPolicyRemovedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -130,17 +129,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(LabelPolicyInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -156,17 +155,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceActivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LabelPolicyActivatedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.LabelPolicyActivatedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LabelPolicyActivatedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.LabelPolicyActivatedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceActivated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -187,17 +186,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceLogoAdded light",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LabelPolicyLogoAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/logo.png"}`),
|
||||
), org.LabelPolicyLogoAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LabelPolicyLogoAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/logo.png"}`),
|
||||
), org.LabelPolicyLogoAddedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceLogoAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -218,17 +217,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceLogoAdded dark",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LabelPolicyLogoDarkAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/logo.png"}`),
|
||||
), org.LabelPolicyLogoDarkAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LabelPolicyLogoDarkAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/logo.png"}`),
|
||||
), org.LabelPolicyLogoDarkAddedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceLogoAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -249,17 +248,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceIconAdded light",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LabelPolicyIconAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/icon.png"}`),
|
||||
), org.LabelPolicyIconAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LabelPolicyIconAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/icon.png"}`),
|
||||
), org.LabelPolicyIconAddedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceIconAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -280,17 +279,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceIconAdded dark",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LabelPolicyIconDarkAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/icon.png"}`),
|
||||
), org.LabelPolicyIconDarkAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LabelPolicyIconDarkAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/icon.png"}`),
|
||||
), org.LabelPolicyIconDarkAddedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceIconAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -311,17 +310,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceLogoRemoved light",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LabelPolicyLogoRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/logo.png"}`),
|
||||
), org.LabelPolicyLogoRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LabelPolicyLogoRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/logo.png"}`),
|
||||
), org.LabelPolicyLogoRemovedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceLogoRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -342,17 +341,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceLogoRemoved dark",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LabelPolicyLogoDarkRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/logo.png"}`),
|
||||
), org.LabelPolicyLogoDarkRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LabelPolicyLogoDarkRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/logo.png"}`),
|
||||
), org.LabelPolicyLogoDarkRemovedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceLogoRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -373,17 +372,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceIconRemoved light",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LabelPolicyIconRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/icon.png"}`),
|
||||
), org.LabelPolicyIconRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LabelPolicyIconRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/icon.png"}`),
|
||||
), org.LabelPolicyIconRemovedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceIconRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -404,17 +403,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceIconRemoved dark",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LabelPolicyIconDarkRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/icon.png"}`),
|
||||
), org.LabelPolicyIconDarkRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LabelPolicyIconDarkRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/icon.png"}`),
|
||||
), org.LabelPolicyIconDarkRemovedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceIconRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -435,17 +434,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceFontAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LabelPolicyFontAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/font.ttf"}`),
|
||||
), org.LabelPolicyFontAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LabelPolicyFontAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/font.ttf"}`),
|
||||
), org.LabelPolicyFontAddedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceFontAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -466,17 +465,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceFontRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LabelPolicyFontRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/font.ttf"}`),
|
||||
), org.LabelPolicyFontRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LabelPolicyFontRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/font.ttf"}`),
|
||||
), org.LabelPolicyFontRemovedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceFontRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -497,17 +496,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceAssetsRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LabelPolicyAssetsRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.LabelPolicyAssetsRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LabelPolicyAssetsRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.LabelPolicyAssetsRemovedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceAssetsRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -532,17 +531,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LabelPolicyAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"backgroundColor": "#141735", "fontColor": "#ffffff", "primaryColor": "#5282c1", "warnColor": "#ff3b5b"}`),
|
||||
), instance.LabelPolicyAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LabelPolicyAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"backgroundColor": "#141735", "fontColor": "#ffffff", "primaryColor": "#5282c1", "warnColor": "#ff3b5b"}`),
|
||||
), instance.LabelPolicyAddedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -576,17 +575,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LabelPolicyChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"backgroundColor": "#141735", "fontColor": "#ffffff", "primaryColor": "#5282c1", "warnColor": "#ff3b5b", "primaryColorDark": "#ffffff","backgroundColorDark": "#ffffff", "warnColorDark": "#ffffff", "fontColorDark": "#ffffff", "hideLoginNameSuffix": true, "errorMsgPopup": true, "disableWatermark": true}`),
|
||||
), instance.LabelPolicyChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LabelPolicyChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"backgroundColor": "#141735", "fontColor": "#ffffff", "primaryColor": "#5282c1", "warnColor": "#ff3b5b", "primaryColorDark": "#ffffff","backgroundColorDark": "#ffffff", "warnColorDark": "#ffffff", "fontColorDark": "#ffffff", "hideLoginNameSuffix": true, "errorMsgPopup": true, "disableWatermark": true}`),
|
||||
), instance.LabelPolicyChangedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -617,17 +616,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceActivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LabelPolicyActivatedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.LabelPolicyActivatedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LabelPolicyActivatedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.LabelPolicyActivatedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceActivated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -648,17 +647,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceLogoAdded light",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LabelPolicyLogoAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/logo.png"}`),
|
||||
), instance.LabelPolicyLogoAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LabelPolicyLogoAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/logo.png"}`),
|
||||
), instance.LabelPolicyLogoAddedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceLogoAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -679,17 +678,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceLogoAdded dark",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LabelPolicyLogoDarkAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/logo.png"}`),
|
||||
), instance.LabelPolicyLogoDarkAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LabelPolicyLogoDarkAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/logo.png"}`),
|
||||
), instance.LabelPolicyLogoDarkAddedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceLogoAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -710,17 +709,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceIconAdded light",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LabelPolicyIconAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/icon.png"}`),
|
||||
), instance.LabelPolicyIconAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LabelPolicyIconAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/icon.png"}`),
|
||||
), instance.LabelPolicyIconAddedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceIconAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -741,17 +740,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceIconAdded dark",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LabelPolicyIconDarkAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/icon.png"}`),
|
||||
), instance.LabelPolicyIconDarkAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LabelPolicyIconDarkAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/icon.png"}`),
|
||||
), instance.LabelPolicyIconDarkAddedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceIconAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -772,17 +771,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceLogoRemoved light",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LabelPolicyLogoRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/logo.png"}`),
|
||||
), instance.LabelPolicyLogoRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LabelPolicyLogoRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/logo.png"}`),
|
||||
), instance.LabelPolicyLogoRemovedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceLogoRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -803,17 +802,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceLogoRemoved dark",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LabelPolicyLogoDarkRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/logo.png"}`),
|
||||
), instance.LabelPolicyLogoDarkRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LabelPolicyLogoDarkRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/logo.png"}`),
|
||||
), instance.LabelPolicyLogoDarkRemovedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceLogoRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -834,17 +833,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceIconRemoved light",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LabelPolicyIconRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/icon.png"}`),
|
||||
), instance.LabelPolicyIconRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LabelPolicyIconRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/icon.png"}`),
|
||||
), instance.LabelPolicyIconRemovedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceIconRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -865,17 +864,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceIconRemoved dark",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LabelPolicyIconDarkRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/icon.png"}`),
|
||||
), instance.LabelPolicyIconDarkRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LabelPolicyIconDarkRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/icon.png"}`),
|
||||
), instance.LabelPolicyIconDarkRemovedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceIconRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -896,17 +895,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceFontAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LabelPolicyFontAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/font.ttf"}`),
|
||||
), instance.LabelPolicyFontAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LabelPolicyFontAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/font.ttf"}`),
|
||||
), instance.LabelPolicyFontAddedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceFontAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -927,17 +926,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceFontRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LabelPolicyFontRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/font.ttf"}`),
|
||||
), instance.LabelPolicyFontRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LabelPolicyFontRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"storeKey": "/path/to/font.ttf"}`),
|
||||
), instance.LabelPolicyFontRemovedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceFontRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -958,17 +957,17 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceAssetsRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LabelPolicyAssetsRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.LabelPolicyAssetsRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LabelPolicyAssetsRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.LabelPolicyAssetsRemovedEventMapper),
|
||||
},
|
||||
reduce: (&labelPolicyProjection{}).reduceAssetsRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -994,16 +993,16 @@ func TestLabelPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (&labelPolicyProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
@@ -29,41 +29,42 @@ const (
|
||||
LockoutPolicyOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type lockoutPolicyProjection struct {
|
||||
crdb.StatementHandler
|
||||
type lockoutPolicyProjection struct{}
|
||||
|
||||
func newLockoutPolicyProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(lockoutPolicyProjection))
|
||||
}
|
||||
|
||||
func newLockoutPolicyProjection(ctx context.Context, config crdb.StatementHandlerConfig) *lockoutPolicyProjection {
|
||||
p := new(lockoutPolicyProjection)
|
||||
config.ProjectionName = LockoutPolicyTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(LockoutPolicyIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LockoutPolicyCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(LockoutPolicyChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(LockoutPolicySequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(LockoutPolicyStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(LockoutPolicyIsDefaultCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(LockoutPolicyResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LockoutPolicyInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LockoutPolicyMaxPasswordAttemptsCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(LockoutPolicyShowLockOutFailuresCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(LockoutPolicyOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*lockoutPolicyProjection) Name() string {
|
||||
return LockoutPolicyTable
|
||||
}
|
||||
|
||||
func (*lockoutPolicyProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(LockoutPolicyIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LockoutPolicyCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(LockoutPolicyChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(LockoutPolicySequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(LockoutPolicyStateCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(LockoutPolicyIsDefaultCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(LockoutPolicyResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LockoutPolicyInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LockoutPolicyMaxPasswordAttemptsCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(LockoutPolicyShowLockOutFailuresCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(LockoutPolicyOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(LockoutPolicyInstanceIDCol, LockoutPolicyIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{LockoutPolicyOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(LockoutPolicyInstanceIDCol, LockoutPolicyIDCol),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{LockoutPolicyOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *lockoutPolicyProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *lockoutPolicyProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.LockoutPolicyAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -84,7 +85,7 @@ func (p *lockoutPolicyProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.LockoutPolicyAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -115,7 +116,7 @@ func (p *lockoutPolicyProjection) reduceAdded(event eventstore.Event) (*handler.
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-d8mZO", "reduce.wrong.event.type, %v", []eventstore.EventType{org.LockoutPolicyAddedEventType, instance.LockoutPolicyAddedEventType})
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
&policyEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LockoutPolicyCreationDateCol, policyEvent.CreationDate()),
|
||||
@@ -151,7 +152,7 @@ func (p *lockoutPolicyProjection) reduceChanged(event eventstore.Event) (*handle
|
||||
if policyEvent.ShowLockOutFailures != nil {
|
||||
cols = append(cols, handler.NewCol(LockoutPolicyShowLockOutFailuresCol, *policyEvent.ShowLockOutFailures))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&policyEvent,
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
@@ -165,7 +166,7 @@ func (p *lockoutPolicyProjection) reduceRemoved(event eventstore.Event) (*handle
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Bqut9", "reduce.wrong.event.type %s", org.LockoutPolicyRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
policyEvent,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LockoutPolicyIDCol, policyEvent.Aggregate().ID),
|
||||
@@ -179,7 +180,7 @@ func (p *lockoutPolicyProjection) reduceOwnerRemoved(event eventstore.Event) (*h
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-IoW0x", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LockoutPolicyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -25,20 +24,20 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LockoutPolicyAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LockoutPolicyAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"maxPasswordAttempts": 10,
|
||||
"showLockOutFailures": true
|
||||
}`),
|
||||
), org.LockoutPolicyAddedEventMapper),
|
||||
), org.LockoutPolicyAddedEventMapper),
|
||||
},
|
||||
reduce: (&lockoutPolicyProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -64,19 +63,19 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org reduceChanged",
|
||||
reduce: (&lockoutPolicyProjection{}).reduceChanged,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LockoutPolicyChangedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LockoutPolicyChangedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"maxPasswordAttempts": 10,
|
||||
"showLockOutFailures": true
|
||||
}`),
|
||||
), org.LockoutPolicyChangedEventMapper),
|
||||
), org.LockoutPolicyChangedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -98,16 +97,16 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org reduceRemoved",
|
||||
reduce: (&lockoutPolicyProjection{}).reduceRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LockoutPolicyRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.LockoutPolicyRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LockoutPolicyRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.LockoutPolicyRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -124,17 +123,17 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(LockoutPolicyInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -151,19 +150,19 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceAdded",
|
||||
reduce: (&lockoutPolicyProjection{}).reduceAdded,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LockoutPolicyAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LockoutPolicyAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"maxPasswordAttempts": 10,
|
||||
"showLockOutFailures": true
|
||||
}`),
|
||||
), instance.LockoutPolicyAddedEventMapper),
|
||||
), instance.LockoutPolicyAddedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -189,19 +188,19 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceChanged",
|
||||
reduce: (&lockoutPolicyProjection{}).reduceChanged,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LockoutPolicyChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LockoutPolicyChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"maxPasswordAttempts": 10,
|
||||
"showLockOutFailures": true
|
||||
}`),
|
||||
), instance.LockoutPolicyChangedEventMapper),
|
||||
), instance.LockoutPolicyChangedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -223,16 +222,16 @@ func TestLockoutPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (&lockoutPolicyProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
@@ -171,61 +171,73 @@ func whenThenElse(when, then, el string) string {
|
||||
return "(CASE WHEN " + when + " THEN " + then + " ELSE " + el + " END)"
|
||||
}
|
||||
|
||||
type loginNameProjection struct {
|
||||
crdb.StatementHandler
|
||||
type loginNameProjection struct{}
|
||||
|
||||
func newLoginNameProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(loginNameProjection))
|
||||
}
|
||||
|
||||
func newLoginNameProjection(ctx context.Context, config crdb.StatementHandlerConfig) *loginNameProjection {
|
||||
p := new(loginNameProjection)
|
||||
config.ProjectionName = LoginNameProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewViewCheck(
|
||||
func (*loginNameProjection) Name() string {
|
||||
return LoginNameProjectionTable
|
||||
}
|
||||
|
||||
func (*loginNameProjection) Init() *old_handler.Check {
|
||||
return handler.NewViewCheck(
|
||||
viewStmt,
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(LoginNameUserIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginNameUserUserNameCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginNameUserResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginNameUserInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginNameUserOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(LoginNameUserInstanceIDCol, LoginNameUserIDCol),
|
||||
handler.NewSuffixedTable(
|
||||
[]*handler.InitColumn{
|
||||
handler.NewColumn(LoginNameUserIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LoginNameUserUserNameCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LoginNameUserResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LoginNameUserInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LoginNameUserOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
handler.NewPrimaryKey(LoginNameUserInstanceIDCol, LoginNameUserIDCol),
|
||||
loginNameUserSuffix,
|
||||
crdb.WithIndex(crdb.NewIndex("resource_owner", []string{LoginNameUserResourceOwnerCol})),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{LoginNameUserOwnerRemovedCol})),
|
||||
handler.WithIndex(handler.NewIndex("resource_owner", []string{LoginNameUserResourceOwnerCol})),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{LoginNameUserOwnerRemovedCol})),
|
||||
handler.WithIndex(
|
||||
handler.NewIndex("lnu_instance_ro_id", []string{LoginNameUserInstanceIDCol, LoginNameUserResourceOwnerCol, LoginNameUserIDCol},
|
||||
handler.WithInclude(
|
||||
LoginNameUserUserNameCol,
|
||||
LoginNameUserOwnerRemovedCol,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(LoginNameDomainNameCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginNameDomainIsPrimaryCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(LoginNameDomainResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginNameDomainInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginNameDomainOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(LoginNameDomainInstanceIDCol, LoginNameDomainResourceOwnerCol, LoginNameDomainNameCol),
|
||||
handler.NewSuffixedTable(
|
||||
[]*handler.InitColumn{
|
||||
handler.NewColumn(LoginNameDomainNameCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LoginNameDomainIsPrimaryCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(LoginNameDomainResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LoginNameDomainInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LoginNameDomainOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
handler.NewPrimaryKey(LoginNameDomainInstanceIDCol, LoginNameDomainResourceOwnerCol, LoginNameDomainNameCol),
|
||||
loginNameDomainSuffix,
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{LoginNameDomainOwnerRemovedCol})),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{LoginNameDomainOwnerRemovedCol})),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(LoginNamePoliciesMustBeDomainCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(LoginNamePoliciesIsDefaultCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(LoginNamePoliciesResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginNamePoliciesInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginNamePoliciesOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(LoginNamePoliciesInstanceIDCol, LoginNamePoliciesResourceOwnerCol),
|
||||
handler.NewSuffixedTable(
|
||||
[]*handler.InitColumn{
|
||||
handler.NewColumn(LoginNamePoliciesMustBeDomainCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(LoginNamePoliciesIsDefaultCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(LoginNamePoliciesResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LoginNamePoliciesInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LoginNamePoliciesOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
handler.NewPrimaryKey(LoginNamePoliciesInstanceIDCol, LoginNamePoliciesResourceOwnerCol),
|
||||
loginNamePolicySuffix,
|
||||
crdb.WithIndex(crdb.NewIndex("is_default", []string{LoginNamePoliciesResourceOwnerCol, LoginNamePoliciesIsDefaultCol})),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{LoginNamePoliciesOwnerRemovedCol})),
|
||||
handler.WithIndex(handler.NewIndex("is_default", []string{LoginNamePoliciesResourceOwnerCol, LoginNamePoliciesIsDefaultCol})),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{LoginNamePoliciesOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *loginNameProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *loginNameProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: user.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: user.UserV1AddedType,
|
||||
Reduce: p.reduceUserCreated,
|
||||
@@ -265,7 +277,7 @@ func (p *loginNameProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.DomainPolicyAddedEventType,
|
||||
Reduce: p.reduceOrgIAMPolicyAdded,
|
||||
@@ -298,7 +310,7 @@ func (p *loginNameProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.DomainPolicyAddedEventType,
|
||||
Reduce: p.reduceOrgIAMPolicyAdded,
|
||||
@@ -330,7 +342,7 @@ func (p *loginNameProjection) reduceUserCreated(event eventstore.Event) (*handle
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ayo69", "reduce.wrong.event.type %v", []eventstore.EventType{user.UserV1AddedType, user.HumanAddedType, user.UserV1RegisteredType, user.HumanRegisteredType, user.MachineAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LoginNameUserIDCol, event.Aggregate().ID),
|
||||
@@ -338,7 +350,7 @@ func (p *loginNameProjection) reduceUserCreated(event eventstore.Event) (*handle
|
||||
handler.NewCol(LoginNameUserResourceOwnerCol, event.Aggregate().ResourceOwner),
|
||||
handler.NewCol(LoginNameUserInstanceIDCol, event.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNameUserSuffix),
|
||||
handler.WithTableSuffix(loginNameUserSuffix),
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -348,13 +360,13 @@ func (p *loginNameProjection) reduceUserRemoved(event eventstore.Event) (*handle
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-QIe3C", "reduce.wrong.event.type %s", user.UserRemovedType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
event,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LoginNameUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(LoginNameUserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNameUserSuffix),
|
||||
handler.WithTableSuffix(loginNameUserSuffix),
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -364,7 +376,7 @@ func (p *loginNameProjection) reduceUserNameChanged(event eventstore.Event) (*ha
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-QlwjC", "reduce.wrong.event.type %s", user.UserUserNameChangedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LoginNameUserUserNameCol, e.UserName),
|
||||
@@ -373,7 +385,7 @@ func (p *loginNameProjection) reduceUserNameChanged(event eventstore.Event) (*ha
|
||||
handler.NewCond(LoginNameUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(LoginNameUserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNameUserSuffix),
|
||||
handler.WithTableSuffix(loginNameUserSuffix),
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -383,7 +395,7 @@ func (p *loginNameProjection) reduceUserDomainClaimed(event eventstore.Event) (*
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-AQMBY", "reduce.wrong.event.type %s", user.UserDomainClaimedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LoginNameUserUserNameCol, e.UserName),
|
||||
@@ -392,7 +404,7 @@ func (p *loginNameProjection) reduceUserDomainClaimed(event eventstore.Event) (*
|
||||
handler.NewCond(LoginNameUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(LoginNameUserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNameUserSuffix),
|
||||
handler.WithTableSuffix(loginNameUserSuffix),
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -413,7 +425,7 @@ func (p *loginNameProjection) reduceOrgIAMPolicyAdded(event eventstore.Event) (*
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-yCV6S", "reduce.wrong.event.type %v", []eventstore.EventType{org.DomainPolicyAddedEventType, instance.DomainPolicyAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LoginNamePoliciesMustBeDomainCol, policyEvent.UserLoginMustBeDomain),
|
||||
@@ -421,7 +433,7 @@ func (p *loginNameProjection) reduceOrgIAMPolicyAdded(event eventstore.Event) (*
|
||||
handler.NewCol(LoginNamePoliciesResourceOwnerCol, policyEvent.Aggregate().ResourceOwner),
|
||||
handler.NewCol(LoginNamePoliciesInstanceIDCol, policyEvent.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNamePolicySuffix),
|
||||
handler.WithTableSuffix(loginNamePolicySuffix),
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -438,10 +450,10 @@ func (p *loginNameProjection) reduceDomainPolicyChanged(event eventstore.Event)
|
||||
}
|
||||
|
||||
if policyEvent.UserLoginMustBeDomain == nil {
|
||||
return crdb.NewNoOpStatement(event), nil
|
||||
return handler.NewNoOpStatement(event), nil
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LoginNamePoliciesMustBeDomainCol, *policyEvent.UserLoginMustBeDomain),
|
||||
@@ -450,7 +462,7 @@ func (p *loginNameProjection) reduceDomainPolicyChanged(event eventstore.Event)
|
||||
handler.NewCond(LoginNamePoliciesResourceOwnerCol, policyEvent.Aggregate().ResourceOwner),
|
||||
handler.NewCond(LoginNamePoliciesInstanceIDCol, policyEvent.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNamePolicySuffix),
|
||||
handler.WithTableSuffix(loginNamePolicySuffix),
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -460,13 +472,13 @@ func (p *loginNameProjection) reduceDomainPolicyRemoved(event eventstore.Event)
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ysEeB", "reduce.wrong.event.type %s", org.DomainPolicyRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
event,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LoginNamePoliciesResourceOwnerCol, e.Aggregate().ResourceOwner),
|
||||
handler.NewCond(LoginNamePoliciesInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNamePolicySuffix),
|
||||
handler.WithTableSuffix(loginNamePolicySuffix),
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -476,14 +488,14 @@ func (p *loginNameProjection) reduceDomainVerified(event eventstore.Event) (*han
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-weGAh", "reduce.wrong.event.type %s", org.OrgDomainVerifiedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LoginNameDomainNameCol, e.Domain),
|
||||
handler.NewCol(LoginNameDomainResourceOwnerCol, e.Aggregate().ResourceOwner),
|
||||
handler.NewCol(LoginNameDomainInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNameDomainSuffix),
|
||||
handler.WithTableSuffix(loginNameDomainSuffix),
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -493,9 +505,9 @@ func (p *loginNameProjection) reducePrimaryDomainSet(event eventstore.Event) (*h
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-eOXPN", "reduce.wrong.event.type %s", org.OrgDomainPrimarySetEventType)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(LoginNameDomainIsPrimaryCol, false),
|
||||
},
|
||||
@@ -504,9 +516,9 @@ func (p *loginNameProjection) reducePrimaryDomainSet(event eventstore.Event) (*h
|
||||
handler.NewCond(LoginNameDomainIsPrimaryCol, true),
|
||||
handler.NewCond(LoginNameDomainInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNameDomainSuffix),
|
||||
handler.WithTableSuffix(loginNameDomainSuffix),
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(LoginNameDomainIsPrimaryCol, true),
|
||||
},
|
||||
@@ -515,7 +527,7 @@ func (p *loginNameProjection) reducePrimaryDomainSet(event eventstore.Event) (*h
|
||||
handler.NewCond(LoginNameDomainResourceOwnerCol, e.Aggregate().ResourceOwner),
|
||||
handler.NewCond(LoginNameDomainInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNameDomainSuffix),
|
||||
handler.WithTableSuffix(loginNameDomainSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -526,14 +538,14 @@ func (p *loginNameProjection) reduceDomainRemoved(event eventstore.Event) (*hand
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-4RHYq", "reduce.wrong.event.type %s", org.OrgDomainRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
event,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LoginNameDomainNameCol, e.Domain),
|
||||
handler.NewCond(LoginNameDomainResourceOwnerCol, e.Aggregate().ResourceOwner),
|
||||
handler.NewCond(LoginNameDomainInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNameDomainSuffix),
|
||||
handler.WithTableSuffix(loginNameDomainSuffix),
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -543,25 +555,25 @@ func (p *loginNameProjection) reduceInstanceRemoved(event eventstore.Event) (*ha
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ASeg3", "reduce.wrong.event.type %s", instance.InstanceRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
event,
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LoginNameDomainInstanceIDCol, e.Aggregate().ID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNameDomainSuffix),
|
||||
handler.WithTableSuffix(loginNameDomainSuffix),
|
||||
),
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LoginNamePoliciesInstanceIDCol, e.Aggregate().ID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNamePolicySuffix),
|
||||
handler.WithTableSuffix(loginNamePolicySuffix),
|
||||
),
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LoginNameUserInstanceIDCol, e.Aggregate().ID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNameUserSuffix),
|
||||
handler.WithTableSuffix(loginNameUserSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -572,28 +584,28 @@ func (p *loginNameProjection) reduceOwnerRemoved(event eventstore.Event) (*handl
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-px02mo", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
event,
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LoginNameDomainInstanceIDCol, e.Aggregate().InstanceID),
|
||||
handler.NewCond(LoginNameDomainResourceOwnerCol, e.Aggregate().ID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNameDomainSuffix),
|
||||
handler.WithTableSuffix(loginNameDomainSuffix),
|
||||
),
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LoginNamePoliciesInstanceIDCol, e.Aggregate().InstanceID),
|
||||
handler.NewCond(LoginNamePoliciesResourceOwnerCol, e.Aggregate().ID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNamePolicySuffix),
|
||||
handler.WithTableSuffix(loginNamePolicySuffix),
|
||||
),
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LoginNameUserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
handler.NewCond(LoginNameUserResourceOwnerCol, e.Aggregate().ID),
|
||||
},
|
||||
crdb.WithTableSuffix(loginNameUserSuffix),
|
||||
handler.WithTableSuffix(loginNameUserSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -5,8 +5,7 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/user"
|
||||
@@ -25,19 +24,19 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "user HumanAddedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.HumanAddedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.HumanAddedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"userName": "human-added"
|
||||
}`),
|
||||
), user.HumanAddedEventMapper),
|
||||
), user.HumanAddedEventMapper),
|
||||
},
|
||||
reduce: (&loginNameProjection{}).reduceUserCreated,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -56,19 +55,19 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "user HumanRegisteredType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.HumanRegisteredType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.HumanRegisteredType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"userName": "human-registered"
|
||||
}`),
|
||||
), user.HumanRegisteredEventMapper),
|
||||
), user.HumanRegisteredEventMapper),
|
||||
},
|
||||
reduce: (&loginNameProjection{}).reduceUserCreated,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -87,19 +86,19 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "user MachineAddedEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.MachineAddedEventType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.MachineAddedEventType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"userName": "machine-added"
|
||||
}`),
|
||||
), user.MachineAddedEventMapper),
|
||||
), user.MachineAddedEventMapper),
|
||||
},
|
||||
reduce: (&loginNameProjection{}).reduceUserCreated,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -118,17 +117,17 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "user UserRemovedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.UserRemovedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), user.UserRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.UserRemovedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), user.UserRemovedEventMapper),
|
||||
},
|
||||
reduce: (&loginNameProjection{}).reduceUserRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -145,19 +144,19 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "user UserUserNameChangedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.UserUserNameChangedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.UserUserNameChangedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"userName": "changed"
|
||||
}`),
|
||||
), user.UsernameChangedEventMapper),
|
||||
), user.UsernameChangedEventMapper),
|
||||
},
|
||||
reduce: (&loginNameProjection{}).reduceUserNameChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -175,19 +174,19 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "user UserDomainClaimedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.UserDomainClaimedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.UserDomainClaimedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"userName": "claimed"
|
||||
}`),
|
||||
), user.DomainClaimedEventMapper),
|
||||
), user.DomainClaimedEventMapper),
|
||||
},
|
||||
reduce: (&loginNameProjection{}).reduceUserDomainClaimed,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -205,19 +204,19 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org OrgDomainPolicyAddedEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.DomainPolicyAddedEventType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.DomainPolicyAddedEventType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"userLoginMustBeDomain": true
|
||||
}`),
|
||||
), org.DomainPolicyAddedEventMapper),
|
||||
), org.DomainPolicyAddedEventMapper),
|
||||
},
|
||||
reduce: (&loginNameProjection{}).reduceOrgIAMPolicyAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -236,19 +235,19 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org OrgDomainPolicyChangedEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.DomainPolicyChangedEventType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.DomainPolicyChangedEventType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"userLoginMustBeDomain": false
|
||||
}`),
|
||||
), org.DomainPolicyChangedEventMapper),
|
||||
), org.DomainPolicyChangedEventMapper),
|
||||
},
|
||||
reduce: (&loginNameProjection{}).reduceDomainPolicyChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -266,17 +265,17 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org OrgDomainPolicyChangedEventType no change",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.DomainPolicyChangedEventType),
|
||||
user.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), org.DomainPolicyChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.DomainPolicyChangedEventType,
|
||||
user.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), org.DomainPolicyChangedEventMapper),
|
||||
},
|
||||
reduce: (&loginNameProjection{}).reduceDomainPolicyChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{},
|
||||
},
|
||||
@@ -285,17 +284,17 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org OrgDomainPolicyRemovedEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.DomainPolicyRemovedEventType),
|
||||
user.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), org.DomainPolicyRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.DomainPolicyRemovedEventType,
|
||||
user.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), org.DomainPolicyRemovedEventMapper),
|
||||
},
|
||||
reduce: (&loginNameProjection{}).reduceDomainPolicyRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -312,19 +311,19 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org OrgDomainVerifiedEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgDomainVerifiedEventType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgDomainVerifiedEventType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"domain": "verified"
|
||||
}`),
|
||||
), org.DomainVerifiedEventMapper),
|
||||
), org.DomainVerifiedEventMapper),
|
||||
},
|
||||
reduce: (&loginNameProjection{}).reduceDomainVerified,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -342,19 +341,19 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org OrgDomainRemovedEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgDomainRemovedEventType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgDomainRemovedEventType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"domain": "remove"
|
||||
}`),
|
||||
), org.DomainRemovedEventMapper),
|
||||
), org.DomainRemovedEventMapper),
|
||||
},
|
||||
reduce: (&loginNameProjection{}).reduceDomainRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -372,19 +371,19 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org OrgDomainPrimarySetEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgDomainPrimarySetEventType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgDomainPrimarySetEventType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"domain": "primary"
|
||||
}`),
|
||||
), org.DomainPrimarySetEventMapper),
|
||||
), org.DomainPrimarySetEventMapper),
|
||||
},
|
||||
reduce: (&loginNameProjection{}).reducePrimaryDomainSet,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -412,19 +411,19 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "iam OrgDomainPolicyAddedEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.DomainPolicyAddedEventType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.DomainPolicyAddedEventType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"userLoginMustBeDomain": true
|
||||
}`),
|
||||
), instance.DomainPolicyAddedEventMapper),
|
||||
), instance.DomainPolicyAddedEventMapper),
|
||||
},
|
||||
reduce: (&loginNameProjection{}).reduceOrgIAMPolicyAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -443,19 +442,19 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "iam OrgDomainPolicyChangedEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.DomainPolicyChangedEventType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.DomainPolicyChangedEventType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"userLoginMustBeDomain": false
|
||||
}`),
|
||||
), instance.DomainPolicyChangedEventMapper),
|
||||
), instance.DomainPolicyChangedEventMapper),
|
||||
},
|
||||
reduce: (&loginNameProjection{}).reduceDomainPolicyChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -473,17 +472,17 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "iam OrgDomainPolicyChangedEventType no change",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.DomainPolicyChangedEventType),
|
||||
user.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), instance.DomainPolicyChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.DomainPolicyChangedEventType,
|
||||
user.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), instance.DomainPolicyChangedEventMapper),
|
||||
},
|
||||
reduce: (&loginNameProjection{}).reduceDomainPolicyChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{},
|
||||
},
|
||||
@@ -492,17 +491,17 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: (&loginNameProjection{}).reduceInstanceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -530,17 +529,17 @@ func TestLoginNameProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance.reduceOwnerRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"name": "Name"}`),
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"name": "Name"}`),
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
reduce: (&loginNameProjection{}).reduceOwnerRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
@@ -43,56 +43,57 @@ const (
|
||||
LoginPolicyOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type loginPolicyProjection struct {
|
||||
crdb.StatementHandler
|
||||
type loginPolicyProjection struct{}
|
||||
|
||||
func newLoginPolicyProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(loginPolicyProjection))
|
||||
}
|
||||
|
||||
func newLoginPolicyProjection(ctx context.Context, config crdb.StatementHandlerConfig) *loginPolicyProjection {
|
||||
p := new(loginPolicyProjection)
|
||||
config.ProjectionName = LoginPolicyTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(LoginPolicyIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginPolicyInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LoginPolicyCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(LoginPolicyChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(LoginPolicySequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(LoginPolicyIsDefaultCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(LoginPolicyAllowRegisterCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(LoginPolicyAllowUsernamePasswordCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(LoginPolicyAllowExternalIDPsCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(LoginPolicyForceMFACol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(LoginPolicyForceMFALocalOnlyCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(LoginPolicy2FAsCol, crdb.ColumnTypeEnumArray, crdb.Nullable()),
|
||||
crdb.NewColumn(LoginPolicyMFAsCol, crdb.ColumnTypeEnumArray, crdb.Nullable()),
|
||||
crdb.NewColumn(LoginPolicyPasswordlessTypeCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(LoginPolicyHidePWResetCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(IgnoreUnknownUsernames, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(AllowDomainDiscovery, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(DisableLoginWithEmail, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(DisableLoginWithPhone, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(DefaultRedirectURI, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(PasswordCheckLifetimeCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(ExternalLoginCheckLifetimeCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(MFAInitSkipLifetimeCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(SecondFactorCheckLifetimeCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(MultiFactorCheckLifetimeCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(LoginPolicyOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*loginPolicyProjection) Name() string {
|
||||
return LoginPolicyTable
|
||||
}
|
||||
|
||||
func (*loginPolicyProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(LoginPolicyIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LoginPolicyInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LoginPolicyCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(LoginPolicyChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(LoginPolicySequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(LoginPolicyIsDefaultCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(LoginPolicyAllowRegisterCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(LoginPolicyAllowUsernamePasswordCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(LoginPolicyAllowExternalIDPsCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(LoginPolicyForceMFACol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(LoginPolicyForceMFALocalOnlyCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(LoginPolicy2FAsCol, handler.ColumnTypeEnumArray, handler.Nullable()),
|
||||
handler.NewColumn(LoginPolicyMFAsCol, handler.ColumnTypeEnumArray, handler.Nullable()),
|
||||
handler.NewColumn(LoginPolicyPasswordlessTypeCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(LoginPolicyHidePWResetCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(IgnoreUnknownUsernames, handler.ColumnTypeBool),
|
||||
handler.NewColumn(AllowDomainDiscovery, handler.ColumnTypeBool),
|
||||
handler.NewColumn(DisableLoginWithEmail, handler.ColumnTypeBool),
|
||||
handler.NewColumn(DisableLoginWithPhone, handler.ColumnTypeBool),
|
||||
handler.NewColumn(DefaultRedirectURI, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(PasswordCheckLifetimeCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(ExternalLoginCheckLifetimeCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(MFAInitSkipLifetimeCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(SecondFactorCheckLifetimeCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(MultiFactorCheckLifetimeCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(LoginPolicyOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(LoginPolicyInstanceIDCol, LoginPolicyIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{LoginPolicyOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(LoginPolicyInstanceIDCol, LoginPolicyIDCol),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{LoginPolicyOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *loginPolicyProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *loginPolicyProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.LoginPolicyAddedEventType,
|
||||
Reduce: p.reduceLoginPolicyAdded,
|
||||
@@ -129,7 +130,7 @@ func (p *loginPolicyProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.LoginPolicyAddedEventType,
|
||||
Reduce: p.reduceLoginPolicyAdded,
|
||||
@@ -177,7 +178,7 @@ func (p *loginPolicyProjection) reduceLoginPolicyAdded(event eventstore.Event) (
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-pYPxS", "reduce.wrong.event.type %v", []eventstore.EventType{org.LoginPolicyAddedEventType, instance.LoginPolicyAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(&policyEvent, []handler.Column{
|
||||
return handler.NewCreateStatement(&policyEvent, []handler.Column{
|
||||
handler.NewCol(LoginPolicyIDCol, policyEvent.Aggregate().ID),
|
||||
handler.NewCol(LoginPolicyInstanceIDCol, policyEvent.Aggregate().InstanceID),
|
||||
handler.NewCol(LoginPolicyCreationDateCol, policyEvent.CreationDate()),
|
||||
@@ -271,7 +272,7 @@ func (p *loginPolicyProjection) reduceLoginPolicyChanged(event eventstore.Event)
|
||||
cols = append(cols, handler.NewCol(MultiFactorCheckLifetimeCol, *policyEvent.MultiFactorCheckLifetime))
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&policyEvent,
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
@@ -292,12 +293,12 @@ func (p *loginPolicyProjection) reduceMFAAdded(event eventstore.Event) (*handler
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-WMhAV", "reduce.wrong.event.type %v", []eventstore.EventType{org.LoginPolicyMultiFactorAddedEventType, instance.LoginPolicyMultiFactorAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&policyEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LoginPolicyChangeDateCol, policyEvent.CreationDate()),
|
||||
handler.NewCol(LoginPolicySequenceCol, policyEvent.Sequence()),
|
||||
crdb.NewArrayAppendCol(LoginPolicyMFAsCol, policyEvent.MFAType),
|
||||
handler.NewArrayAppendCol(LoginPolicyMFAsCol, policyEvent.MFAType),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LoginPolicyIDCol, policyEvent.Aggregate().ID),
|
||||
@@ -317,12 +318,12 @@ func (p *loginPolicyProjection) reduceMFARemoved(event eventstore.Event) (*handl
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-czU7n", "reduce.wrong.event.type %v", []eventstore.EventType{org.LoginPolicyMultiFactorRemovedEventType, instance.LoginPolicyMultiFactorRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&policyEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LoginPolicyChangeDateCol, policyEvent.CreationDate()),
|
||||
handler.NewCol(LoginPolicySequenceCol, policyEvent.Sequence()),
|
||||
crdb.NewArrayRemoveCol(LoginPolicyMFAsCol, policyEvent.MFAType),
|
||||
handler.NewArrayRemoveCol(LoginPolicyMFAsCol, policyEvent.MFAType),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LoginPolicyIDCol, policyEvent.Aggregate().ID),
|
||||
@@ -336,7 +337,7 @@ func (p *loginPolicyProjection) reduceLoginPolicyRemoved(event eventstore.Event)
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-oRSvD", "reduce.wrong.event.type %s", org.LoginPolicyRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LoginPolicyIDCol, e.Aggregate().ID),
|
||||
@@ -356,12 +357,12 @@ func (p *loginPolicyProjection) reduceSecondFactorAdded(event eventstore.Event)
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-agB2E", "reduce.wrong.event.type %v", []eventstore.EventType{org.LoginPolicySecondFactorAddedEventType, instance.LoginPolicySecondFactorAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&policyEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LoginPolicyChangeDateCol, policyEvent.CreationDate()),
|
||||
handler.NewCol(LoginPolicySequenceCol, policyEvent.Sequence()),
|
||||
crdb.NewArrayAppendCol(LoginPolicy2FAsCol, policyEvent.MFAType),
|
||||
handler.NewArrayAppendCol(LoginPolicy2FAsCol, policyEvent.MFAType),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LoginPolicyIDCol, policyEvent.Aggregate().ID),
|
||||
@@ -381,12 +382,12 @@ func (p *loginPolicyProjection) reduceSecondFactorRemoved(event eventstore.Event
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-KYJvA", "reduce.wrong.event.type %v", []eventstore.EventType{org.LoginPolicySecondFactorRemovedEventType, instance.LoginPolicySecondFactorRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&policyEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LoginPolicyChangeDateCol, policyEvent.CreationDate()),
|
||||
handler.NewCol(LoginPolicySequenceCol, policyEvent.Sequence()),
|
||||
crdb.NewArrayRemoveCol(LoginPolicy2FAsCol, policyEvent.MFAType),
|
||||
handler.NewArrayRemoveCol(LoginPolicy2FAsCol, policyEvent.MFAType),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LoginPolicyIDCol, policyEvent.Aggregate().ID),
|
||||
@@ -401,7 +402,7 @@ func (p *loginPolicyProjection) reduceOwnerRemoved(event eventstore.Event) (*han
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-B8NZW", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LoginPolicyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -7,8 +7,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -26,10 +25,11 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceLoginPolicyAdded without forceMFALocalOnly",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LoginPolicyAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LoginPolicyAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"allowUsernamePassword": true,
|
||||
"allowRegister": true,
|
||||
"allowExternalIdp": false,
|
||||
@@ -47,13 +47,12 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
"secondFactorCheckLifetime": 10000000,
|
||||
"multiFactorCheckLifetime": 10000000
|
||||
}`),
|
||||
), org.LoginPolicyAddedEventMapper),
|
||||
), org.LoginPolicyAddedEventMapper),
|
||||
},
|
||||
reduce: (&loginPolicyProjection{}).reduceLoginPolicyAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -92,7 +91,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org reduceLoginPolicyAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LoginPolicyAddedEventType),
|
||||
org.LoginPolicyAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"allowUsernamePassword": true,
|
||||
@@ -117,9 +116,8 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&loginPolicyProjection{}).reduceLoginPolicyAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -158,10 +156,11 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org reduceLoginPolicyChanged",
|
||||
reduce: (&loginPolicyProjection{}).reduceLoginPolicyChanged,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LoginPolicyChangedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LoginPolicyChangedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"allowUsernamePassword": true,
|
||||
"allowRegister": true,
|
||||
"allowExternalIdp": true,
|
||||
@@ -180,12 +179,11 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
"secondFactorCheckLifetime": 10000000,
|
||||
"multiFactorCheckLifetime": 10000000
|
||||
}`),
|
||||
), org.LoginPolicyChangedEventMapper),
|
||||
), org.LoginPolicyChangedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -222,18 +220,18 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org reduceMFAAdded",
|
||||
reduce: (&loginPolicyProjection{}).reduceMFAAdded,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LoginPolicyMultiFactorAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LoginPolicyMultiFactorAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"mfaType": 1
|
||||
}`),
|
||||
), org.MultiFactorAddedEventEventMapper),
|
||||
), org.MultiFactorAddedEventEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -254,18 +252,18 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org reduceMFARemoved",
|
||||
reduce: (&loginPolicyProjection{}).reduceMFARemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LoginPolicyMultiFactorRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LoginPolicyMultiFactorRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"mfaType": 1
|
||||
}`),
|
||||
), org.MultiFactorRemovedEventEventMapper),
|
||||
), org.MultiFactorRemovedEventEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -286,16 +284,16 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org reduceLoginPolicyRemoved",
|
||||
reduce: (&loginPolicyProjection{}).reduceLoginPolicyRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LoginPolicyRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.LoginPolicyRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LoginPolicyRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.LoginPolicyRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -313,18 +311,18 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org reduceSecondFactorAdded",
|
||||
reduce: (&loginPolicyProjection{}).reduceSecondFactorAdded,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LoginPolicySecondFactorAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LoginPolicySecondFactorAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"mfaType": 2
|
||||
}`),
|
||||
), org.SecondFactorAddedEventEventMapper),
|
||||
), org.SecondFactorAddedEventEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -345,18 +343,18 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org reduceSecondFactorRemoved",
|
||||
reduce: (&loginPolicyProjection{}).reduceSecondFactorRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.LoginPolicySecondFactorRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.LoginPolicySecondFactorRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"mfaType": 2
|
||||
}`),
|
||||
), org.SecondFactorRemovedEventEventMapper),
|
||||
), org.SecondFactorRemovedEventEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -377,10 +375,11 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceLoginPolicyAdded",
|
||||
reduce: (&loginPolicyProjection{}).reduceLoginPolicyAdded,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LoginPolicyAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LoginPolicyAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"allowUsernamePassword": true,
|
||||
"allowRegister": true,
|
||||
"allowExternalIdp": true,
|
||||
@@ -399,12 +398,11 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
"secondFactorCheckLifetime": 10000000,
|
||||
"multiFactorCheckLifetime": 10000000
|
||||
}`),
|
||||
), instance.LoginPolicyAddedEventMapper),
|
||||
), instance.LoginPolicyAddedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -443,10 +441,11 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceLoginPolicyChanged",
|
||||
reduce: (&loginPolicyProjection{}).reduceLoginPolicyChanged,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LoginPolicyChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LoginPolicyChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"allowUsernamePassword": true,
|
||||
"allowRegister": true,
|
||||
"allowExternalIdp": true,
|
||||
@@ -460,12 +459,11 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
"passwordlessType": 1,
|
||||
"defaultRedirectURI": "https://example.com/redirect"
|
||||
}`),
|
||||
), instance.LoginPolicyChangedEventMapper),
|
||||
), instance.LoginPolicyChangedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -497,18 +495,18 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceMFAAdded",
|
||||
reduce: (&loginPolicyProjection{}).reduceMFAAdded,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LoginPolicyMultiFactorAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LoginPolicyMultiFactorAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"mfaType": 1
|
||||
}`),
|
||||
), instance.MultiFactorAddedEventMapper),
|
||||
), instance.MultiFactorAddedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -529,18 +527,18 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceMFARemoved",
|
||||
reduce: (&loginPolicyProjection{}).reduceMFARemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LoginPolicyMultiFactorRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LoginPolicyMultiFactorRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"mfaType": 1
|
||||
}`),
|
||||
), instance.MultiFactorRemovedEventMapper),
|
||||
), instance.MultiFactorRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -561,18 +559,18 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceSecondFactorAdded u2f",
|
||||
reduce: (&loginPolicyProjection{}).reduceSecondFactorAdded,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LoginPolicySecondFactorAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LoginPolicySecondFactorAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"mfaType": 2
|
||||
}`),
|
||||
), instance.SecondFactorAddedEventMapper),
|
||||
), instance.SecondFactorAddedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -593,18 +591,18 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceSecondFactorRemoved u2f",
|
||||
reduce: (&loginPolicyProjection{}).reduceSecondFactorRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LoginPolicySecondFactorRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.LoginPolicySecondFactorRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"mfaType": 2
|
||||
}`),
|
||||
), instance.SecondFactorRemovedEventMapper),
|
||||
), instance.SecondFactorRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -626,7 +624,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
reduce: (&loginPolicyProjection{}).reduceSecondFactorAdded,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LoginPolicySecondFactorAddedEventType),
|
||||
instance.LoginPolicySecondFactorAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"mfaType": 3
|
||||
@@ -634,9 +632,8 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
), instance.SecondFactorAddedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -658,7 +655,7 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
reduce: (&loginPolicyProjection{}).reduceSecondFactorRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.LoginPolicySecondFactorRemovedEventType),
|
||||
instance.LoginPolicySecondFactorRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"mfaType": 3
|
||||
@@ -666,9 +663,8 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
), instance.SecondFactorRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -689,16 +685,16 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (&loginPolicyProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -715,17 +711,17 @@ func TestLoginPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(LoginPolicyInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
@@ -27,39 +27,40 @@ const (
|
||||
MailTemplateOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type mailTemplateProjection struct {
|
||||
crdb.StatementHandler
|
||||
type mailTemplateProjection struct{}
|
||||
|
||||
func newMailTemplateProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(mailTemplateProjection))
|
||||
}
|
||||
|
||||
func newMailTemplateProjection(ctx context.Context, config crdb.StatementHandlerConfig) *mailTemplateProjection {
|
||||
p := new(mailTemplateProjection)
|
||||
config.ProjectionName = MailTemplateTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(MailTemplateAggregateIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(MailTemplateInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(MailTemplateCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(MailTemplateChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(MailTemplateSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(MailTemplateStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(MailTemplateIsDefaultCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(MailTemplateTemplateCol, crdb.ColumnTypeBytes),
|
||||
crdb.NewColumn(MailTemplateOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*mailTemplateProjection) Name() string {
|
||||
return MailTemplateTable
|
||||
}
|
||||
|
||||
func (*mailTemplateProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(MailTemplateAggregateIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(MailTemplateInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(MailTemplateCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(MailTemplateChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(MailTemplateSequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(MailTemplateStateCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(MailTemplateIsDefaultCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(MailTemplateTemplateCol, handler.ColumnTypeBytes),
|
||||
handler.NewColumn(MailTemplateOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(MailTemplateInstanceIDCol, MailTemplateAggregateIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{MailTemplateOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(MailTemplateInstanceIDCol, MailTemplateAggregateIDCol),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{MailTemplateOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *mailTemplateProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *mailTemplateProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.MailTemplateAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -80,7 +81,7 @@ func (p *mailTemplateProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.MailTemplateAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -111,7 +112,7 @@ func (p *mailTemplateProjection) reduceAdded(event eventstore.Event) (*handler.S
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-0pJ3f", "reduce.wrong.event.type, %v", []eventstore.EventType{org.MailTemplateAddedEventType, instance.MailTemplateAddedEventType})
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
&templateEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(MailTemplateAggregateIDCol, templateEvent.Aggregate().ID),
|
||||
@@ -142,7 +143,7 @@ func (p *mailTemplateProjection) reduceChanged(event eventstore.Event) (*handler
|
||||
if policyEvent.Template != nil {
|
||||
cols = append(cols, handler.NewCol(MailTemplateTemplateCol, *policyEvent.Template))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&policyEvent,
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
@@ -156,7 +157,7 @@ func (p *mailTemplateProjection) reduceRemoved(event eventstore.Event) (*handler
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-3jJGs", "reduce.wrong.event.type %s", org.MailTemplateRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
policyEvent,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(MailTemplateAggregateIDCol, policyEvent.Aggregate().ID),
|
||||
@@ -170,7 +171,7 @@ func (p *mailTemplateProjection) reduceOwnerRemoved(event eventstore.Event) (*ha
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-CThXR", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(MailTemplateInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -25,19 +24,19 @@ func TestMailTemplateProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org.reduceAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.MailTemplateAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.MailTemplateAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"template": "PHRhYmxlPjwvdGFibGU+"
|
||||
}`),
|
||||
), org.MailTemplateAddedEventMapper),
|
||||
), org.MailTemplateAddedEventMapper),
|
||||
},
|
||||
reduce: (&mailTemplateProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -61,18 +60,18 @@ func TestMailTemplateProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceChanged",
|
||||
reduce: (&mailTemplateProjection{}).reduceChanged,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.MailTemplateChangedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.MailTemplateChangedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"template": "PHRhYmxlPjwvdGFibGU+"
|
||||
}`),
|
||||
), org.MailTemplateChangedEventMapper),
|
||||
), org.MailTemplateChangedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -93,16 +92,16 @@ func TestMailTemplateProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceRemoved",
|
||||
reduce: (&mailTemplateProjection{}).reduceRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.MailTemplateRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.MailTemplateRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.MailTemplateRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.MailTemplateRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -119,17 +118,17 @@ func TestMailTemplateProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance.reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(MailTemplateInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -146,18 +145,18 @@ func TestMailTemplateProjection_reduces(t *testing.T) {
|
||||
name: "instance.reduceAdded",
|
||||
reduce: (&mailTemplateProjection{}).reduceAdded,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.MailTemplateAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.MailTemplateAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"template": "PHRhYmxlPjwvdGFibGU+"
|
||||
}`),
|
||||
), instance.MailTemplateAddedEventMapper),
|
||||
), instance.MailTemplateAddedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -181,18 +180,18 @@ func TestMailTemplateProjection_reduces(t *testing.T) {
|
||||
name: "instance.reduceChanged",
|
||||
reduce: (&mailTemplateProjection{}).reduceChanged,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.MailTemplateChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.MailTemplateChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"template": "PHRhYmxlPjwvdGFibGU+"
|
||||
}`),
|
||||
), instance.MailTemplateChangedEventMapper),
|
||||
), instance.MailTemplateChangedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -213,16 +212,16 @@ func TestMailTemplateProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (&mailTemplateProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -25,7 +25,12 @@ func eventstoreExpect(t *testing.T, expects ...expect) *eventstore.Eventstore {
|
||||
for _, e := range expects {
|
||||
e(m)
|
||||
}
|
||||
es := eventstore.NewEventstore(eventstore.TestConfig(m))
|
||||
es := eventstore.NewEventstore(
|
||||
&eventstore.Config{
|
||||
Querier: m.MockQuerier,
|
||||
Pusher: m.MockPusher,
|
||||
},
|
||||
)
|
||||
iam_repo.RegisterEventMappers(es)
|
||||
org.RegisterEventMappers(es)
|
||||
usr_repo.RegisterEventMappers(es)
|
||||
@@ -37,27 +42,18 @@ func eventstoreExpect(t *testing.T, expects ...expect) *eventstore.Eventstore {
|
||||
return es
|
||||
}
|
||||
|
||||
func expectFilter(events ...*repository.Event) expect {
|
||||
return func(m *mock.MockRepository) {
|
||||
m.ExpectFilterEvents(events...)
|
||||
}
|
||||
}
|
||||
|
||||
func eventFromEventPusher(event eventstore.Command) *repository.Event {
|
||||
data, _ := eventstore.EventData(event)
|
||||
return &repository.Event{
|
||||
ID: "",
|
||||
Sequence: 0,
|
||||
PreviousAggregateSequence: 0,
|
||||
PreviousAggregateTypeSequence: 0,
|
||||
CreationDate: time.Time{},
|
||||
Type: repository.EventType(event.Type()),
|
||||
Data: data,
|
||||
EditorService: event.EditorService(),
|
||||
EditorUser: event.EditorUser(),
|
||||
Version: repository.Version(event.Aggregate().Version),
|
||||
AggregateID: event.Aggregate().ID,
|
||||
AggregateType: repository.AggregateType(event.Aggregate().Type),
|
||||
ResourceOwner: sql.NullString{String: event.Aggregate().ResourceOwner, Valid: event.Aggregate().ResourceOwner != ""},
|
||||
ID: "",
|
||||
Seq: 0,
|
||||
CreationDate: time.Time{},
|
||||
Typ: event.Type(),
|
||||
Data: data,
|
||||
EditorUser: event.Creator(),
|
||||
Version: event.Aggregate().Version,
|
||||
AggregateID: event.Aggregate().ID,
|
||||
AggregateType: event.Aggregate().Type,
|
||||
ResourceOwner: sql.NullString{String: event.Aggregate().ResourceOwner, Valid: event.Aggregate().ResourceOwner != ""},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/member"
|
||||
)
|
||||
|
||||
@@ -26,17 +25,17 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
memberColumns = []*crdb.Column{
|
||||
crdb.NewColumn(MemberCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(MemberChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(MemberUserIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(MemberUserResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(MemberUserOwnerRemoved, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(MemberRolesCol, crdb.ColumnTypeTextArray, crdb.Nullable()),
|
||||
crdb.NewColumn(MemberSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(MemberResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(MemberInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(MemberOwnerRemoved, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
memberColumns = []*handler.InitColumn{
|
||||
handler.NewColumn(MemberCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(MemberChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(MemberUserIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(MemberUserResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(MemberUserOwnerRemoved, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(MemberRolesCol, handler.ColumnTypeTextArray, handler.Nullable()),
|
||||
handler.NewColumn(MemberSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(MemberResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(MemberInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(MemberOwnerRemoved, handler.ColumnTypeBool, handler.Default(false)),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -67,9 +66,9 @@ func reduceMemberAdded(e member.MemberAddedEvent, userResourceOwner string, opts
|
||||
handler.NewCol(MemberUserIDCol, e.UserID),
|
||||
handler.NewCol(MemberUserResourceOwner, userResourceOwner),
|
||||
handler.NewCol(MemberUserOwnerRemoved, false),
|
||||
handler.NewCol(MemberRolesCol, database.StringArray(e.Roles)),
|
||||
handler.NewCol(MemberCreationDate, e.CreationDate()),
|
||||
handler.NewCol(MemberChangeDate, e.CreationDate()),
|
||||
handler.NewCol(MemberRolesCol, database.TextArray[string](e.Roles)),
|
||||
handler.NewCol(MemberCreationDate, e.CreatedAt()),
|
||||
handler.NewCol(MemberChangeDate, e.CreatedAt()),
|
||||
handler.NewCol(MemberSequence, e.Sequence()),
|
||||
handler.NewCol(MemberResourceOwner, e.Aggregate().ResourceOwner),
|
||||
handler.NewCol(MemberInstanceID, e.Aggregate().InstanceID),
|
||||
@@ -80,14 +79,14 @@ func reduceMemberAdded(e member.MemberAddedEvent, userResourceOwner string, opts
|
||||
config = opt(config)
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(&e, config.cols), nil
|
||||
return handler.NewCreateStatement(&e, config.cols), nil
|
||||
}
|
||||
|
||||
func reduceMemberChanged(e member.MemberChangedEvent, opts ...reduceMemberOpt) (*handler.Statement, error) {
|
||||
config := reduceMemberConfig{
|
||||
cols: []handler.Column{
|
||||
handler.NewCol(MemberRolesCol, database.StringArray(e.Roles)),
|
||||
handler.NewCol(MemberChangeDate, e.CreationDate()),
|
||||
handler.NewCol(MemberRolesCol, database.TextArray[string](e.Roles)),
|
||||
handler.NewCol(MemberChangeDate, e.CreatedAt()),
|
||||
handler.NewCol(MemberSequence, e.Sequence()),
|
||||
},
|
||||
conds: []handler.Condition{
|
||||
@@ -99,7 +98,7 @@ func reduceMemberChanged(e member.MemberChangedEvent, opts ...reduceMemberOpt) (
|
||||
config = opt(config)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(&e, config.cols, config.conds), nil
|
||||
return handler.NewUpdateStatement(&e, config.cols, config.conds), nil
|
||||
}
|
||||
|
||||
func reduceMemberCascadeRemoved(e member.MemberCascadeRemovedEvent, opts ...reduceMemberOpt) (*handler.Statement, error) {
|
||||
@@ -112,7 +111,7 @@ func reduceMemberCascadeRemoved(e member.MemberCascadeRemovedEvent, opts ...redu
|
||||
for _, opt := range opts {
|
||||
config = opt(config)
|
||||
}
|
||||
return crdb.NewDeleteStatement(&e, config.conds), nil
|
||||
return handler.NewDeleteStatement(&e, config.conds), nil
|
||||
}
|
||||
|
||||
func reduceMemberRemoved(e eventstore.Event, opts ...reduceMemberOpt) (*handler.Statement, error) {
|
||||
@@ -125,10 +124,10 @@ func reduceMemberRemoved(e eventstore.Event, opts ...reduceMemberOpt) (*handler.
|
||||
for _, opt := range opts {
|
||||
config = opt(config)
|
||||
}
|
||||
return crdb.NewDeleteStatement(e, config.conds), nil
|
||||
return handler.NewDeleteStatement(e, config.conds), nil
|
||||
}
|
||||
|
||||
func multiReduceMemberOwnerRemoved(e eventstore.Event, opts ...reduceMemberOpt) func(eventstore.Event) crdb.Exec {
|
||||
func multiReduceMemberOwnerRemoved(e eventstore.Event, opts ...reduceMemberOpt) func(eventstore.Event) handler.Exec {
|
||||
config := reduceMemberConfig{
|
||||
conds: []handler.Condition{
|
||||
handler.NewCond(MemberInstanceID, e.Aggregate().InstanceID),
|
||||
@@ -140,7 +139,7 @@ func multiReduceMemberOwnerRemoved(e eventstore.Event, opts ...reduceMemberOpt)
|
||||
config = opt(config)
|
||||
}
|
||||
|
||||
return crdb.AddDeleteStatement(
|
||||
return handler.AddDeleteStatement(
|
||||
config.conds,
|
||||
)
|
||||
}
|
||||
@@ -161,25 +160,25 @@ func memberUserOwnerRemovedConds(e eventstore.Event, opts ...reduceMemberOpt) []
|
||||
|
||||
func memberUserOwnerRemovedCols(e eventstore.Event) []handler.Column {
|
||||
return []handler.Column{
|
||||
handler.NewCol(MemberChangeDate, e.CreationDate()),
|
||||
handler.NewCol(MemberChangeDate, e.CreatedAt()),
|
||||
handler.NewCol(MemberSequence, e.Sequence()),
|
||||
handler.NewCol(MemberUserOwnerRemoved, true),
|
||||
}
|
||||
}
|
||||
|
||||
func reduceMemberUserOwnerRemoved(e eventstore.Event, opts ...reduceMemberOpt) (*handler.Statement, error) {
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
memberUserOwnerRemovedConds(e, opts...),
|
||||
), nil
|
||||
}
|
||||
|
||||
func multiReduceMemberUserOwnerRemoved(e eventstore.Event, opts ...reduceMemberOpt) func(eventstore.Event) crdb.Exec {
|
||||
return crdb.AddDeleteStatement(
|
||||
func multiReduceMemberUserOwnerRemoved(e eventstore.Event, opts ...reduceMemberOpt) func(eventstore.Event) handler.Exec {
|
||||
return handler.AddDeleteStatement(
|
||||
memberUserOwnerRemovedConds(e, opts...),
|
||||
)
|
||||
}
|
||||
|
||||
func setMemberContext(event eventstore.Aggregate) context.Context {
|
||||
return authz.WithInstanceID(context.Background(), event.InstanceID)
|
||||
func setMemberContext(aggregate *eventstore.Aggregate) context.Context {
|
||||
return authz.WithInstanceID(context.Background(), aggregate.InstanceID)
|
||||
}
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -25,22 +24,22 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceAdded Title",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.CustomTextSetEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.CustomTextSetEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Title",
|
||||
"language": "en",
|
||||
"template": "InitCode",
|
||||
"text": "Test"
|
||||
}`),
|
||||
), org.CustomTextSetEventMapper),
|
||||
), org.CustomTextSetEventMapper),
|
||||
},
|
||||
reduce: (&messageTextProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -64,22 +63,22 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceAdded PreHeader",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.CustomTextSetEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.CustomTextSetEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "PreHeader",
|
||||
"language": "en",
|
||||
"template": "InitCode",
|
||||
"text": "Test"
|
||||
}`),
|
||||
), org.CustomTextSetEventMapper),
|
||||
), org.CustomTextSetEventMapper),
|
||||
},
|
||||
reduce: (&messageTextProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -103,22 +102,22 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceAdded Subject",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.CustomTextSetEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.CustomTextSetEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Subject",
|
||||
"language": "en",
|
||||
"template": "InitCode",
|
||||
"text": "Test"
|
||||
}`),
|
||||
), org.CustomTextSetEventMapper),
|
||||
), org.CustomTextSetEventMapper),
|
||||
},
|
||||
reduce: (&messageTextProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -142,22 +141,22 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceAdded Greeting",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.CustomTextSetEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.CustomTextSetEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Greeting",
|
||||
"language": "en",
|
||||
"template": "InitCode",
|
||||
"text": "Test"
|
||||
}`),
|
||||
), org.CustomTextSetEventMapper),
|
||||
), org.CustomTextSetEventMapper),
|
||||
},
|
||||
reduce: (&messageTextProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -181,22 +180,22 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceAdded Text",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.CustomTextSetEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.CustomTextSetEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Text",
|
||||
"language": "en",
|
||||
"template": "InitCode",
|
||||
"text": "Test"
|
||||
}`),
|
||||
), org.CustomTextSetEventMapper),
|
||||
), org.CustomTextSetEventMapper),
|
||||
},
|
||||
reduce: (&messageTextProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -220,22 +219,22 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceAdded ButtonText",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.CustomTextSetEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.CustomTextSetEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "ButtonText",
|
||||
"language": "en",
|
||||
"template": "InitCode",
|
||||
"text": "Test"
|
||||
}`),
|
||||
), org.CustomTextSetEventMapper),
|
||||
), org.CustomTextSetEventMapper),
|
||||
},
|
||||
reduce: (&messageTextProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -259,22 +258,22 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceAdded Footer",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.CustomTextSetEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.CustomTextSetEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Footer",
|
||||
"language": "en",
|
||||
"template": "InitCode",
|
||||
"text": "Test"
|
||||
}`),
|
||||
), org.CustomTextSetEventMapper),
|
||||
), org.CustomTextSetEventMapper),
|
||||
},
|
||||
reduce: (&messageTextProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -298,21 +297,21 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceRemoved Title",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.CustomTextRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.CustomTextRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Title",
|
||||
"language": "en",
|
||||
"template": "InitCode"
|
||||
}`),
|
||||
), org.CustomTextRemovedEventMapper),
|
||||
), org.CustomTextRemovedEventMapper),
|
||||
},
|
||||
reduce: (&messageTextProjection{}).reduceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -334,17 +333,17 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(MessageTextInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -360,21 +359,21 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceRemoved PreHeader",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.CustomTextRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.CustomTextRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "PreHeader",
|
||||
"language": "en",
|
||||
"template": "InitCode"
|
||||
}`),
|
||||
), org.CustomTextRemovedEventMapper),
|
||||
), org.CustomTextRemovedEventMapper),
|
||||
},
|
||||
reduce: (&messageTextProjection{}).reduceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -396,21 +395,21 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceRemoved Subject",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.CustomTextRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.CustomTextRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Subject",
|
||||
"language": "en",
|
||||
"template": "InitCode"
|
||||
}`),
|
||||
), org.CustomTextRemovedEventMapper),
|
||||
), org.CustomTextRemovedEventMapper),
|
||||
},
|
||||
reduce: (&messageTextProjection{}).reduceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -432,21 +431,21 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceRemoved Greeting",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.CustomTextRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.CustomTextRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Greeting",
|
||||
"language": "en",
|
||||
"template": "InitCode"
|
||||
}`),
|
||||
), org.CustomTextRemovedEventMapper),
|
||||
), org.CustomTextRemovedEventMapper),
|
||||
},
|
||||
reduce: (&messageTextProjection{}).reduceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -468,21 +467,21 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceRemoved Text",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.CustomTextRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.CustomTextRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Text",
|
||||
"language": "en",
|
||||
"template": "InitCode"
|
||||
}`),
|
||||
), org.CustomTextRemovedEventMapper),
|
||||
), org.CustomTextRemovedEventMapper),
|
||||
},
|
||||
reduce: (&messageTextProjection{}).reduceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -504,21 +503,21 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceRemoved ButtonText",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.CustomTextRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.CustomTextRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "ButtonText",
|
||||
"language": "en",
|
||||
"template": "InitCode"
|
||||
}`),
|
||||
), org.CustomTextRemovedEventMapper),
|
||||
), org.CustomTextRemovedEventMapper),
|
||||
},
|
||||
reduce: (&messageTextProjection{}).reduceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -540,21 +539,21 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceRemoved Footer",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.CustomTextRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.CustomTextRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Footer",
|
||||
"language": "en",
|
||||
"template": "InitCode"
|
||||
}`),
|
||||
), org.CustomTextRemovedEventMapper),
|
||||
), org.CustomTextRemovedEventMapper),
|
||||
},
|
||||
reduce: (&messageTextProjection{}).reduceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -577,20 +576,20 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
name: "org reduceRemoved",
|
||||
reduce: (&messageTextProjection{}).reduceTemplateRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.CustomTextTemplateRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.CustomTextTemplateRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Title",
|
||||
"language": "en",
|
||||
"template": "InitCode"
|
||||
}`),
|
||||
), org.CustomTextTemplateRemovedEventMapper),
|
||||
), org.CustomTextTemplateRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -610,21 +609,21 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceAdded",
|
||||
reduce: (&messageTextProjection{}).reduceAdded,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.CustomTextSetEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.CustomTextSetEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Title",
|
||||
"language": "en",
|
||||
"template": "InitCode",
|
||||
"text": "Test"
|
||||
}`),
|
||||
), instance.CustomTextSetEventMapper),
|
||||
), instance.CustomTextSetEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -648,21 +647,21 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceRemoved Title",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.CustomTextRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.CustomTextRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "Title",
|
||||
"language": "en",
|
||||
"template": "InitCode"
|
||||
}`),
|
||||
), instance.CustomTextRemovedEventMapper),
|
||||
), instance.CustomTextRemovedEventMapper),
|
||||
},
|
||||
reduce: (&messageTextProjection{}).reduceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -685,16 +684,16 @@ func TestMessageTextProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (&messageTextProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
@@ -34,46 +34,47 @@ const (
|
||||
MessageTextOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type messageTextProjection struct {
|
||||
crdb.StatementHandler
|
||||
type messageTextProjection struct{}
|
||||
|
||||
func newMessageTextProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(messageTextProjection))
|
||||
}
|
||||
|
||||
func newMessageTextProjection(ctx context.Context, config crdb.StatementHandlerConfig) *messageTextProjection {
|
||||
p := new(messageTextProjection)
|
||||
config.ProjectionName = MessageTextTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(MessageTextAggregateIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(MessageTextInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(MessageTextCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(MessageTextChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(MessageTextSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(MessageTextStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(MessageTextTypeCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(MessageTextLanguageCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(MessageTextTitleCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(MessageTextPreHeaderCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(MessageTextSubjectCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(MessageTextGreetingCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(MessageTextTextCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(MessageTextButtonTextCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(MessageTextFooterCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(MessageTextOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*messageTextProjection) Name() string {
|
||||
return MessageTextTable
|
||||
}
|
||||
|
||||
func (*messageTextProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(MessageTextAggregateIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(MessageTextInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(MessageTextCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(MessageTextChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(MessageTextSequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(MessageTextStateCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(MessageTextTypeCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(MessageTextLanguageCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(MessageTextTitleCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(MessageTextPreHeaderCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(MessageTextSubjectCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(MessageTextGreetingCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(MessageTextTextCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(MessageTextButtonTextCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(MessageTextFooterCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(MessageTextOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(MessageTextInstanceIDCol, MessageTextAggregateIDCol, MessageTextTypeCol, MessageTextLanguageCol),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{MessageTextOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(MessageTextInstanceIDCol, MessageTextAggregateIDCol, MessageTextTypeCol, MessageTextLanguageCol),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{MessageTextOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *messageTextProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *messageTextProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.CustomTextSetEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -94,7 +95,7 @@ func (p *messageTextProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.CustomTextSetEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -127,7 +128,7 @@ func (p *messageTextProjection) reduceAdded(event eventstore.Event) (*handler.St
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-2n90r", "reduce.wrong.event.type %v", []eventstore.EventType{org.CustomTextSetEventType, instance.CustomTextSetEventType})
|
||||
}
|
||||
if !isMessageTemplate(templateEvent.Template) {
|
||||
return crdb.NewNoOpStatement(event), nil
|
||||
return handler.NewNoOpStatement(event), nil
|
||||
}
|
||||
|
||||
cols := []handler.Column{
|
||||
@@ -161,7 +162,7 @@ func (p *messageTextProjection) reduceAdded(event eventstore.Event) (*handler.St
|
||||
if isFooterText(templateEvent.Key) {
|
||||
cols = append(cols, handler.NewCol(MessageTextFooterCol, templateEvent.Text))
|
||||
}
|
||||
return crdb.NewUpsertStatement(
|
||||
return handler.NewUpsertStatement(
|
||||
&templateEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(MessageTextInstanceIDCol, nil),
|
||||
@@ -184,7 +185,7 @@ func (p *messageTextProjection) reduceRemoved(event eventstore.Event) (*handler.
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-fm0ge", "reduce.wrong.event.type %v", []eventstore.EventType{org.CustomTextRemovedEventType, instance.CustomTextRemovedEventType})
|
||||
}
|
||||
if !isMessageTemplate(templateEvent.Template) {
|
||||
return crdb.NewNoOpStatement(event), nil
|
||||
return handler.NewNoOpStatement(event), nil
|
||||
}
|
||||
cols := []handler.Column{
|
||||
handler.NewCol(MessageTextChangeDateCol, templateEvent.CreationDate()),
|
||||
@@ -211,7 +212,7 @@ func (p *messageTextProjection) reduceRemoved(event eventstore.Event) (*handler.
|
||||
if isFooterText(templateEvent.Key) {
|
||||
cols = append(cols, handler.NewCol(MessageTextFooterCol, ""))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&templateEvent,
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
@@ -234,9 +235,9 @@ func (p *messageTextProjection) reduceTemplateRemoved(event eventstore.Event) (*
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-2n9rs", "reduce.wrong.event.type %s", org.CustomTextTemplateRemovedEventType)
|
||||
}
|
||||
if !isMessageTemplate(templateEvent.Template) {
|
||||
return crdb.NewNoOpStatement(event), nil
|
||||
return handler.NewNoOpStatement(event), nil
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
event,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(MessageTextAggregateIDCol, templateEvent.Aggregate().ID),
|
||||
@@ -253,7 +254,7 @@ func (p *messageTextProjection) reduceOwnerRemoved(event eventstore.Event) (*han
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-mLsQw", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(MessageTextInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -3,11 +3,11 @@ package projection
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
internal_authz "github.com/zitadel/zitadel/internal/api/authz"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/milestone"
|
||||
"github.com/zitadel/zitadel/internal/repository/project"
|
||||
@@ -26,34 +26,38 @@ const (
|
||||
)
|
||||
|
||||
type milestoneProjection struct {
|
||||
crdb.StatementHandler
|
||||
systemUsers map[string]*internal_authz.SystemAPIUser
|
||||
}
|
||||
|
||||
func newMilestoneProjection(ctx context.Context, config crdb.StatementHandlerConfig) *milestoneProjection {
|
||||
p := new(milestoneProjection)
|
||||
config.ProjectionName = MilestonesProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewMultiTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(MilestoneColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(MilestoneColumnType, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(MilestoneColumnReachedDate, crdb.ColumnTypeTimestamp, crdb.Nullable()),
|
||||
crdb.NewColumn(MilestoneColumnPushedDate, crdb.ColumnTypeTimestamp, crdb.Nullable()),
|
||||
crdb.NewColumn(MilestoneColumnPrimaryDomain, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(MilestoneColumnIgnoreClientIDs, crdb.ColumnTypeTextArray, crdb.Nullable()),
|
||||
func newMilestoneProjection(ctx context.Context, config handler.Config, systemUsers map[string]*internal_authz.SystemAPIUser) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, &milestoneProjection{systemUsers: systemUsers})
|
||||
}
|
||||
|
||||
func (*milestoneProjection) Name() string {
|
||||
return MilestonesProjectionTable
|
||||
}
|
||||
|
||||
func (*milestoneProjection) Init() *old_handler.Check {
|
||||
return handler.NewMultiTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(MilestoneColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(MilestoneColumnType, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(MilestoneColumnReachedDate, handler.ColumnTypeTimestamp, handler.Nullable()),
|
||||
handler.NewColumn(MilestoneColumnPushedDate, handler.ColumnTypeTimestamp, handler.Nullable()),
|
||||
handler.NewColumn(MilestoneColumnPrimaryDomain, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(MilestoneColumnIgnoreClientIDs, handler.ColumnTypeTextArray, handler.Nullable()),
|
||||
},
|
||||
crdb.NewPrimaryKey(MilestoneColumnInstanceID, MilestoneColumnType),
|
||||
handler.NewPrimaryKey(MilestoneColumnInstanceID, MilestoneColumnType),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *milestoneProjection) reducers() []handler.AggregateReducer {
|
||||
// Reducers implements handler.Projection.
|
||||
func (p *milestoneProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceAddedEventType,
|
||||
Reduce: p.reduceInstanceAdded,
|
||||
@@ -70,7 +74,7 @@ func (p *milestoneProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: project.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: project.ProjectAddedType,
|
||||
Reduce: p.reduceProjectAdded,
|
||||
@@ -91,7 +95,7 @@ func (p *milestoneProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: user.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
// user.UserTokenAddedType is not emitted on creation of personal access tokens
|
||||
// PATs have no effect on milestone.AuthenticationSucceededOnApplication or milestone.AuthenticationSucceededOnInstance
|
||||
@@ -102,7 +106,7 @@ func (p *milestoneProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: milestone.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: milestone.PushedEventType,
|
||||
Reduce: p.reduceMilestonePushed,
|
||||
@@ -118,18 +122,18 @@ func (p *milestoneProjection) reduceInstanceAdded(event eventstore.Event) (*hand
|
||||
return nil, err
|
||||
}
|
||||
allTypes := milestone.AllTypes()
|
||||
statements := make([]func(eventstore.Event) crdb.Exec, 0, len(allTypes))
|
||||
statements := make([]func(eventstore.Event) handler.Exec, 0, len(allTypes))
|
||||
for _, msType := range allTypes {
|
||||
createColumns := []handler.Column{
|
||||
handler.NewCol(MilestoneColumnInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCol(MilestoneColumnType, msType),
|
||||
}
|
||||
if msType == milestone.InstanceCreated {
|
||||
createColumns = append(createColumns, handler.NewCol(MilestoneColumnReachedDate, event.CreationDate()))
|
||||
createColumns = append(createColumns, handler.NewCol(MilestoneColumnReachedDate, event.CreatedAt()))
|
||||
}
|
||||
statements = append(statements, crdb.AddCreateStatement(createColumns))
|
||||
statements = append(statements, handler.AddCreateStatement(createColumns))
|
||||
}
|
||||
return crdb.NewMultiStatement(e, statements...), nil
|
||||
return handler.NewMultiStatement(e, statements...), nil
|
||||
}
|
||||
|
||||
func (p *milestoneProjection) reduceInstanceDomainPrimarySet(event eventstore.Event) (*handler.Statement, error) {
|
||||
@@ -137,14 +141,14 @@ func (p *milestoneProjection) reduceInstanceDomainPrimarySet(event eventstore.Ev
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(MilestoneColumnPrimaryDomain, e.Domain),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(MilestoneColumnInstanceID, e.Aggregate().InstanceID),
|
||||
crdb.NewIsNullCond(MilestoneColumnPushedDate),
|
||||
handler.NewIsNullCond(MilestoneColumnPushedDate),
|
||||
},
|
||||
), nil
|
||||
}
|
||||
@@ -184,33 +188,33 @@ func (p *milestoneProjection) reduceUserTokenAdded(event eventstore.Event) (*han
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
statements := []func(eventstore.Event) crdb.Exec{
|
||||
crdb.AddUpdateStatement(
|
||||
statements := []func(eventstore.Event) handler.Exec{
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(MilestoneColumnReachedDate, event.CreationDate()),
|
||||
handler.NewCol(MilestoneColumnReachedDate, event.CreatedAt()),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID),
|
||||
handler.NewCond(MilestoneColumnType, milestone.AuthenticationSucceededOnInstance),
|
||||
crdb.NewIsNullCond(MilestoneColumnReachedDate),
|
||||
handler.NewIsNullCond(MilestoneColumnReachedDate),
|
||||
},
|
||||
),
|
||||
}
|
||||
// We ignore authentications without app, for example JWT profile or PAT
|
||||
if e.ApplicationID != "" {
|
||||
statements = append(statements, crdb.AddUpdateStatement(
|
||||
statements = append(statements, handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(MilestoneColumnReachedDate, event.CreationDate()),
|
||||
handler.NewCol(MilestoneColumnReachedDate, event.CreatedAt()),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID),
|
||||
handler.NewCond(MilestoneColumnType, milestone.AuthenticationSucceededOnApplication),
|
||||
crdb.Not(crdb.NewTextArrayContainsCond(MilestoneColumnIgnoreClientIDs, e.ApplicationID)),
|
||||
crdb.NewIsNullCond(MilestoneColumnReachedDate),
|
||||
handler.Not(handler.NewTextArrayContainsCond(MilestoneColumnIgnoreClientIDs, e.ApplicationID)),
|
||||
handler.NewIsNullCond(MilestoneColumnReachedDate),
|
||||
},
|
||||
))
|
||||
}
|
||||
return crdb.NewMultiStatement(e, statements...), nil
|
||||
return handler.NewMultiStatement(e, statements...), nil
|
||||
}
|
||||
|
||||
func (p *milestoneProjection) reduceInstanceRemoved(event eventstore.Event) (*handler.Statement, error) {
|
||||
@@ -226,10 +230,10 @@ func (p *milestoneProjection) reduceMilestonePushed(event eventstore.Event) (*ha
|
||||
return nil, err
|
||||
}
|
||||
if e.MilestoneType != milestone.InstanceDeleted {
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(MilestoneColumnPushedDate, event.CreationDate()),
|
||||
handler.NewCol(MilestoneColumnPushedDate, event.CreatedAt()),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID),
|
||||
@@ -237,7 +241,7 @@ func (p *milestoneProjection) reduceMilestonePushed(event eventstore.Event) (*ha
|
||||
},
|
||||
), nil
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
event,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID),
|
||||
@@ -248,7 +252,7 @@ func (p *milestoneProjection) reduceMilestonePushed(event eventstore.Event) (*ha
|
||||
func (p *milestoneProjection) reduceReachedIfUserEventFunc(msType milestone.Type) func(event eventstore.Event) (*handler.Statement, error) {
|
||||
return func(event eventstore.Event) (*handler.Statement, error) {
|
||||
if p.isSystemEvent(event) {
|
||||
return crdb.NewNoOpStatement(event), nil
|
||||
return handler.NewNoOpStatement(event), nil
|
||||
}
|
||||
return p.reduceReachedFunc(msType)(event)
|
||||
}
|
||||
@@ -256,40 +260,46 @@ func (p *milestoneProjection) reduceReachedIfUserEventFunc(msType milestone.Type
|
||||
|
||||
func (p *milestoneProjection) reduceReachedFunc(msType milestone.Type) func(event eventstore.Event) (*handler.Statement, error) {
|
||||
return func(event eventstore.Event) (*handler.Statement, error) {
|
||||
return crdb.NewUpdateStatement(event, []handler.Column{
|
||||
handler.NewCol(MilestoneColumnReachedDate, event.CreationDate()),
|
||||
return handler.NewUpdateStatement(event, []handler.Column{
|
||||
handler.NewCol(MilestoneColumnReachedDate, event.CreatedAt()),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID),
|
||||
handler.NewCond(MilestoneColumnType, msType),
|
||||
crdb.NewIsNullCond(MilestoneColumnReachedDate),
|
||||
handler.NewIsNullCond(MilestoneColumnReachedDate),
|
||||
}), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p *milestoneProjection) reduceAppConfigAdded(event eventstore.Event, clientID string) (*handler.Statement, error) {
|
||||
if !p.isSystemEvent(event) {
|
||||
return crdb.NewNoOpStatement(event), nil
|
||||
return handler.NewNoOpStatement(event), nil
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
crdb.NewArrayAppendCol(MilestoneColumnIgnoreClientIDs, clientID),
|
||||
handler.NewArrayAppendCol(MilestoneColumnIgnoreClientIDs, clientID),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(MilestoneColumnInstanceID, event.Aggregate().InstanceID),
|
||||
handler.NewCond(MilestoneColumnType, milestone.AuthenticationSucceededOnApplication),
|
||||
crdb.NewIsNullCond(MilestoneColumnReachedDate),
|
||||
handler.NewIsNullCond(MilestoneColumnReachedDate),
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *milestoneProjection) isSystemEvent(event eventstore.Event) bool {
|
||||
if userId, err := strconv.Atoi(event.EditorUser()); err == nil && userId > 0 {
|
||||
if userId, err := strconv.Atoi(event.Creator()); err == nil && userId > 0 {
|
||||
return false
|
||||
}
|
||||
lowerEditorService := strings.ToLower(event.EditorService())
|
||||
return lowerEditorService == "" ||
|
||||
lowerEditorService == "system" ||
|
||||
lowerEditorService == "system-api"
|
||||
|
||||
// check if it is a hard coded event creator
|
||||
for _, creator := range []string{"", "system", "OIDC", "LOGIN", "SYSTEM"} {
|
||||
if creator == event.Creator() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
_, ok := p.systemUsers[event.Creator()]
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/milestone"
|
||||
"github.com/zitadel/zitadel/internal/repository/project"
|
||||
@@ -30,7 +29,7 @@ func TestMilestonesProjection_reduces(t *testing.T) {
|
||||
name: "reduceInstanceAdded",
|
||||
args: args{
|
||||
event: getEvent(timedTestEvent(
|
||||
repository.EventType(instance.InstanceAddedEventType),
|
||||
instance.InstanceAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{}`),
|
||||
now,
|
||||
@@ -38,9 +37,8 @@ func TestMilestonesProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&milestoneProjection{}).reduceInstanceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -94,16 +92,15 @@ func TestMilestonesProjection_reduces(t *testing.T) {
|
||||
name: "reduceInstancePrimaryDomainSet",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceDomainPrimarySetEventType),
|
||||
instance.InstanceDomainPrimarySetEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"domain": "my.domain"}`),
|
||||
), instance.DomainPrimarySetEventMapper),
|
||||
},
|
||||
reduce: (&milestoneProjection{}).reduceInstanceDomainPrimarySet,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -121,7 +118,7 @@ func TestMilestonesProjection_reduces(t *testing.T) {
|
||||
name: "reduceProjectAdded",
|
||||
args: args{
|
||||
event: getEvent(timedTestEvent(
|
||||
repository.EventType(project.ProjectAddedType),
|
||||
project.ProjectAddedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{}`),
|
||||
now,
|
||||
@@ -129,9 +126,8 @@ func TestMilestonesProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&milestoneProjection{}).reduceProjectAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -150,7 +146,7 @@ func TestMilestonesProjection_reduces(t *testing.T) {
|
||||
name: "reduceApplicationAdded",
|
||||
args: args{
|
||||
event: getEvent(timedTestEvent(
|
||||
repository.EventType(project.ApplicationAddedType),
|
||||
project.ApplicationAddedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{}`),
|
||||
now,
|
||||
@@ -158,9 +154,8 @@ func TestMilestonesProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&milestoneProjection{}).reduceApplicationAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -179,33 +174,31 @@ func TestMilestonesProjection_reduces(t *testing.T) {
|
||||
name: "reduceOIDCConfigAdded user event",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.OIDCConfigAddedType),
|
||||
project.OIDCConfigAddedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), project.OIDCConfigAddedEventMapper),
|
||||
},
|
||||
reduce: (&milestoneProjection{}).reduceOIDCConfigAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
executer: &testExecuter{},
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "reduceOIDCConfigAdded system event",
|
||||
args: args{
|
||||
event: getEvent(toSystemEvent(testEvent(
|
||||
repository.EventType(project.OIDCConfigAddedType),
|
||||
project.OIDCConfigAddedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"clientId": "client-id"}`),
|
||||
)), project.OIDCConfigAddedEventMapper),
|
||||
},
|
||||
reduce: (&milestoneProjection{}).reduceOIDCConfigAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -224,33 +217,31 @@ func TestMilestonesProjection_reduces(t *testing.T) {
|
||||
name: "reduceAPIConfigAdded user event",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.APIConfigAddedType),
|
||||
project.APIConfigAddedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), project.APIConfigAddedEventMapper),
|
||||
},
|
||||
reduce: (&milestoneProjection{}).reduceAPIConfigAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
executer: &testExecuter{},
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "reduceAPIConfigAdded system event",
|
||||
args: args{
|
||||
event: getEvent(toSystemEvent(testEvent(
|
||||
repository.EventType(project.APIConfigAddedType),
|
||||
project.APIConfigAddedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"clientId": "client-id"}`),
|
||||
)), project.APIConfigAddedEventMapper),
|
||||
},
|
||||
reduce: (&milestoneProjection{}).reduceAPIConfigAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -269,7 +260,7 @@ func TestMilestonesProjection_reduces(t *testing.T) {
|
||||
name: "reduceUserTokenAdded",
|
||||
args: args{
|
||||
event: getEvent(timedTestEvent(
|
||||
repository.EventType(user.UserTokenAddedType),
|
||||
user.UserTokenAddedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{"applicationId": "client-id"}`),
|
||||
now,
|
||||
@@ -277,9 +268,8 @@ func TestMilestonesProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&milestoneProjection{}).reduceUserTokenAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("user"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("user"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
// TODO: This can be optimized to only use one statement with OR
|
||||
executions: []execution{
|
||||
@@ -297,7 +287,7 @@ func TestMilestonesProjection_reduces(t *testing.T) {
|
||||
now,
|
||||
"instance-id",
|
||||
milestone.AuthenticationSucceededOnApplication,
|
||||
database.StringArray{"client-id"},
|
||||
database.TextArray[string]{"client-id"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -308,7 +298,7 @@ func TestMilestonesProjection_reduces(t *testing.T) {
|
||||
name: "reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(timedTestEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{}`),
|
||||
now,
|
||||
@@ -316,9 +306,8 @@ func TestMilestonesProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&milestoneProjection{}).reduceInstanceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -337,7 +326,7 @@ func TestMilestonesProjection_reduces(t *testing.T) {
|
||||
name: "reduceMilestonePushed normal milestone",
|
||||
args: args{
|
||||
event: getEvent(timedTestEvent(
|
||||
repository.EventType(milestone.PushedEventType),
|
||||
milestone.PushedEventType,
|
||||
milestone.AggregateType,
|
||||
[]byte(`{"type": "ProjectCreated"}`),
|
||||
now,
|
||||
@@ -345,9 +334,8 @@ func TestMilestonesProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&milestoneProjection{}).reduceMilestonePushed,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("milestone"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("milestone"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -366,16 +354,15 @@ func TestMilestonesProjection_reduces(t *testing.T) {
|
||||
name: "reduceMilestonePushed instance deleted milestone",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(milestone.PushedEventType),
|
||||
milestone.PushedEventType,
|
||||
milestone.AggregateType,
|
||||
[]byte(`{"type": "InstanceDeleted"}`),
|
||||
), milestone.PushedEventMapper),
|
||||
},
|
||||
reduce: (&milestoneProjection{}).reduceMilestonePushed,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("milestone"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("milestone"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
@@ -28,39 +28,40 @@ const (
|
||||
NotificationPolicyColumnOwnerRemoved = "owner_removed"
|
||||
)
|
||||
|
||||
type notificationPolicyProjection struct {
|
||||
crdb.StatementHandler
|
||||
type notificationPolicyProjection struct{}
|
||||
|
||||
func newNotificationPolicyProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(notificationPolicyProjection))
|
||||
}
|
||||
|
||||
func newNotificationPolicyProjection(ctx context.Context, config crdb.StatementHandlerConfig) *notificationPolicyProjection {
|
||||
p := new(notificationPolicyProjection)
|
||||
config.ProjectionName = NotificationPolicyProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(NotificationPolicyColumnID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(NotificationPolicyColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(NotificationPolicyColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(NotificationPolicyColumnResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(NotificationPolicyColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(NotificationPolicyColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(NotificationPolicyColumnStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(NotificationPolicyColumnIsDefault, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(NotificationPolicyColumnPasswordChange, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(NotificationPolicyColumnOwnerRemoved, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*notificationPolicyProjection) Name() string {
|
||||
return NotificationPolicyProjectionTable
|
||||
}
|
||||
|
||||
func (*notificationPolicyProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(NotificationPolicyColumnID, handler.ColumnTypeText),
|
||||
handler.NewColumn(NotificationPolicyColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(NotificationPolicyColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(NotificationPolicyColumnResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(NotificationPolicyColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(NotificationPolicyColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(NotificationPolicyColumnStateCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(NotificationPolicyColumnIsDefault, handler.ColumnTypeBool),
|
||||
handler.NewColumn(NotificationPolicyColumnPasswordChange, handler.ColumnTypeBool),
|
||||
handler.NewColumn(NotificationPolicyColumnOwnerRemoved, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(NotificationPolicyColumnInstanceID, NotificationPolicyColumnID),
|
||||
handler.NewPrimaryKey(NotificationPolicyColumnInstanceID, NotificationPolicyColumnID),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *notificationPolicyProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *notificationPolicyProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.NotificationPolicyAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -81,7 +82,7 @@ func (p *notificationPolicyProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(NotificationPolicyColumnInstanceID),
|
||||
@@ -112,7 +113,7 @@ func (p *notificationPolicyProjection) reduceAdded(event eventstore.Event) (*han
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-x02s1m", "reduce.wrong.event.type %v", []eventstore.EventType{org.NotificationPolicyAddedEventType, instance.NotificationPolicyAddedEventType})
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
&policyEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(NotificationPolicyColumnCreationDate, policyEvent.CreationDate()),
|
||||
@@ -144,7 +145,7 @@ func (p *notificationPolicyProjection) reduceChanged(event eventstore.Event) (*h
|
||||
if policyEvent.PasswordChange != nil {
|
||||
cols = append(cols, handler.NewCol(NotificationPolicyColumnPasswordChange, *policyEvent.PasswordChange))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&policyEvent,
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
@@ -158,7 +159,7 @@ func (p *notificationPolicyProjection) reduceRemoved(event eventstore.Event) (*h
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Po2iso2", "reduce.wrong.event.type %s", org.NotificationPolicyRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
policyEvent,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(NotificationPolicyColumnID, policyEvent.Aggregate().ID),
|
||||
@@ -172,7 +173,7 @@ func (p *notificationPolicyProjection) reduceOwnerRemoved(event eventstore.Event
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-poxi9a", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(DomainPolicyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -25,19 +24,19 @@ func TestNotificationPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.NotificationPolicyAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.NotificationPolicyAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"passwordChange": true
|
||||
}`),
|
||||
), org.NotificationPolicyAddedEventMapper),
|
||||
), org.NotificationPolicyAddedEventMapper),
|
||||
},
|
||||
reduce: (¬ificationPolicyProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -62,18 +61,18 @@ func TestNotificationPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org reduceChanged",
|
||||
reduce: (¬ificationPolicyProjection{}).reduceChanged,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.NotificationPolicyChangedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.NotificationPolicyChangedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"passwordChange": true
|
||||
}`),
|
||||
), org.NotificationPolicyChangedEventMapper),
|
||||
), org.NotificationPolicyChangedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -94,16 +93,16 @@ func TestNotificationPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org reduceRemoved",
|
||||
reduce: (¬ificationPolicyProjection{}).reduceRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.NotificationPolicyRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.NotificationPolicyRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.NotificationPolicyRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.NotificationPolicyRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -119,17 +118,17 @@ func TestNotificationPolicyProjection_reduces(t *testing.T) {
|
||||
}, {
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(NotificationPolicyColumnInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -146,18 +145,18 @@ func TestNotificationPolicyProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceAdded",
|
||||
reduce: (¬ificationPolicyProjection{}).reduceAdded,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.NotificationPolicyAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.NotificationPolicyAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"passwordChange": true
|
||||
}`),
|
||||
), instance.NotificationPolicyAddedEventMapper),
|
||||
), instance.NotificationPolicyAddedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -182,18 +181,18 @@ func TestNotificationPolicyProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceChanged",
|
||||
reduce: (¬ificationPolicyProjection{}).reduceChanged,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.NotificationPolicyChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.NotificationPolicyChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"passwordChange": true
|
||||
}`),
|
||||
), instance.NotificationPolicyChangedEventMapper),
|
||||
), instance.NotificationPolicyChangedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -214,16 +213,16 @@ func TestNotificationPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (¬ificationPolicyProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
@@ -25,39 +25,40 @@ const (
|
||||
OIDCSettingsColumnRefreshTokenExpiration = "refresh_token_expiration"
|
||||
)
|
||||
|
||||
type oidcSettingsProjection struct {
|
||||
crdb.StatementHandler
|
||||
type oidcSettingsProjection struct{}
|
||||
|
||||
func newOIDCSettingsProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(oidcSettingsProjection))
|
||||
}
|
||||
|
||||
func newOIDCSettingsProjection(ctx context.Context, config crdb.StatementHandlerConfig) *oidcSettingsProjection {
|
||||
p := new(oidcSettingsProjection)
|
||||
config.ProjectionName = OIDCSettingsProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(OIDCSettingsColumnAggregateID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OIDCSettingsColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(OIDCSettingsColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(OIDCSettingsColumnResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OIDCSettingsColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OIDCSettingsColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(OIDCSettingsColumnAccessTokenLifetime, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(OIDCSettingsColumnIdTokenLifetime, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(OIDCSettingsColumnRefreshTokenIdleExpiration, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(OIDCSettingsColumnRefreshTokenExpiration, crdb.ColumnTypeInt64),
|
||||
func (*oidcSettingsProjection) Name() string {
|
||||
return OIDCSettingsProjectionTable
|
||||
}
|
||||
|
||||
func (*oidcSettingsProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(OIDCSettingsColumnAggregateID, handler.ColumnTypeText),
|
||||
handler.NewColumn(OIDCSettingsColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(OIDCSettingsColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(OIDCSettingsColumnResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(OIDCSettingsColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(OIDCSettingsColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(OIDCSettingsColumnAccessTokenLifetime, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(OIDCSettingsColumnIdTokenLifetime, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(OIDCSettingsColumnRefreshTokenIdleExpiration, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(OIDCSettingsColumnRefreshTokenExpiration, handler.ColumnTypeInt64),
|
||||
},
|
||||
crdb.NewPrimaryKey(OIDCSettingsColumnInstanceID, OIDCSettingsColumnAggregateID),
|
||||
handler.NewPrimaryKey(OIDCSettingsColumnInstanceID, OIDCSettingsColumnAggregateID),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *oidcSettingsProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *oidcSettingsProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.OIDCSettingsAddedEventType,
|
||||
Reduce: p.reduceOIDCSettingsAdded,
|
||||
@@ -80,7 +81,7 @@ func (p *oidcSettingsProjection) reduceOIDCSettingsAdded(event eventstore.Event)
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-f9nwf", "reduce.wrong.event.type %s", instance.OIDCSettingsAddedEventType)
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(OIDCSettingsColumnAggregateID, e.Aggregate().ID),
|
||||
@@ -120,7 +121,7 @@ func (p *oidcSettingsProjection) reduceOIDCSettingsChanged(event eventstore.Even
|
||||
if e.RefreshTokenExpiration != nil {
|
||||
columns = append(columns, handler.NewCol(OIDCSettingsColumnRefreshTokenExpiration, *e.RefreshTokenExpiration))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
columns,
|
||||
[]handler.Condition{
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
@@ -24,17 +23,17 @@ func TestOIDCSettingsProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceOIDCSettingsChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.OIDCSettingsChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"accessTokenLifetime": 10000000, "idTokenLifetime": 10000000, "refreshTokenIdleExpiration": 10000000, "refreshTokenExpiration": 10000000}`),
|
||||
), instance.OIDCSettingsChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.OIDCSettingsChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"accessTokenLifetime": 10000000, "idTokenLifetime": 10000000, "refreshTokenIdleExpiration": 10000000, "refreshTokenExpiration": 10000000}`),
|
||||
), instance.OIDCSettingsChangedEventMapper),
|
||||
},
|
||||
reduce: (&oidcSettingsProjection{}).reduceOIDCSettingsChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -57,17 +56,17 @@ func TestOIDCSettingsProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceOIDCSettingsAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.OIDCSettingsAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"accessTokenLifetime": 10000000, "idTokenLifetime": 10000000, "refreshTokenIdleExpiration": 10000000, "refreshTokenExpiration": 10000000}`),
|
||||
), instance.OIDCSettingsAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.OIDCSettingsAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"accessTokenLifetime": 10000000, "idTokenLifetime": 10000000, "refreshTokenIdleExpiration": 10000000, "refreshTokenExpiration": 10000000}`),
|
||||
), instance.OIDCSettingsAddedEventMapper),
|
||||
},
|
||||
reduce: (&oidcSettingsProjection{}).reduceOIDCSettingsAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -92,17 +91,17 @@ func TestOIDCSettingsProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(OIDCSettingsColumnInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -26,40 +26,42 @@ const (
|
||||
OrgColumnDomain = "primary_domain"
|
||||
)
|
||||
|
||||
type orgProjection struct {
|
||||
crdb.StatementHandler
|
||||
type orgProjection struct{}
|
||||
|
||||
func (*orgProjection) Name() string {
|
||||
return OrgProjectionTable
|
||||
}
|
||||
|
||||
func newOrgProjection(ctx context.Context, config crdb.StatementHandlerConfig) *orgProjection {
|
||||
p := new(orgProjection)
|
||||
config.ProjectionName = OrgProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(OrgColumnID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OrgColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(OrgColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(OrgColumnResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OrgColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OrgColumnState, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(OrgColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(OrgColumnName, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OrgColumnDomain, crdb.ColumnTypeText, crdb.Default("")),
|
||||
func newOrgProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(orgProjection))
|
||||
}
|
||||
|
||||
// Init implements [handler.initializer]
|
||||
func (p *orgProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(OrgColumnID, handler.ColumnTypeText),
|
||||
handler.NewColumn(OrgColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(OrgColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(OrgColumnResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(OrgColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(OrgColumnState, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(OrgColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(OrgColumnName, handler.ColumnTypeText),
|
||||
handler.NewColumn(OrgColumnDomain, handler.ColumnTypeText, handler.Default("")),
|
||||
},
|
||||
crdb.NewPrimaryKey(OrgColumnInstanceID, OrgColumnID),
|
||||
crdb.WithIndex(crdb.NewIndex("domain", []string{OrgColumnDomain})),
|
||||
crdb.WithIndex(crdb.NewIndex("name", []string{OrgColumnName})),
|
||||
handler.NewPrimaryKey(OrgColumnInstanceID, OrgColumnID),
|
||||
handler.WithIndex(handler.NewIndex("domain", []string{OrgColumnDomain})),
|
||||
handler.WithIndex(handler.NewIndex("name", []string{OrgColumnName})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *orgProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *orgProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.OrgAddedEventType,
|
||||
Reduce: p.reduceOrgAdded,
|
||||
@@ -88,7 +90,7 @@ func (p *orgProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(OrgColumnInstanceID),
|
||||
@@ -103,7 +105,7 @@ func (p *orgProjection) reduceOrgAdded(event eventstore.Event) (*handler.Stateme
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-uYq4r", "reduce.wrong.event.type %s", org.OrgAddedEventType)
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(OrgColumnID, e.Aggregate().ID),
|
||||
@@ -124,9 +126,9 @@ func (p *orgProjection) reduceOrgChanged(event eventstore.Event) (*handler.State
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Bg8oM", "reduce.wrong.event.type %s", org.OrgChangedEventType)
|
||||
}
|
||||
if e.Name == "" {
|
||||
return crdb.NewNoOpStatement(e), nil
|
||||
return handler.NewNoOpStatement(e), nil
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(OrgColumnChangeDate, e.CreationDate()),
|
||||
@@ -145,7 +147,7 @@ func (p *orgProjection) reduceOrgDeactivated(event eventstore.Event) (*handler.S
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-BApK4", "reduce.wrong.event.type %s", org.OrgDeactivatedEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(OrgColumnChangeDate, e.CreationDate()),
|
||||
@@ -164,7 +166,7 @@ func (p *orgProjection) reduceOrgReactivated(event eventstore.Event) (*handler.S
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-o37De", "reduce.wrong.event.type %s", org.OrgReactivatedEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(OrgColumnChangeDate, e.CreationDate()),
|
||||
@@ -183,7 +185,7 @@ func (p *orgProjection) reducePrimaryDomainSet(event eventstore.Event) (*handler
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-4TbKT", "reduce.wrong.event.type %s", org.OrgDomainPrimarySetEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(OrgColumnChangeDate, e.CreationDate()),
|
||||
@@ -202,7 +204,7 @@ func (p *orgProjection) reduceOrgRemoved(event eventstore.Event) (*handler.State
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-DgMSg", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(OrgColumnID, e.Aggregate().ID),
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -27,40 +27,41 @@ const (
|
||||
OrgDomainOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type orgDomainProjection struct {
|
||||
crdb.StatementHandler
|
||||
type orgDomainProjection struct{}
|
||||
|
||||
func newOrgDomainProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(orgDomainProjection))
|
||||
}
|
||||
|
||||
func newOrgDomainProjection(ctx context.Context, config crdb.StatementHandlerConfig) *orgDomainProjection {
|
||||
p := new(orgDomainProjection)
|
||||
config.ProjectionName = OrgDomainTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(OrgDomainOrgIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OrgDomainInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OrgDomainCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(OrgDomainChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(OrgDomainSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(OrgDomainDomainCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OrgDomainIsVerifiedCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(OrgDomainIsPrimaryCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(OrgDomainValidationTypeCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(OrgDomainOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*orgDomainProjection) Name() string {
|
||||
return OrgDomainTable
|
||||
}
|
||||
|
||||
func (*orgDomainProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(OrgDomainOrgIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(OrgDomainInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(OrgDomainCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(OrgDomainChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(OrgDomainSequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(OrgDomainDomainCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(OrgDomainIsVerifiedCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(OrgDomainIsPrimaryCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(OrgDomainValidationTypeCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(OrgDomainOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(OrgDomainOrgIDCol, OrgDomainDomainCol, OrgDomainInstanceIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{OrgDomainOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(OrgDomainOrgIDCol, OrgDomainDomainCol, OrgDomainInstanceIDCol),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{OrgDomainOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *orgDomainProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *orgDomainProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.OrgDomainAddedEventType,
|
||||
Reduce: p.reduceDomainAdded,
|
||||
@@ -89,7 +90,7 @@ func (p *orgDomainProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(OrgDomainInstanceIDCol),
|
||||
@@ -104,7 +105,7 @@ func (p *orgDomainProjection) reduceDomainAdded(event eventstore.Event) (*handle
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-DM2DI", "reduce.wrong.event.type %s", org.OrgDomainAddedEventType)
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(OrgDomainCreationDateCol, e.CreationDate()),
|
||||
@@ -125,7 +126,7 @@ func (p *orgDomainProjection) reduceDomainVerificationAdded(event eventstore.Eve
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-EBzyu", "reduce.wrong.event.type %s", org.OrgDomainVerificationAddedEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(OrgDomainChangeDateCol, e.CreationDate()),
|
||||
@@ -145,7 +146,7 @@ func (p *orgDomainProjection) reduceDomainVerified(event eventstore.Event) (*han
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-3Rvkr", "reduce.wrong.event.type %s", org.OrgDomainVerifiedEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(OrgDomainChangeDateCol, e.CreationDate()),
|
||||
@@ -165,9 +166,9 @@ func (p *orgDomainProjection) reducePrimaryDomainSet(event eventstore.Event) (*h
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-aIuei", "reduce.wrong.event.type %s", org.OrgDomainPrimarySetEventType)
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(OrgDomainChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(OrgDomainSequenceCol, e.Sequence()),
|
||||
@@ -179,7 +180,7 @@ func (p *orgDomainProjection) reducePrimaryDomainSet(event eventstore.Event) (*h
|
||||
handler.NewCond(OrgDomainInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(OrgDomainChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(OrgDomainSequenceCol, e.Sequence()),
|
||||
@@ -199,7 +200,7 @@ func (p *orgDomainProjection) reduceDomainRemoved(event eventstore.Event) (*hand
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-gh1Mx", "reduce.wrong.event.type %s", org.OrgDomainRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(OrgDomainDomainCol, e.Domain),
|
||||
@@ -215,7 +216,7 @@ func (p *orgDomainProjection) reduceOwnerRemoved(event eventstore.Event) (*handl
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-dMUKJ", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(OrgDomainInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -25,17 +24,17 @@ func TestOrgDomainProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceDomainAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgDomainAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"domain": "domain.new"}`),
|
||||
), org.DomainAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgDomainAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"domain": "domain.new"}`),
|
||||
), org.DomainAddedEventMapper),
|
||||
},
|
||||
reduce: (&orgDomainProjection{}).reduceDomainAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -59,17 +58,17 @@ func TestOrgDomainProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceDomainVerificationAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgDomainVerificationAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"domain": "domain.new", "validationType": 2}`),
|
||||
), org.DomainVerificationAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgDomainVerificationAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"domain": "domain.new", "validationType": 2}`),
|
||||
), org.DomainVerificationAddedEventMapper),
|
||||
},
|
||||
reduce: (&orgDomainProjection{}).reduceDomainVerificationAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -90,17 +89,17 @@ func TestOrgDomainProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceDomainVerified",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgDomainVerifiedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"domain": "domain.new"}`),
|
||||
), org.DomainVerifiedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgDomainVerifiedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"domain": "domain.new"}`),
|
||||
), org.DomainVerifiedEventMapper),
|
||||
},
|
||||
reduce: (&orgDomainProjection{}).reduceDomainVerified,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -121,17 +120,17 @@ func TestOrgDomainProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reducePrimaryDomainSet",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgDomainPrimarySetEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"domain": "domain.new"}`),
|
||||
), org.DomainPrimarySetEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgDomainPrimarySetEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"domain": "domain.new"}`),
|
||||
), org.DomainPrimarySetEventMapper),
|
||||
},
|
||||
reduce: (&orgDomainProjection{}).reducePrimaryDomainSet,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -163,17 +162,17 @@ func TestOrgDomainProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceDomainRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgDomainRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"domain": "domain.new"}`),
|
||||
), org.DomainRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgDomainRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"domain": "domain.new"}`),
|
||||
), org.DomainRemovedEventMapper),
|
||||
},
|
||||
reduce: (&orgDomainProjection{}).reduceDomainRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -192,16 +191,16 @@ func TestOrgDomainProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (&orgDomainProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -218,17 +217,17 @@ func TestOrgDomainProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(OrgDomainInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/user"
|
||||
@@ -18,31 +18,47 @@ const (
|
||||
)
|
||||
|
||||
type orgMemberProjection struct {
|
||||
crdb.StatementHandler
|
||||
es handler.EventStore
|
||||
}
|
||||
|
||||
func newOrgMemberProjection(ctx context.Context, config crdb.StatementHandlerConfig) *orgMemberProjection {
|
||||
p := new(orgMemberProjection)
|
||||
config.ProjectionName = OrgMemberProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable(
|
||||
append(memberColumns, crdb.NewColumn(OrgMemberOrgIDCol, crdb.ColumnTypeText)),
|
||||
crdb.NewPrimaryKey(MemberInstanceID, OrgMemberOrgIDCol, MemberUserIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("user_id", []string{MemberUserIDCol})),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{MemberOwnerRemoved})),
|
||||
crdb.WithIndex(crdb.NewIndex("user_owner_removed", []string{MemberUserOwnerRemoved})),
|
||||
func newOrgMemberProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, &orgMemberProjection{es: config.Eventstore})
|
||||
}
|
||||
|
||||
func (*orgMemberProjection) Name() string {
|
||||
return OrgMemberProjectionTable
|
||||
}
|
||||
|
||||
func (*orgMemberProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable(
|
||||
append(memberColumns, handler.NewColumn(OrgMemberOrgIDCol, handler.ColumnTypeText)),
|
||||
handler.NewPrimaryKey(MemberInstanceID, OrgMemberOrgIDCol, MemberUserIDCol),
|
||||
handler.WithIndex(handler.NewIndex("user_id", []string{MemberUserIDCol})),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{MemberOwnerRemoved})),
|
||||
handler.WithIndex(handler.NewIndex("user_owner_removed", []string{MemberUserOwnerRemoved})),
|
||||
handler.WithIndex(
|
||||
handler.NewIndex("om_instance", []string{MemberInstanceID},
|
||||
handler.WithInclude(
|
||||
MemberCreationDate,
|
||||
MemberChangeDate,
|
||||
MemberUserOwnerRemoved,
|
||||
MemberRolesCol,
|
||||
MemberSequence,
|
||||
MemberResourceOwner,
|
||||
MemberOwnerRemoved,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *orgMemberProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *orgMemberProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.MemberAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -67,7 +83,7 @@ func (p *orgMemberProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: user.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: user.UserRemovedType,
|
||||
Reduce: p.reduceUserRemoved,
|
||||
@@ -76,7 +92,7 @@ func (p *orgMemberProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(MemberInstanceID),
|
||||
@@ -92,7 +108,7 @@ func (p *orgMemberProjection) reduceAdded(event eventstore.Event) (*handler.Stat
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-uYq4r", "reduce.wrong.event.type %s", org.MemberAddedEventType)
|
||||
}
|
||||
ctx := setMemberContext(e.Aggregate())
|
||||
userOwner, err := getResourceOwnerOfUser(ctx, p.Eventstore, e.Aggregate().InstanceID, e.UserID)
|
||||
userOwner, err := getResourceOwnerOfUser(ctx, p.es, e.Aggregate().InstanceID, e.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -139,7 +155,7 @@ func (p *orgMemberProjection) reduceOrgRemoved(event eventstore.Event) (*handler
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-jnGAV", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
multiReduceMemberOwnerRemoved(e),
|
||||
multiReduceMemberUserOwnerRemoved(e),
|
||||
|
||||
@@ -10,8 +10,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/user"
|
||||
@@ -30,17 +29,18 @@ func TestOrgMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org MemberAddedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.MemberAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.MemberAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"userId": "user-id",
|
||||
"roles": ["role"]
|
||||
}`),
|
||||
), org.MemberAddedEventMapper),
|
||||
), org.MemberAddedEventMapper),
|
||||
},
|
||||
reduce: (&orgMemberProjection{
|
||||
StatementHandler: getStatementHandlerWithFilters(
|
||||
es: newMockEventStore().appendFilterResponse([]eventstore.Event{
|
||||
user.NewHumanAddedEvent(context.Background(),
|
||||
&user.NewAggregate("user-id", "org1").Aggregate,
|
||||
"username1",
|
||||
@@ -53,11 +53,11 @@ func TestOrgMemberProjection_reduces(t *testing.T) {
|
||||
"email1",
|
||||
true,
|
||||
),
|
||||
)(t)}).reduceAdded,
|
||||
}),
|
||||
}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -66,7 +66,7 @@ func TestOrgMemberProjection_reduces(t *testing.T) {
|
||||
"user-id",
|
||||
"org1",
|
||||
false,
|
||||
database.StringArray{"role"},
|
||||
database.TextArray[string]{"role"},
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -83,26 +83,26 @@ func TestOrgMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org MemberChangedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.MemberChangedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.MemberChangedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"userId": "user-id",
|
||||
"roles": ["role", "changed"]
|
||||
}`),
|
||||
), org.MemberChangedEventMapper),
|
||||
), org.MemberChangedEventMapper),
|
||||
},
|
||||
reduce: (&orgMemberProjection{}).reduceChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.org_members3 SET (roles, change_date, sequence) = ($1, $2, $3) WHERE (instance_id = $4) AND (user_id = $5) AND (org_id = $6)",
|
||||
expectedArgs: []interface{}{
|
||||
database.StringArray{"role", "changed"},
|
||||
database.TextArray[string]{"role", "changed"},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"instance-id",
|
||||
@@ -117,19 +117,19 @@ func TestOrgMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org MemberCascadeRemovedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.MemberCascadeRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.MemberCascadeRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"userId": "user-id"
|
||||
}`),
|
||||
), org.MemberCascadeRemovedEventMapper),
|
||||
), org.MemberCascadeRemovedEventMapper),
|
||||
},
|
||||
reduce: (&orgMemberProjection{}).reduceCascadeRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -147,19 +147,19 @@ func TestOrgMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org MemberRemovedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.MemberRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.MemberRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"userId": "user-id"
|
||||
}`),
|
||||
), org.MemberRemovedEventMapper),
|
||||
), org.MemberRemovedEventMapper),
|
||||
},
|
||||
reduce: (&orgMemberProjection{}).reduceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -177,17 +177,17 @@ func TestOrgMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "user UserRemovedEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.UserRemovedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), user.UserRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.UserRemovedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), user.UserRemovedEventMapper),
|
||||
},
|
||||
reduce: (&orgMemberProjection{}).reduceUserRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -204,17 +204,17 @@ func TestOrgMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org OrgRemovedEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
reduce: (&orgMemberProjection{}).reduceOrgRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -238,17 +238,17 @@ func TestOrgMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(MemberInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -25,40 +25,40 @@ const (
|
||||
OrgMetadataColumnOwnerRemoved = "owner_removed"
|
||||
)
|
||||
|
||||
type orgMetadataProjection struct {
|
||||
crdb.StatementHandler
|
||||
type orgMetadataProjection struct{}
|
||||
|
||||
func (*orgMetadataProjection) Name() string {
|
||||
return OrgMetadataProjectionTable
|
||||
}
|
||||
|
||||
func newOrgMetadataProjection(ctx context.Context, config crdb.StatementHandlerConfig) *orgMetadataProjection {
|
||||
p := new(orgMetadataProjection)
|
||||
config.ProjectionName = OrgMetadataProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(OrgMetadataColumnOrgID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OrgMetadataColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(OrgMetadataColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(OrgMetadataColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(OrgMetadataColumnResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OrgMetadataColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OrgMetadataColumnKey, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OrgMetadataColumnValue, crdb.ColumnTypeBytes, crdb.Nullable()),
|
||||
crdb.NewColumn(OrgMetadataColumnOwnerRemoved, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*orgMetadataProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(OrgMetadataColumnOrgID, handler.ColumnTypeText),
|
||||
handler.NewColumn(OrgMetadataColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(OrgMetadataColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(OrgMetadataColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(OrgMetadataColumnResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(OrgMetadataColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(OrgMetadataColumnKey, handler.ColumnTypeText),
|
||||
handler.NewColumn(OrgMetadataColumnValue, handler.ColumnTypeBytes, handler.Nullable()),
|
||||
handler.NewColumn(OrgMetadataColumnOwnerRemoved, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(OrgMetadataColumnInstanceID, OrgMetadataColumnOrgID, OrgMetadataColumnKey),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{OrgMetadataColumnOwnerRemoved})),
|
||||
handler.NewPrimaryKey(OrgMetadataColumnInstanceID, OrgMetadataColumnOrgID, OrgMetadataColumnKey),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{OrgMetadataColumnOwnerRemoved})),
|
||||
),
|
||||
)
|
||||
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *orgMetadataProjection) reducers() []handler.AggregateReducer {
|
||||
func newOrgMetadataProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(orgMetadataProjection))
|
||||
}
|
||||
|
||||
func (p *orgMetadataProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.MetadataSetType,
|
||||
Reduce: p.reduceMetadataSet,
|
||||
@@ -79,7 +79,7 @@ func (p *orgMetadataProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(OrgMetadataColumnInstanceID),
|
||||
@@ -94,7 +94,7 @@ func (p *orgMetadataProjection) reduceMetadataSet(event eventstore.Event) (*hand
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Ghn53", "reduce.wrong.event.type %s", org.MetadataSetType)
|
||||
}
|
||||
return crdb.NewUpsertStatement(
|
||||
return handler.NewUpsertStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(OrgMetadataColumnInstanceID, nil),
|
||||
@@ -119,7 +119,7 @@ func (p *orgMetadataProjection) reduceMetadataRemoved(event eventstore.Event) (*
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Bm542", "reduce.wrong.event.type %s", org.MetadataRemovedType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(OrgMetadataColumnOrgID, e.Aggregate().ID),
|
||||
@@ -137,7 +137,7 @@ func (p *orgMetadataProjection) reduceMetadataRemovedAll(event eventstore.Event)
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Bmnf3", "reduce.wrong.event.type %v", []eventstore.EventType{org.MetadataRemovedAllType, org.OrgRemovedEventType})
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
event,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(OrgMetadataColumnOrgID, event.Aggregate().ID),
|
||||
@@ -152,7 +152,7 @@ func (p *orgMetadataProjection) reduceOwnerRemoved(event eventstore.Event) (*han
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Hkd1f", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(OrgMetadataColumnChangeDate, e.CreationDate()),
|
||||
|
||||
@@ -5,8 +5,7 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -24,20 +23,20 @@ func TestOrgMetadataProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceMetadataSet",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.MetadataSetType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.MetadataSetType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "key",
|
||||
"value": "dmFsdWU="
|
||||
}`),
|
||||
), org.MetadataSetEventMapper),
|
||||
), org.MetadataSetEventMapper),
|
||||
},
|
||||
reduce: (&orgMetadataProjection{}).reduceMetadataSet,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -60,19 +59,19 @@ func TestOrgMetadataProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceMetadataRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.MetadataRemovedType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.MetadataRemovedType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "key"
|
||||
}`),
|
||||
), org.MetadataRemovedEventMapper),
|
||||
), org.MetadataRemovedEventMapper),
|
||||
},
|
||||
reduce: (&orgMetadataProjection{}).reduceMetadataRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -90,17 +89,17 @@ func TestOrgMetadataProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceMetadataRemovedAll",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.MetadataRemovedAllType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.MetadataRemovedAllEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.MetadataRemovedAllType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.MetadataRemovedAllEventMapper),
|
||||
},
|
||||
reduce: (&orgMetadataProjection{}).reduceMetadataRemovedAll,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -117,17 +116,17 @@ func TestOrgMetadataProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceOwnerRemoved(org removed)",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
reduce: (&orgMetadataProjection{}).reduceOwnerRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -147,17 +146,17 @@ func TestOrgMetadataProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(MemberInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -25,17 +24,17 @@ func TestOrgProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reducePrimaryDomainSet",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgDomainPrimarySetEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"domain": "domain.new"}`),
|
||||
), org.DomainPrimarySetEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgDomainPrimarySetEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"domain": "domain.new"}`),
|
||||
), org.DomainPrimarySetEventMapper),
|
||||
},
|
||||
reduce: (&orgProjection{}).reducePrimaryDomainSet,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -55,17 +54,17 @@ func TestOrgProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceOrgReactivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgReactivatedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgReactivatedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgReactivatedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgReactivatedEventMapper),
|
||||
},
|
||||
reduce: (&orgProjection{}).reduceOrgReactivated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -85,17 +84,17 @@ func TestOrgProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceOrgDeactivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgDeactivatedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgDeactivatedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgDeactivatedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgDeactivatedEventMapper),
|
||||
},
|
||||
reduce: (&orgProjection{}).reduceOrgDeactivated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -115,17 +114,17 @@ func TestOrgProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceOrgChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgChangedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"name": "new name"}`),
|
||||
), org.OrgChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgChangedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"name": "new name"}`),
|
||||
), org.OrgChangedEventMapper),
|
||||
},
|
||||
reduce: (&orgProjection{}).reduceOrgChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -145,34 +144,34 @@ func TestOrgProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceOrgChanged no changes",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgChangedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), org.OrgChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgChangedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), org.OrgChangedEventMapper),
|
||||
},
|
||||
reduce: (&orgProjection{}).reduceOrgChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
executer: &testExecuter{},
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "reduceOrgAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{"name": "name"}`),
|
||||
), org.OrgAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{"name": "name"}`),
|
||||
), org.OrgAddedEventMapper),
|
||||
},
|
||||
reduce: (&orgProjection{}).reduceOrgAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -195,17 +194,17 @@ func TestOrgProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceOrgRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
reduce: (&orgProjection{}).reduceOrgRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -222,17 +221,17 @@ func TestOrgProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(OrgColumnInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
@@ -29,41 +29,42 @@ const (
|
||||
AgePolicyOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type passwordAgeProjection struct {
|
||||
crdb.StatementHandler
|
||||
type passwordAgeProjection struct{}
|
||||
|
||||
func newPasswordAgeProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(passwordAgeProjection))
|
||||
}
|
||||
|
||||
func newPasswordAgeProjection(ctx context.Context, config crdb.StatementHandlerConfig) *passwordAgeProjection {
|
||||
p := new(passwordAgeProjection)
|
||||
config.ProjectionName = PasswordAgeTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(AgePolicyIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AgePolicyCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(AgePolicyChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(AgePolicySequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(AgePolicyStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(AgePolicyIsDefaultCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(AgePolicyResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AgePolicyInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AgePolicyExpireWarnDaysCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(AgePolicyMaxAgeDaysCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(AgePolicyOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*passwordAgeProjection) Name() string {
|
||||
return PasswordAgeTable
|
||||
}
|
||||
|
||||
func (*passwordAgeProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(AgePolicyIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(AgePolicyCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(AgePolicyChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(AgePolicySequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(AgePolicyStateCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(AgePolicyIsDefaultCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(AgePolicyResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(AgePolicyInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(AgePolicyExpireWarnDaysCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(AgePolicyMaxAgeDaysCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(AgePolicyOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(AgePolicyInstanceIDCol, AgePolicyIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{AgePolicyOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(AgePolicyInstanceIDCol, AgePolicyIDCol),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{AgePolicyOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *passwordAgeProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *passwordAgeProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.PasswordAgePolicyAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -84,7 +85,7 @@ func (p *passwordAgeProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.PasswordAgePolicyAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -115,7 +116,7 @@ func (p *passwordAgeProjection) reduceAdded(event eventstore.Event) (*handler.St
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-CJqF0", "reduce.wrong.event.type %v", []eventstore.EventType{org.PasswordAgePolicyAddedEventType, instance.PasswordAgePolicyAddedEventType})
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
&policyEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(AgePolicyCreationDateCol, policyEvent.CreationDate()),
|
||||
@@ -151,7 +152,7 @@ func (p *passwordAgeProjection) reduceChanged(event eventstore.Event) (*handler.
|
||||
if policyEvent.MaxAgeDays != nil {
|
||||
cols = append(cols, handler.NewCol(AgePolicyMaxAgeDaysCol, *policyEvent.MaxAgeDays))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&policyEvent,
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
@@ -165,7 +166,7 @@ func (p *passwordAgeProjection) reduceRemoved(event eventstore.Event) (*handler.
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-EtHWB", "reduce.wrong.event.type %s", org.PasswordAgePolicyRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
policyEvent,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(AgePolicyIDCol, policyEvent.Aggregate().ID),
|
||||
@@ -179,7 +180,7 @@ func (p *passwordAgeProjection) reduceOwnerRemoved(event eventstore.Event) (*han
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-edLs2", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(AgePolicyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -25,20 +24,20 @@ func TestPasswordAgeProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.PasswordAgePolicyAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.PasswordAgePolicyAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"expireWarnDays": 10,
|
||||
"maxAgeDays": 13
|
||||
}`),
|
||||
), org.PasswordAgePolicyAddedEventMapper),
|
||||
), org.PasswordAgePolicyAddedEventMapper),
|
||||
},
|
||||
reduce: (&passwordAgeProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -64,19 +63,19 @@ func TestPasswordAgeProjection_reduces(t *testing.T) {
|
||||
name: "org reduceChanged",
|
||||
reduce: (&passwordAgeProjection{}).reduceChanged,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.PasswordAgePolicyChangedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.PasswordAgePolicyChangedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"expireWarnDays": 10,
|
||||
"maxAgeDays": 13
|
||||
}`),
|
||||
), org.PasswordAgePolicyChangedEventMapper),
|
||||
), org.PasswordAgePolicyChangedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -98,16 +97,16 @@ func TestPasswordAgeProjection_reduces(t *testing.T) {
|
||||
name: "org reduceRemoved",
|
||||
reduce: (&passwordAgeProjection{}).reduceRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.PasswordAgePolicyRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.PasswordAgePolicyRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.PasswordAgePolicyRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.PasswordAgePolicyRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -124,17 +123,17 @@ func TestPasswordAgeProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(AgePolicyInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -151,19 +150,19 @@ func TestPasswordAgeProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceAdded",
|
||||
reduce: (&passwordAgeProjection{}).reduceAdded,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.PasswordAgePolicyAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.PasswordAgePolicyAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"expireWarnDays": 10,
|
||||
"maxAgeDays": 13
|
||||
}`),
|
||||
), instance.PasswordAgePolicyAddedEventMapper),
|
||||
), instance.PasswordAgePolicyAddedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -189,19 +188,19 @@ func TestPasswordAgeProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceChanged",
|
||||
reduce: (&passwordAgeProjection{}).reduceChanged,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.PasswordAgePolicyChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.PasswordAgePolicyChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"expireWarnDays": 10,
|
||||
"maxAgeDays": 13
|
||||
}`),
|
||||
), instance.PasswordAgePolicyChangedEventMapper),
|
||||
), instance.PasswordAgePolicyChangedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -223,16 +222,16 @@ func TestPasswordAgeProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (&passwordAgeProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
@@ -32,44 +32,45 @@ const (
|
||||
ComplexityPolicyOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type passwordComplexityProjection struct {
|
||||
crdb.StatementHandler
|
||||
type passwordComplexityProjection struct{}
|
||||
|
||||
func newPasswordComplexityProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(passwordComplexityProjection))
|
||||
}
|
||||
|
||||
func newPasswordComplexityProjection(ctx context.Context, config crdb.StatementHandlerConfig) *passwordComplexityProjection {
|
||||
p := new(passwordComplexityProjection)
|
||||
config.ProjectionName = PasswordComplexityTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(ComplexityPolicyIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ComplexityPolicyCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(ComplexityPolicyChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(ComplexityPolicySequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(ComplexityPolicyStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(ComplexityPolicyIsDefaultCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(ComplexityPolicyResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ComplexityPolicyInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ComplexityPolicyMinLengthCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(ComplexityPolicyHasLowercaseCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(ComplexityPolicyHasUppercaseCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(ComplexityPolicyHasSymbolCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(ComplexityPolicyHasNumberCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(ComplexityPolicyOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*passwordComplexityProjection) Name() string {
|
||||
return PasswordComplexityTable
|
||||
}
|
||||
|
||||
func (*passwordComplexityProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(ComplexityPolicyIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(ComplexityPolicyCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(ComplexityPolicyChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(ComplexityPolicySequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(ComplexityPolicyStateCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(ComplexityPolicyIsDefaultCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(ComplexityPolicyResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(ComplexityPolicyInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(ComplexityPolicyMinLengthCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(ComplexityPolicyHasLowercaseCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(ComplexityPolicyHasUppercaseCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(ComplexityPolicyHasSymbolCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(ComplexityPolicyHasNumberCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(ComplexityPolicyOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(ComplexityPolicyInstanceIDCol, ComplexityPolicyIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{ComplexityPolicyOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(ComplexityPolicyInstanceIDCol, ComplexityPolicyIDCol),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{ComplexityPolicyOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *passwordComplexityProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *passwordComplexityProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.PasswordComplexityPolicyAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -90,7 +91,7 @@ func (p *passwordComplexityProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.PasswordComplexityPolicyAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -121,7 +122,7 @@ func (p *passwordComplexityProjection) reduceAdded(event eventstore.Event) (*han
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-KTHmJ", "reduce.wrong.event.type %v", []eventstore.EventType{org.PasswordComplexityPolicyAddedEventType, instance.PasswordComplexityPolicyAddedEventType})
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
&policyEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(ComplexityPolicyCreationDateCol, policyEvent.CreationDate()),
|
||||
@@ -169,7 +170,7 @@ func (p *passwordComplexityProjection) reduceChanged(event eventstore.Event) (*h
|
||||
if policyEvent.HasNumber != nil {
|
||||
cols = append(cols, handler.NewCol(ComplexityPolicyHasNumberCol, *policyEvent.HasNumber))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&policyEvent,
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
@@ -183,7 +184,7 @@ func (p *passwordComplexityProjection) reduceRemoved(event eventstore.Event) (*h
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-wttCd", "reduce.wrong.event.type %s", org.PasswordComplexityPolicyRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
policyEvent,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ComplexityPolicyIDCol, policyEvent.Aggregate().ID),
|
||||
@@ -197,7 +198,7 @@ func (p *passwordComplexityProjection) reduceOwnerRemoved(event eventstore.Event
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-pGTz9", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ComplexityPolicyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -25,23 +24,23 @@ func TestPasswordComplexityProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.PasswordComplexityPolicyAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.PasswordComplexityPolicyAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"minLength": 10,
|
||||
"hasLowercase": true,
|
||||
"hasUppercase": true,
|
||||
"HasNumber": true,
|
||||
"HasSymbol": true
|
||||
}`),
|
||||
), org.PasswordComplexityPolicyAddedEventMapper),
|
||||
), org.PasswordComplexityPolicyAddedEventMapper),
|
||||
},
|
||||
reduce: (&passwordComplexityProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -70,22 +69,22 @@ func TestPasswordComplexityProjection_reduces(t *testing.T) {
|
||||
name: "org reduceChanged",
|
||||
reduce: (&passwordComplexityProjection{}).reduceChanged,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.PasswordComplexityPolicyChangedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.PasswordComplexityPolicyChangedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"minLength": 11,
|
||||
"hasLowercase": true,
|
||||
"hasUppercase": true,
|
||||
"HasNumber": true,
|
||||
"HasSymbol": true
|
||||
}`),
|
||||
), org.PasswordComplexityPolicyChangedEventMapper),
|
||||
), org.PasswordComplexityPolicyChangedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -110,16 +109,16 @@ func TestPasswordComplexityProjection_reduces(t *testing.T) {
|
||||
name: "org reduceRemoved",
|
||||
reduce: (&passwordComplexityProjection{}).reduceRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.PasswordComplexityPolicyRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.PasswordComplexityPolicyRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.PasswordComplexityPolicyRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.PasswordComplexityPolicyRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -136,17 +135,17 @@ func TestPasswordComplexityProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(ComplexityPolicyInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -163,22 +162,22 @@ func TestPasswordComplexityProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceAdded",
|
||||
reduce: (&passwordComplexityProjection{}).reduceAdded,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.PasswordComplexityPolicyAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.PasswordComplexityPolicyAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"minLength": 10,
|
||||
"hasLowercase": true,
|
||||
"hasUppercase": true,
|
||||
"HasNumber": true,
|
||||
"HasSymbol": true
|
||||
}`),
|
||||
), instance.PasswordComplexityPolicyAddedEventMapper),
|
||||
), instance.PasswordComplexityPolicyAddedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -207,22 +206,22 @@ func TestPasswordComplexityProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceChanged",
|
||||
reduce: (&passwordComplexityProjection{}).reduceChanged,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.PasswordComplexityPolicyChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.PasswordComplexityPolicyChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"minLength": 10,
|
||||
"hasLowercase": true,
|
||||
"hasUppercase": true,
|
||||
"HasNumber": true,
|
||||
"HasSymbol": true
|
||||
}`),
|
||||
), instance.PasswordComplexityPolicyChangedEventMapper),
|
||||
), instance.PasswordComplexityPolicyChangedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -247,16 +246,16 @@ func TestPasswordComplexityProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (&passwordComplexityProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
@@ -31,43 +31,44 @@ const (
|
||||
PrivacyPolicyOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type privacyPolicyProjection struct {
|
||||
crdb.StatementHandler
|
||||
type privacyPolicyProjection struct{}
|
||||
|
||||
func newPrivacyPolicyProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(privacyPolicyProjection))
|
||||
}
|
||||
|
||||
func newPrivacyPolicyProjection(ctx context.Context, config crdb.StatementHandlerConfig) *privacyPolicyProjection {
|
||||
p := new(privacyPolicyProjection)
|
||||
config.ProjectionName = PrivacyPolicyTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(PrivacyPolicyIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(PrivacyPolicyCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(PrivacyPolicyChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(PrivacyPolicySequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(PrivacyPolicyStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(PrivacyPolicyIsDefaultCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(PrivacyPolicyResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(PrivacyPolicyInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(PrivacyPolicyPrivacyLinkCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(PrivacyPolicyTOSLinkCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(PrivacyPolicyHelpLinkCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(PrivacyPolicySupportEmailCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(PrivacyPolicyOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*privacyPolicyProjection) Name() string {
|
||||
return PrivacyPolicyTable
|
||||
}
|
||||
|
||||
func (*privacyPolicyProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(PrivacyPolicyIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(PrivacyPolicyCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(PrivacyPolicyChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(PrivacyPolicySequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(PrivacyPolicyStateCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(PrivacyPolicyIsDefaultCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(PrivacyPolicyResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(PrivacyPolicyInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(PrivacyPolicyPrivacyLinkCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(PrivacyPolicyTOSLinkCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(PrivacyPolicyHelpLinkCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(PrivacyPolicySupportEmailCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(PrivacyPolicyOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(PrivacyPolicyInstanceIDCol, PrivacyPolicyIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{PrivacyPolicyOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(PrivacyPolicyInstanceIDCol, PrivacyPolicyIDCol),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{PrivacyPolicyOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *privacyPolicyProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *privacyPolicyProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.PrivacyPolicyAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -88,7 +89,7 @@ func (p *privacyPolicyProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.PrivacyPolicyAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -119,7 +120,7 @@ func (p *privacyPolicyProjection) reduceAdded(event eventstore.Event) (*handler.
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-kRNh8", "reduce.wrong.event.type %v", []eventstore.EventType{org.PrivacyPolicyAddedEventType, instance.PrivacyPolicyAddedEventType})
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
&policyEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(PrivacyPolicyCreationDateCol, policyEvent.CreationDate()),
|
||||
@@ -163,7 +164,7 @@ func (p *privacyPolicyProjection) reduceChanged(event eventstore.Event) (*handle
|
||||
if policyEvent.SupportEmail != nil {
|
||||
cols = append(cols, handler.NewCol(PrivacyPolicySupportEmailCol, *policyEvent.SupportEmail))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&policyEvent,
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
@@ -177,7 +178,7 @@ func (p *privacyPolicyProjection) reduceRemoved(event eventstore.Event) (*handle
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-FvtGO", "reduce.wrong.event.type %s", org.PrivacyPolicyRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
policyEvent,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(PrivacyPolicyIDCol, policyEvent.Aggregate().ID),
|
||||
@@ -191,7 +192,7 @@ func (p *privacyPolicyProjection) reduceOwnerRemoved(event eventstore.Event) (*h
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-bxJCY", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(PrivacyPolicyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
@@ -25,21 +24,21 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org reduceAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.PrivacyPolicyAddedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.PrivacyPolicyAddedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"tosLink": "http://tos.link",
|
||||
"privacyLink": "http://privacy.link",
|
||||
"helpLink": "http://help.link",
|
||||
"supportEmail": "[email protected]"}`),
|
||||
), org.PrivacyPolicyAddedEventMapper),
|
||||
), org.PrivacyPolicyAddedEventMapper),
|
||||
},
|
||||
reduce: (&privacyPolicyProjection{}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -67,20 +66,20 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org reduceChanged",
|
||||
reduce: (&privacyPolicyProjection{}).reduceChanged,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.PrivacyPolicyChangedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.PrivacyPolicyChangedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{
|
||||
"tosLink": "http://tos.link",
|
||||
"privacyLink": "http://privacy.link",
|
||||
"helpLink": "http://help.link",
|
||||
"supportEmail": "[email protected]"}`),
|
||||
), org.PrivacyPolicyChangedEventMapper),
|
||||
), org.PrivacyPolicyChangedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -104,16 +103,16 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org reduceRemoved",
|
||||
reduce: (&privacyPolicyProjection{}).reduceRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.PrivacyPolicyRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.PrivacyPolicyRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.PrivacyPolicyRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.PrivacyPolicyRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -129,17 +128,17 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
|
||||
}, {
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(PrivacyPolicyInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -156,20 +155,20 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceAdded",
|
||||
reduce: (&privacyPolicyProjection{}).reduceAdded,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.PrivacyPolicyAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.PrivacyPolicyAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"tosLink": "http://tos.link",
|
||||
"privacyLink": "http://privacy.link",
|
||||
"helpLink": "http://help.link",
|
||||
"supportEmail": "[email protected]"}`),
|
||||
), instance.PrivacyPolicyAddedEventMapper),
|
||||
), instance.PrivacyPolicyAddedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -197,20 +196,20 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
|
||||
name: "instance reduceChanged",
|
||||
reduce: (&privacyPolicyProjection{}).reduceChanged,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.PrivacyPolicyChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.PrivacyPolicyChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"tosLink": "http://tos.link",
|
||||
"privacyLink": "http://privacy.link",
|
||||
"helpLink": "http://help.link",
|
||||
"supportEmail": "[email protected]"}`),
|
||||
), instance.PrivacyPolicyChangedEventMapper),
|
||||
), instance.PrivacyPolicyChangedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -234,16 +233,16 @@ func TestPrivacyPolicyProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (&privacyPolicyProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/project"
|
||||
@@ -31,44 +31,45 @@ const (
|
||||
ProjectColumnOwnerRemoved = "owner_removed"
|
||||
)
|
||||
|
||||
type projectProjection struct {
|
||||
crdb.StatementHandler
|
||||
type projectProjection struct{}
|
||||
|
||||
func newProjectProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(projectProjection))
|
||||
}
|
||||
|
||||
func newProjectProjection(ctx context.Context, config crdb.StatementHandlerConfig) *projectProjection {
|
||||
p := new(projectProjection)
|
||||
config.ProjectionName = ProjectProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(ProjectColumnID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ProjectColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(ProjectColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(ProjectColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(ProjectColumnState, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(ProjectColumnResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ProjectColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ProjectColumnName, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ProjectColumnProjectRoleAssertion, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(ProjectColumnProjectRoleCheck, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(ProjectColumnHasProjectCheck, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(ProjectColumnPrivateLabelingSetting, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(ProjectColumnOwnerRemoved, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*projectProjection) Name() string {
|
||||
return ProjectProjectionTable
|
||||
}
|
||||
|
||||
func (*projectProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(ProjectColumnID, handler.ColumnTypeText),
|
||||
handler.NewColumn(ProjectColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(ProjectColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(ProjectColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(ProjectColumnState, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(ProjectColumnResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(ProjectColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(ProjectColumnName, handler.ColumnTypeText),
|
||||
handler.NewColumn(ProjectColumnProjectRoleAssertion, handler.ColumnTypeBool),
|
||||
handler.NewColumn(ProjectColumnProjectRoleCheck, handler.ColumnTypeBool),
|
||||
handler.NewColumn(ProjectColumnHasProjectCheck, handler.ColumnTypeBool),
|
||||
handler.NewColumn(ProjectColumnPrivateLabelingSetting, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(ProjectColumnOwnerRemoved, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(ProjectColumnInstanceID, ProjectColumnID),
|
||||
crdb.WithIndex(crdb.NewIndex("resource_owner", []string{ProjectColumnResourceOwner})),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{ProjectColumnOwnerRemoved})),
|
||||
handler.NewPrimaryKey(ProjectColumnInstanceID, ProjectColumnID),
|
||||
handler.WithIndex(handler.NewIndex("resource_owner", []string{ProjectColumnResourceOwner})),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{ProjectColumnOwnerRemoved})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *projectProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *projectProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: project.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: project.ProjectAddedType,
|
||||
Reduce: p.reduceProjectAdded,
|
||||
@@ -93,7 +94,7 @@ func (p *projectProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.OrgRemovedEventType,
|
||||
Reduce: p.reduceOwnerRemoved,
|
||||
@@ -102,7 +103,7 @@ func (p *projectProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(ProjectColumnInstanceID),
|
||||
@@ -117,7 +118,7 @@ func (p *projectProjection) reduceProjectAdded(event eventstore.Event) (*handler
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-l000S", "reduce.wrong.event.type %s", project.ProjectAddedType)
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(ProjectColumnID, e.Aggregate().ID),
|
||||
@@ -142,7 +143,7 @@ func (p *projectProjection) reduceProjectChanged(event eventstore.Event) (*handl
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-s00Fs", "reduce.wrong.event.type %s", project.ProjectChangedType)
|
||||
}
|
||||
if e.Name == nil && e.HasProjectCheck == nil && e.ProjectRoleAssertion == nil && e.ProjectRoleCheck == nil && e.PrivateLabelingSetting == nil {
|
||||
return crdb.NewNoOpStatement(e), nil
|
||||
return handler.NewNoOpStatement(e), nil
|
||||
}
|
||||
|
||||
columns := make([]handler.Column, 0, 7)
|
||||
@@ -163,7 +164,7 @@ func (p *projectProjection) reduceProjectChanged(event eventstore.Event) (*handl
|
||||
if e.PrivateLabelingSetting != nil {
|
||||
columns = append(columns, handler.NewCol(ProjectColumnPrivateLabelingSetting, *e.PrivateLabelingSetting))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
columns,
|
||||
[]handler.Condition{
|
||||
@@ -178,7 +179,7 @@ func (p *projectProjection) reduceProjectDeactivated(event eventstore.Event) (*h
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-LLp0f", "reduce.wrong.event.type %s", project.ProjectDeactivatedType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(ProjectColumnChangeDate, e.CreationDate()),
|
||||
@@ -197,7 +198,7 @@ func (p *projectProjection) reduceProjectReactivated(event eventstore.Event) (*h
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-9J98f", "reduce.wrong.event.type %s", project.ProjectReactivatedType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(ProjectColumnChangeDate, e.CreationDate()),
|
||||
@@ -216,7 +217,7 @@ func (p *projectProjection) reduceProjectRemoved(event eventstore.Event) (*handl
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-5N9fs", "reduce.wrong.event.type %s", project.ProjectRemovedType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ProjectColumnID, e.Aggregate().ID),
|
||||
@@ -231,7 +232,7 @@ func (p *projectProjection) reduceOwnerRemoved(event eventstore.Event) (*handler
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-sbgru", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ProjectColumnInstanceID, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/project"
|
||||
@@ -31,45 +31,46 @@ const (
|
||||
ProjectGrantColumnGrantedOrgRemoved = "granted_org_removed"
|
||||
)
|
||||
|
||||
type projectGrantProjection struct {
|
||||
crdb.StatementHandler
|
||||
type projectGrantProjection struct{}
|
||||
|
||||
func newProjectGrantProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(projectGrantProjection))
|
||||
}
|
||||
|
||||
func newProjectGrantProjection(ctx context.Context, config crdb.StatementHandlerConfig) *projectGrantProjection {
|
||||
p := new(projectGrantProjection)
|
||||
config.ProjectionName = ProjectGrantProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(ProjectGrantColumnGrantID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ProjectGrantColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(ProjectGrantColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(ProjectGrantColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(ProjectGrantColumnState, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(ProjectGrantColumnResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ProjectGrantColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ProjectGrantColumnProjectID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ProjectGrantColumnGrantedOrgID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ProjectGrantColumnRoleKeys, crdb.ColumnTypeTextArray, crdb.Nullable()),
|
||||
crdb.NewColumn(ProjectGrantColumnOwnerRemoved, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(ProjectGrantColumnGrantedOrgRemoved, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*projectGrantProjection) Name() string {
|
||||
return ProjectGrantProjectionTable
|
||||
}
|
||||
|
||||
func (*projectGrantProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(ProjectGrantColumnGrantID, handler.ColumnTypeText),
|
||||
handler.NewColumn(ProjectGrantColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(ProjectGrantColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(ProjectGrantColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(ProjectGrantColumnState, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(ProjectGrantColumnResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(ProjectGrantColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(ProjectGrantColumnProjectID, handler.ColumnTypeText),
|
||||
handler.NewColumn(ProjectGrantColumnGrantedOrgID, handler.ColumnTypeText),
|
||||
handler.NewColumn(ProjectGrantColumnRoleKeys, handler.ColumnTypeTextArray, handler.Nullable()),
|
||||
handler.NewColumn(ProjectGrantColumnOwnerRemoved, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(ProjectGrantColumnGrantedOrgRemoved, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(ProjectGrantColumnInstanceID, ProjectGrantColumnGrantID),
|
||||
crdb.WithIndex(crdb.NewIndex("resource_owner", []string{ProjectGrantColumnResourceOwner})),
|
||||
crdb.WithIndex(crdb.NewIndex("granted_org", []string{ProjectGrantColumnGrantedOrgID})),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{ProjectGrantColumnOwnerRemoved})),
|
||||
crdb.WithIndex(crdb.NewIndex("granted_org_removed", []string{ProjectGrantColumnGrantedOrgRemoved})),
|
||||
handler.NewPrimaryKey(ProjectGrantColumnInstanceID, ProjectGrantColumnGrantID),
|
||||
handler.WithIndex(handler.NewIndex("resource_owner", []string{ProjectGrantColumnResourceOwner})),
|
||||
handler.WithIndex(handler.NewIndex("granted_org", []string{ProjectGrantColumnGrantedOrgID})),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{ProjectGrantColumnOwnerRemoved})),
|
||||
handler.WithIndex(handler.NewIndex("granted_org_removed", []string{ProjectGrantColumnGrantedOrgRemoved})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *projectGrantProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *projectGrantProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: project.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: project.GrantAddedType,
|
||||
Reduce: p.reduceProjectGrantAdded,
|
||||
@@ -102,7 +103,7 @@ func (p *projectGrantProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.OrgRemovedEventType,
|
||||
Reduce: p.reduceOwnerRemoved,
|
||||
@@ -111,7 +112,7 @@ func (p *projectGrantProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(ProjectGrantColumnInstanceID),
|
||||
@@ -126,7 +127,7 @@ func (p *projectGrantProjection) reduceProjectGrantAdded(event eventstore.Event)
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-g92Fg", "reduce.wrong.event.type %s", project.GrantAddedType)
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(ProjectGrantColumnGrantID, e.GrantID),
|
||||
@@ -138,7 +139,7 @@ func (p *projectGrantProjection) reduceProjectGrantAdded(event eventstore.Event)
|
||||
handler.NewCol(ProjectGrantColumnState, domain.ProjectGrantStateActive),
|
||||
handler.NewCol(ProjectGrantColumnSequence, e.Sequence()),
|
||||
handler.NewCol(ProjectGrantColumnGrantedOrgID, e.GrantedOrgID),
|
||||
handler.NewCol(ProjectGrantColumnRoleKeys, database.StringArray(e.RoleKeys)),
|
||||
handler.NewCol(ProjectGrantColumnRoleKeys, database.TextArray[string](e.RoleKeys)),
|
||||
},
|
||||
), nil
|
||||
}
|
||||
@@ -148,12 +149,12 @@ func (p *projectGrantProjection) reduceProjectGrantChanged(event eventstore.Even
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-g0fg4", "reduce.wrong.event.type %s", project.GrantChangedType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(ProjectColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(ProjectGrantColumnSequence, e.Sequence()),
|
||||
handler.NewCol(ProjectGrantColumnRoleKeys, database.StringArray(e.RoleKeys)),
|
||||
handler.NewCol(ProjectGrantColumnRoleKeys, database.TextArray[string](e.RoleKeys)),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ProjectGrantColumnGrantID, e.GrantID),
|
||||
@@ -168,12 +169,12 @@ func (p *projectGrantProjection) reduceProjectGrantCascadeChanged(event eventsto
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ll9Ts", "reduce.wrong.event.type %s", project.GrantCascadeChangedType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(ProjectGrantColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(ProjectGrantColumnSequence, e.Sequence()),
|
||||
handler.NewCol(ProjectGrantColumnRoleKeys, database.StringArray(e.RoleKeys)),
|
||||
handler.NewCol(ProjectGrantColumnRoleKeys, database.TextArray[string](e.RoleKeys)),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ProjectGrantColumnGrantID, e.GrantID),
|
||||
@@ -188,7 +189,7 @@ func (p *projectGrantProjection) reduceProjectGrantDeactivated(event eventstore.
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-0fj2f", "reduce.wrong.event.type %s", project.GrantDeactivatedType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(ProjectGrantColumnChangeDate, e.CreationDate()),
|
||||
@@ -208,7 +209,7 @@ func (p *projectGrantProjection) reduceProjectGrantReactivated(event eventstore.
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-2M0ve", "reduce.wrong.event.type %s", project.GrantReactivatedType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(ProjectGrantColumnChangeDate, e.CreationDate()),
|
||||
@@ -228,7 +229,7 @@ func (p *projectGrantProjection) reduceProjectGrantRemoved(event eventstore.Even
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-o0w4f", "reduce.wrong.event.type %s", project.GrantRemovedType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ProjectGrantColumnGrantID, e.GrantID),
|
||||
@@ -243,7 +244,7 @@ func (p *projectGrantProjection) reduceProjectRemoved(event eventstore.Event) (*
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-gn9rw", "reduce.wrong.event.type %s", project.ProjectRemovedType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ProjectGrantColumnProjectID, e.Aggregate().ID),
|
||||
@@ -258,15 +259,15 @@ func (p *projectGrantProjection) reduceOwnerRemoved(event eventstore.Event) (*ha
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-HDgW3", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ProjectGrantColumnInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCond(ProjectGrantColumnResourceOwner, e.Aggregate().ID),
|
||||
},
|
||||
),
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ProjectGrantColumnInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCond(ProjectGrantColumnGrantedOrgID, e.Aggregate().ID),
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/member"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
@@ -23,38 +23,54 @@ const (
|
||||
)
|
||||
|
||||
type projectGrantMemberProjection struct {
|
||||
crdb.StatementHandler
|
||||
es handler.EventStore
|
||||
}
|
||||
|
||||
func newProjectGrantMemberProjection(ctx context.Context, config crdb.StatementHandlerConfig) *projectGrantMemberProjection {
|
||||
p := new(projectGrantMemberProjection)
|
||||
config.ProjectionName = ProjectGrantMemberProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable(
|
||||
func newProjectGrantMemberProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, &projectGrantMemberProjection{es: config.Eventstore})
|
||||
}
|
||||
|
||||
func (*projectGrantMemberProjection) Name() string {
|
||||
return ProjectGrantMemberProjectionTable
|
||||
}
|
||||
|
||||
func (*projectGrantMemberProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable(
|
||||
append(memberColumns,
|
||||
crdb.NewColumn(ProjectGrantMemberProjectIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ProjectGrantMemberGrantIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ProjectGrantMemberGrantedOrg, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ProjectGrantMemberGrantedOrgRemoved, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
handler.NewColumn(ProjectGrantMemberProjectIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(ProjectGrantMemberGrantIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(ProjectGrantMemberGrantedOrg, handler.ColumnTypeText),
|
||||
handler.NewColumn(ProjectGrantMemberGrantedOrgRemoved, handler.ColumnTypeBool, handler.Default(false)),
|
||||
),
|
||||
handler.NewPrimaryKey(MemberInstanceID, ProjectGrantMemberProjectIDCol, ProjectGrantMemberGrantIDCol, MemberUserIDCol),
|
||||
handler.WithIndex(handler.NewIndex("user_id", []string{MemberUserIDCol})),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{MemberOwnerRemoved})),
|
||||
handler.WithIndex(handler.NewIndex("user_owner_removed", []string{MemberUserOwnerRemoved})),
|
||||
handler.WithIndex(handler.NewIndex("granted_org_removed", []string{ProjectGrantMemberGrantedOrgRemoved})),
|
||||
handler.WithIndex(
|
||||
handler.NewIndex("pgm_instance", []string{MemberInstanceID},
|
||||
handler.WithInclude(
|
||||
MemberCreationDate,
|
||||
MemberChangeDate,
|
||||
MemberUserOwnerRemoved,
|
||||
MemberRolesCol,
|
||||
MemberSequence,
|
||||
MemberResourceOwner,
|
||||
MemberOwnerRemoved,
|
||||
ProjectGrantMemberGrantedOrgRemoved,
|
||||
),
|
||||
),
|
||||
),
|
||||
crdb.NewPrimaryKey(MemberInstanceID, ProjectGrantMemberProjectIDCol, ProjectGrantMemberGrantIDCol, MemberUserIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("user_id", []string{MemberUserIDCol})),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{MemberOwnerRemoved})),
|
||||
crdb.WithIndex(crdb.NewIndex("user_owner_removed", []string{MemberUserOwnerRemoved})),
|
||||
crdb.WithIndex(crdb.NewIndex("granted_org_removed", []string{ProjectGrantMemberGrantedOrgRemoved})),
|
||||
),
|
||||
)
|
||||
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *projectGrantMemberProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *projectGrantMemberProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: project.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: project.GrantMemberAddedType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -83,7 +99,7 @@ func (p *projectGrantMemberProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: user.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: user.UserRemovedType,
|
||||
Reduce: p.reduceUserRemoved,
|
||||
@@ -92,7 +108,7 @@ func (p *projectGrantMemberProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.OrgRemovedEventType,
|
||||
Reduce: p.reduceOrgRemoved,
|
||||
@@ -101,7 +117,7 @@ func (p *projectGrantMemberProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(MemberInstanceID),
|
||||
@@ -117,11 +133,11 @@ func (p *projectGrantMemberProjection) reduceAdded(event eventstore.Event) (*han
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-0EBQf", "reduce.wrong.event.type %s", project.GrantMemberAddedType)
|
||||
}
|
||||
ctx := setMemberContext(e.Aggregate())
|
||||
userOwner, err := getResourceOwnerOfUser(ctx, p.Eventstore, e.Aggregate().InstanceID, e.UserID)
|
||||
userOwner, err := getResourceOwnerOfUser(ctx, p.es, e.Aggregate().InstanceID, e.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
grantedOrg, err := getGrantedOrgOfGrantedProject(ctx, p.Eventstore, e.Aggregate().InstanceID, e.Aggregate().ID, e.GrantID)
|
||||
grantedOrg, err := getGrantedOrgOfGrantedProject(ctx, p.es, e.Aggregate().InstanceID, e.Aggregate().ID, e.GrantID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -192,11 +208,11 @@ func (p *projectGrantMemberProjection) reduceOrgRemoved(event eventstore.Event)
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Zzp6o", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
multiReduceMemberOwnerRemoved(e),
|
||||
multiReduceMemberUserOwnerRemoved(e),
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ProjectGrantColumnInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCond(ProjectGrantMemberGrantedOrg, e.Aggregate().ID),
|
||||
|
||||
@@ -10,8 +10,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/project"
|
||||
@@ -31,39 +30,45 @@ func TestProjectGrantMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project GrantMemberAddedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.GrantMemberAddedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.GrantMemberAddedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"userId": "user-id",
|
||||
"roles": ["role"],
|
||||
"grantId": "grant-id"
|
||||
}`),
|
||||
), project.GrantMemberAddedEventMapper),
|
||||
), project.GrantMemberAddedEventMapper),
|
||||
},
|
||||
reduce: (&projectGrantMemberProjection{
|
||||
StatementHandler: getStatementHandlerWithFilters(
|
||||
user.NewHumanAddedEvent(context.Background(),
|
||||
&user.NewAggregate("user-id", "org1").Aggregate,
|
||||
"username1",
|
||||
"firstname1",
|
||||
"lastname1",
|
||||
"nickname1",
|
||||
"displayname1",
|
||||
language.German,
|
||||
domain.GenderMale,
|
||||
"email1",
|
||||
true,
|
||||
),
|
||||
project.NewGrantAddedEvent(context.Background(),
|
||||
&project.NewAggregate("project1", "org2").Aggregate,
|
||||
"grant", "org3", []string{},
|
||||
),
|
||||
)(t)}).reduceAdded,
|
||||
es: newMockEventStore().appendFilterResponse(
|
||||
[]eventstore.Event{
|
||||
user.NewHumanAddedEvent(context.Background(),
|
||||
&user.NewAggregate("user-id", "org1").Aggregate,
|
||||
"username1",
|
||||
"firstname1",
|
||||
"lastname1",
|
||||
"nickname1",
|
||||
"displayname1",
|
||||
language.German,
|
||||
domain.GenderMale,
|
||||
"email1",
|
||||
true,
|
||||
),
|
||||
},
|
||||
).appendFilterResponse(
|
||||
[]eventstore.Event{
|
||||
project.NewGrantAddedEvent(context.Background(),
|
||||
&project.NewAggregate("project1", "org2").Aggregate,
|
||||
"grant", "org3", []string{},
|
||||
),
|
||||
},
|
||||
),
|
||||
}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -72,7 +77,7 @@ func TestProjectGrantMemberProjection_reduces(t *testing.T) {
|
||||
"user-id",
|
||||
"org1",
|
||||
false,
|
||||
database.StringArray{"role"},
|
||||
database.TextArray[string]{"role"},
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -92,27 +97,27 @@ func TestProjectGrantMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project GrantMemberChangedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.GrantMemberChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.GrantMemberChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"userId": "user-id",
|
||||
"roles": ["role", "changed"],
|
||||
"grantId": "grant-id"
|
||||
}`),
|
||||
), project.GrantMemberChangedEventMapper),
|
||||
), project.GrantMemberChangedEventMapper),
|
||||
},
|
||||
reduce: (&projectGrantMemberProjection{}).reduceChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.project_grant_members3 SET (roles, change_date, sequence) = ($1, $2, $3) WHERE (instance_id = $4) AND (user_id = $5) AND (project_id = $6) AND (grant_id = $7)",
|
||||
expectedArgs: []interface{}{
|
||||
database.StringArray{"role", "changed"},
|
||||
database.TextArray[string]{"role", "changed"},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"instance-id",
|
||||
@@ -128,20 +133,20 @@ func TestProjectGrantMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project GrantMemberCascadeRemovedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.GrantMemberCascadeRemovedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.GrantMemberCascadeRemovedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"userId": "user-id",
|
||||
"grantId": "grant-id"
|
||||
}`),
|
||||
), project.GrantMemberCascadeRemovedEventMapper),
|
||||
), project.GrantMemberCascadeRemovedEventMapper),
|
||||
},
|
||||
reduce: (&projectGrantMemberProjection{}).reduceCascadeRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -160,20 +165,20 @@ func TestProjectGrantMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project GrantMemberRemovedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.GrantMemberRemovedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.GrantMemberRemovedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"userId": "user-id",
|
||||
"grantId": "grant-id"
|
||||
}`),
|
||||
), project.GrantMemberRemovedEventMapper),
|
||||
), project.GrantMemberRemovedEventMapper),
|
||||
},
|
||||
reduce: (&projectGrantMemberProjection{}).reduceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -192,17 +197,17 @@ func TestProjectGrantMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "user UserRemovedEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.UserRemovedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), user.UserRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.UserRemovedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), user.UserRemovedEventMapper),
|
||||
},
|
||||
reduce: (&projectGrantMemberProjection{}).reduceUserRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -219,17 +224,17 @@ func TestProjectGrantMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project ProjectRemovedEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ProjectRemovedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), project.ProjectRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ProjectRemovedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), project.ProjectRemovedEventMapper),
|
||||
},
|
||||
reduce: (&projectGrantMemberProjection{}).reduceProjectRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -245,17 +250,17 @@ func TestProjectGrantMemberProjection_reduces(t *testing.T) {
|
||||
}, {
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(MemberInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -271,17 +276,17 @@ func TestProjectGrantMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project GrantRemovedEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.GrantRemovedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grant-id"}`),
|
||||
), project.GrantRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.GrantRemovedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grant-id"}`),
|
||||
), project.GrantRemovedEventMapper),
|
||||
},
|
||||
reduce: (&projectGrantMemberProjection{}).reduceProjectGrantRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -299,17 +304,17 @@ func TestProjectGrantMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org OrgRemovedEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
reduce: (&projectGrantMemberProjection{}).reduceOrgRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -7,8 +7,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/project"
|
||||
@@ -27,17 +26,17 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ProjectRemovedType),
|
||||
project.AggregateType,
|
||||
nil,
|
||||
), project.ProjectRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ProjectRemovedType,
|
||||
project.AggregateType,
|
||||
nil,
|
||||
), project.ProjectRemovedEventMapper),
|
||||
},
|
||||
reduce: (&projectGrantProjection{}).reduceProjectRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -54,17 +53,17 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(ProjectGrantColumnInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -80,17 +79,17 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectGrantRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.GrantRemovedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grant-id"}`),
|
||||
), project.GrantRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.GrantRemovedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grant-id"}`),
|
||||
), project.GrantRemovedEventMapper),
|
||||
},
|
||||
reduce: (&projectGrantProjection{}).reduceProjectGrantRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -108,17 +107,17 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectGrantReactivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.GrantReactivatedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grant-id"}`),
|
||||
), project.GrantReactivatedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.GrantReactivatedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grant-id"}`),
|
||||
), project.GrantReactivatedEventMapper),
|
||||
},
|
||||
reduce: (&projectGrantProjection{}).reduceProjectGrantReactivated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -139,17 +138,17 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectGrantDeactivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.GrantDeactivatedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grant-id"}`),
|
||||
), project.GrantDeactivateEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.GrantDeactivatedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grant-id"}`),
|
||||
), project.GrantDeactivateEventMapper),
|
||||
},
|
||||
reduce: (&projectGrantProjection{}).reduceProjectGrantDeactivated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -170,17 +169,17 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectGrantChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.GrantChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grant-id", "roleKeys": ["admin", "user"] }`),
|
||||
), project.GrantChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.GrantChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grant-id", "roleKeys": ["admin", "user"] }`),
|
||||
), project.GrantChangedEventMapper),
|
||||
},
|
||||
reduce: (&projectGrantProjection{}).reduceProjectGrantChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -188,7 +187,7 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
database.StringArray{"admin", "user"},
|
||||
database.TextArray[string]{"admin", "user"},
|
||||
"grant-id",
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
@@ -201,17 +200,17 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectGrantCascadeChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.GrantCascadeChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grant-id", "roleKeys": ["admin", "user"] }`),
|
||||
), project.GrantCascadeChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.GrantCascadeChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grant-id", "roleKeys": ["admin", "user"] }`),
|
||||
), project.GrantCascadeChangedEventMapper),
|
||||
},
|
||||
reduce: (&projectGrantProjection{}).reduceProjectGrantCascadeChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -219,7 +218,7 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
database.StringArray{"admin", "user"},
|
||||
database.TextArray[string]{"admin", "user"},
|
||||
"grant-id",
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
@@ -232,17 +231,17 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectGrantAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.GrantAddedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grant-id", "grantedOrgId": "granted-org-id", "roleKeys": ["admin", "user"] }`),
|
||||
), project.GrantAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.GrantAddedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grant-id", "grantedOrgId": "granted-org-id", "roleKeys": ["admin", "user"] }`),
|
||||
), project.GrantAddedEventMapper),
|
||||
},
|
||||
reduce: (&projectGrantProjection{}).reduceProjectGrantAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -257,7 +256,7 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
|
||||
domain.ProjectGrantStateActive,
|
||||
uint64(15),
|
||||
"granted-org-id",
|
||||
database.StringArray{"admin", "user"},
|
||||
database.TextArray[string]{"admin", "user"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -268,16 +267,16 @@ func TestProjectGrantProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (&projectGrantProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/member"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
@@ -20,34 +20,49 @@ const (
|
||||
)
|
||||
|
||||
type projectMemberProjection struct {
|
||||
crdb.StatementHandler
|
||||
es handler.EventStore
|
||||
}
|
||||
|
||||
func newProjectMemberProjection(ctx context.Context, config crdb.StatementHandlerConfig) *projectMemberProjection {
|
||||
p := new(projectMemberProjection)
|
||||
config.ProjectionName = ProjectMemberProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable(
|
||||
func newProjectMemberProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, &projectMemberProjection{es: config.Eventstore})
|
||||
}
|
||||
|
||||
func (*projectMemberProjection) Name() string {
|
||||
return ProjectMemberProjectionTable
|
||||
}
|
||||
|
||||
func (*projectMemberProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable(
|
||||
append(memberColumns,
|
||||
crdb.NewColumn(ProjectMemberProjectIDCol, crdb.ColumnTypeText),
|
||||
handler.NewColumn(ProjectMemberProjectIDCol, handler.ColumnTypeText),
|
||||
),
|
||||
handler.NewPrimaryKey(MemberInstanceID, ProjectMemberProjectIDCol, MemberUserIDCol),
|
||||
handler.WithIndex(handler.NewIndex("user_id", []string{MemberUserIDCol})),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{MemberOwnerRemoved})),
|
||||
handler.WithIndex(handler.NewIndex("user_owner_removed", []string{MemberUserOwnerRemoved})),
|
||||
handler.WithIndex(
|
||||
handler.NewIndex("pm_instance", []string{MemberInstanceID},
|
||||
handler.WithInclude(
|
||||
MemberCreationDate,
|
||||
MemberChangeDate,
|
||||
MemberUserOwnerRemoved,
|
||||
MemberRolesCol,
|
||||
MemberSequence,
|
||||
MemberResourceOwner,
|
||||
MemberOwnerRemoved,
|
||||
),
|
||||
),
|
||||
),
|
||||
crdb.NewPrimaryKey(MemberInstanceID, ProjectMemberProjectIDCol, MemberUserIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("user_id", []string{MemberUserIDCol})),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{MemberOwnerRemoved})),
|
||||
crdb.WithIndex(crdb.NewIndex("user_owner_removed", []string{MemberUserOwnerRemoved})),
|
||||
),
|
||||
)
|
||||
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *projectMemberProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *projectMemberProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: project.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: project.MemberAddedType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -72,7 +87,7 @@ func (p *projectMemberProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: user.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: user.UserRemovedType,
|
||||
Reduce: p.reduceUserRemoved,
|
||||
@@ -81,7 +96,7 @@ func (p *projectMemberProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.OrgRemovedEventType,
|
||||
Reduce: p.reduceOrgRemoved,
|
||||
@@ -90,7 +105,7 @@ func (p *projectMemberProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(MemberInstanceID),
|
||||
@@ -106,7 +121,7 @@ func (p *projectMemberProjection) reduceAdded(event eventstore.Event) (*handler.
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-bgx5Q", "reduce.wrong.event.type %s", project.MemberAddedType)
|
||||
}
|
||||
ctx := setMemberContext(e.Aggregate())
|
||||
userOwner, err := getResourceOwnerOfUser(ctx, p.Eventstore, e.Aggregate().InstanceID, e.UserID)
|
||||
userOwner, err := getResourceOwnerOfUser(ctx, p.es, e.Aggregate().InstanceID, e.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -163,7 +178,7 @@ func (p *projectMemberProjection) reduceOrgRemoved(event eventstore.Event) (*han
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-NGUEL", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
multiReduceMemberOwnerRemoved(e),
|
||||
multiReduceMemberUserOwnerRemoved(e),
|
||||
|
||||
@@ -10,8 +10,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/project"
|
||||
@@ -31,34 +30,37 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project MemberAddedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.MemberAddedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.MemberAddedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"userId": "user-id",
|
||||
"roles": ["role"]
|
||||
}`),
|
||||
), project.MemberAddedEventMapper),
|
||||
), project.MemberAddedEventMapper),
|
||||
},
|
||||
reduce: (&projectMemberProjection{
|
||||
StatementHandler: getStatementHandlerWithFilters(
|
||||
user.NewHumanAddedEvent(context.Background(),
|
||||
&user.NewAggregate("user-id", "org1").Aggregate,
|
||||
"username1",
|
||||
"firstname1",
|
||||
"lastname1",
|
||||
"nickname1",
|
||||
"displayname1",
|
||||
language.German,
|
||||
domain.GenderMale,
|
||||
"email1",
|
||||
true,
|
||||
),
|
||||
)(t)}).reduceAdded,
|
||||
es: newMockEventStore().appendFilterResponse(
|
||||
[]eventstore.Event{
|
||||
user.NewHumanAddedEvent(context.Background(),
|
||||
&user.NewAggregate("user-id", "org1").Aggregate,
|
||||
"username1",
|
||||
"firstname1",
|
||||
"lastname1",
|
||||
"nickname1",
|
||||
"displayname1",
|
||||
language.German,
|
||||
domain.GenderMale,
|
||||
"email1",
|
||||
true,
|
||||
),
|
||||
},
|
||||
),
|
||||
}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -67,7 +69,7 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
|
||||
"user-id",
|
||||
"org1",
|
||||
false,
|
||||
database.StringArray{"role"},
|
||||
database.TextArray[string]{"role"},
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -84,26 +86,26 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project MemberChangedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.MemberChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.MemberChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"userId": "user-id",
|
||||
"roles": ["role", "changed"]
|
||||
}`),
|
||||
), project.MemberChangedEventMapper),
|
||||
), project.MemberChangedEventMapper),
|
||||
},
|
||||
reduce: (&projectMemberProjection{}).reduceChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.project_members3 SET (roles, change_date, sequence) = ($1, $2, $3) WHERE (instance_id = $4) AND (user_id = $5) AND (project_id = $6)",
|
||||
expectedArgs: []interface{}{
|
||||
database.StringArray{"role", "changed"},
|
||||
database.TextArray[string]{"role", "changed"},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"instance-id",
|
||||
@@ -118,19 +120,19 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project MemberCascadeRemovedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.MemberCascadeRemovedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.MemberCascadeRemovedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"userId": "user-id"
|
||||
}`),
|
||||
), project.MemberCascadeRemovedEventMapper),
|
||||
), project.MemberCascadeRemovedEventMapper),
|
||||
},
|
||||
reduce: (&projectMemberProjection{}).reduceCascadeRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -148,19 +150,19 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project MemberRemovedType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.MemberRemovedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.MemberRemovedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{
|
||||
"userId": "user-id"
|
||||
}`),
|
||||
), project.MemberRemovedEventMapper),
|
||||
), project.MemberRemovedEventMapper),
|
||||
},
|
||||
reduce: (&projectMemberProjection{}).reduceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -178,17 +180,17 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "user UserRemovedEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.UserRemovedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), user.UserRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.UserRemovedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), user.UserRemovedEventMapper),
|
||||
},
|
||||
reduce: (&projectMemberProjection{}).reduceUserRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -205,17 +207,17 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "project ProjectRemovedEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ProjectRemovedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), project.ProjectRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ProjectRemovedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), project.ProjectRemovedEventMapper),
|
||||
},
|
||||
reduce: (&projectMemberProjection{}).reduceProjectRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -232,17 +234,17 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(MemberInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -258,17 +260,17 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "org OrgRemovedEventType",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
reduce: (&projectMemberProjection{}).reduceOrgRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: org.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/project"
|
||||
@@ -27,40 +27,41 @@ const (
|
||||
ProjectRoleColumnOwnerRemoved = "owner_removed"
|
||||
)
|
||||
|
||||
type projectRoleProjection struct {
|
||||
crdb.StatementHandler
|
||||
type projectRoleProjection struct{}
|
||||
|
||||
func newProjectRoleProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(projectRoleProjection))
|
||||
}
|
||||
|
||||
func newProjectRoleProjection(ctx context.Context, config crdb.StatementHandlerConfig) *projectRoleProjection {
|
||||
p := new(projectRoleProjection)
|
||||
config.ProjectionName = ProjectRoleProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(ProjectRoleColumnProjectID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ProjectRoleColumnKey, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ProjectRoleColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(ProjectRoleColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(ProjectRoleColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(ProjectRoleColumnResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ProjectRoleColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ProjectRoleColumnDisplayName, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ProjectRoleColumnGroupName, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(ProjectRoleColumnOwnerRemoved, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*projectRoleProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(ProjectRoleColumnProjectID, handler.ColumnTypeText),
|
||||
handler.NewColumn(ProjectRoleColumnKey, handler.ColumnTypeText),
|
||||
handler.NewColumn(ProjectRoleColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(ProjectRoleColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(ProjectRoleColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(ProjectRoleColumnResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(ProjectRoleColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(ProjectRoleColumnDisplayName, handler.ColumnTypeText),
|
||||
handler.NewColumn(ProjectRoleColumnGroupName, handler.ColumnTypeText),
|
||||
handler.NewColumn(ProjectRoleColumnOwnerRemoved, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(ProjectRoleColumnInstanceID, ProjectRoleColumnProjectID, ProjectRoleColumnKey),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{ProjectRoleColumnOwnerRemoved})),
|
||||
handler.NewPrimaryKey(ProjectRoleColumnInstanceID, ProjectRoleColumnProjectID, ProjectRoleColumnKey),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{ProjectRoleColumnOwnerRemoved})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *projectRoleProjection) reducers() []handler.AggregateReducer {
|
||||
func (*projectRoleProjection) Name() string {
|
||||
return ProjectRoleProjectionTable
|
||||
}
|
||||
|
||||
func (p *projectRoleProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: project.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: project.RoleAddedType,
|
||||
Reduce: p.reduceProjectRoleAdded,
|
||||
@@ -81,7 +82,7 @@ func (p *projectRoleProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.OrgRemovedEventType,
|
||||
Reduce: p.reduceOwnerRemoved,
|
||||
@@ -90,7 +91,7 @@ func (p *projectRoleProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(ProjectRoleColumnInstanceID),
|
||||
@@ -105,7 +106,7 @@ func (p *projectRoleProjection) reduceProjectRoleAdded(event eventstore.Event) (
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-g92Fg", "reduce.wrong.event.type %s", project.RoleAddedType)
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(ProjectRoleColumnKey, e.Key),
|
||||
@@ -127,7 +128,7 @@ func (p *projectRoleProjection) reduceProjectRoleChanged(event eventstore.Event)
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-sM0f", "reduce.wrong.event.type %s", project.GrantChangedType)
|
||||
}
|
||||
if e.DisplayName == nil && e.Group == nil {
|
||||
return crdb.NewNoOpStatement(e), nil
|
||||
return handler.NewNoOpStatement(e), nil
|
||||
}
|
||||
columns := make([]handler.Column, 0, 7)
|
||||
columns = append(columns, handler.NewCol(ProjectRoleColumnChangeDate, e.CreationDate()),
|
||||
@@ -138,7 +139,7 @@ func (p *projectRoleProjection) reduceProjectRoleChanged(event eventstore.Event)
|
||||
if e.Group != nil {
|
||||
columns = append(columns, handler.NewCol(ProjectRoleColumnGroupName, *e.Group))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
columns,
|
||||
[]handler.Condition{
|
||||
@@ -154,7 +155,7 @@ func (p *projectRoleProjection) reduceProjectRoleRemoved(event eventstore.Event)
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-L0fJf", "reduce.wrong.event.type %s", project.GrantRemovedType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ProjectRoleColumnKey, e.Key),
|
||||
@@ -169,7 +170,7 @@ func (p *projectRoleProjection) reduceProjectRemoved(event eventstore.Event) (*h
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-l0geG", "reduce.wrong.event.type %s", project.ProjectRemovedType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ProjectRoleColumnProjectID, e.Aggregate().ID),
|
||||
@@ -184,7 +185,7 @@ func (p *projectRoleProjection) reduceOwnerRemoved(event eventstore.Event) (*han
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-3XrHY", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(ProjectRoleColumnInstanceID, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -5,8 +5,7 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/project"
|
||||
@@ -25,17 +24,17 @@ func TestProjectRoleProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ProjectRemovedType),
|
||||
project.AggregateType,
|
||||
nil,
|
||||
), project.ProjectRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ProjectRemovedType,
|
||||
project.AggregateType,
|
||||
nil,
|
||||
), project.ProjectRemovedEventMapper),
|
||||
},
|
||||
reduce: (&projectRoleProjection{}).reduceProjectRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -52,17 +51,17 @@ func TestProjectRoleProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(ProjectRoleColumnInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -78,17 +77,17 @@ func TestProjectRoleProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectRoleRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.RoleRemovedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"key": "key"}`),
|
||||
), project.RoleRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.RoleRemovedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"key": "key"}`),
|
||||
), project.RoleRemovedEventMapper),
|
||||
},
|
||||
reduce: (&projectRoleProjection{}).reduceProjectRoleRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -106,17 +105,17 @@ func TestProjectRoleProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectRoleChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.RoleChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"key": "key", "displayName": "New Key", "group": "New Group"}`),
|
||||
), project.RoleChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.RoleChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"key": "key", "displayName": "New Key", "group": "New Group"}`),
|
||||
), project.RoleChangedEventMapper),
|
||||
},
|
||||
reduce: (&projectRoleProjection{}).reduceProjectRoleChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -138,34 +137,34 @@ func TestProjectRoleProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectRoleChanged no changes",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.RoleChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), project.RoleChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.RoleChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), project.RoleChangedEventMapper),
|
||||
},
|
||||
reduce: (&projectRoleProjection{}).reduceProjectRoleChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
executer: &testExecuter{},
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "reduceProjectRoleAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.RoleAddedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"key": "key", "displayName": "Key", "group": "Group"}`),
|
||||
), project.RoleAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.RoleAddedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"key": "key", "displayName": "Key", "group": "Group"}`),
|
||||
), project.RoleAddedEventMapper),
|
||||
},
|
||||
reduce: (&projectRoleProjection{}).reduceProjectRoleAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -190,16 +189,16 @@ func TestProjectRoleProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (&projectRoleProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/project"
|
||||
@@ -26,17 +25,17 @@ func TestProjectProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ProjectRemovedType),
|
||||
project.AggregateType,
|
||||
nil,
|
||||
), project.ProjectRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ProjectRemovedType,
|
||||
project.AggregateType,
|
||||
nil,
|
||||
), project.ProjectRemovedEventMapper),
|
||||
},
|
||||
reduce: (&projectProjection{}).reduceProjectRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -53,17 +52,17 @@ func TestProjectProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(ProjectColumnInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -79,17 +78,17 @@ func TestProjectProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectReactivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ProjectReactivatedType),
|
||||
project.AggregateType,
|
||||
nil,
|
||||
), project.ProjectReactivatedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ProjectReactivatedType,
|
||||
project.AggregateType,
|
||||
nil,
|
||||
), project.ProjectReactivatedEventMapper),
|
||||
},
|
||||
reduce: (&projectProjection{}).reduceProjectReactivated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -109,17 +108,17 @@ func TestProjectProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectDeactivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ProjectDeactivatedType),
|
||||
project.AggregateType,
|
||||
nil,
|
||||
), project.ProjectDeactivatedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ProjectDeactivatedType,
|
||||
project.AggregateType,
|
||||
nil,
|
||||
), project.ProjectDeactivatedEventMapper),
|
||||
},
|
||||
reduce: (&projectProjection{}).reduceProjectDeactivated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -139,17 +138,17 @@ func TestProjectProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ProjectChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"name": "new name", "projectRoleAssertion": true, "projectRoleCheck": true, "hasProjectCheck": true, "privateLabelingSetting": 1}`),
|
||||
), project.ProjectChangeEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ProjectChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"name": "new name", "projectRoleAssertion": true, "projectRoleCheck": true, "hasProjectCheck": true, "privateLabelingSetting": 1}`),
|
||||
), project.ProjectChangeEventMapper),
|
||||
},
|
||||
reduce: (&projectProjection{}).reduceProjectChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -173,34 +172,34 @@ func TestProjectProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectChanged no changes",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ProjectChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), project.ProjectChangeEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ProjectChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), project.ProjectChangeEventMapper),
|
||||
},
|
||||
reduce: (&projectProjection{}).reduceProjectChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
executer: &testExecuter{},
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "reduceProjectAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ProjectAddedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"name": "name", "projectRoleAssertion": true, "projectRoleCheck": true, "hasProjectCheck": true, "privateLabelingSetting": 1}`),
|
||||
), project.ProjectAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ProjectAddedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"name": "name", "projectRoleAssertion": true, "projectRoleCheck": true, "hasProjectCheck": true, "privateLabelingSetting": 1}`),
|
||||
), project.ProjectAddedEventMapper),
|
||||
},
|
||||
reduce: (&projectProjection{}).reduceProjectAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("project"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -228,16 +227,16 @@ func TestProjectProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (&projectProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -3,77 +3,76 @@ package projection
|
||||
import (
|
||||
"context"
|
||||
|
||||
internal_authz "github.com/zitadel/zitadel/internal/api/authz"
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
CurrentSeqTable = "projections.current_sequences"
|
||||
CurrentStateTable = "projections.current_states"
|
||||
LocksTable = "projections.locks"
|
||||
FailedEventsTable = "projections.failed_events"
|
||||
FailedEventsTable = "projections.failed_events2"
|
||||
)
|
||||
|
||||
var (
|
||||
projectionConfig crdb.StatementHandlerConfig
|
||||
OrgProjection *orgProjection
|
||||
OrgMetadataProjection *orgMetadataProjection
|
||||
ActionProjection *actionProjection
|
||||
FlowProjection *flowProjection
|
||||
ProjectProjection *projectProjection
|
||||
PasswordComplexityProjection *passwordComplexityProjection
|
||||
PasswordAgeProjection *passwordAgeProjection
|
||||
LockoutPolicyProjection *lockoutPolicyProjection
|
||||
PrivacyPolicyProjection *privacyPolicyProjection
|
||||
DomainPolicyProjection *domainPolicyProjection
|
||||
LabelPolicyProjection *labelPolicyProjection
|
||||
ProjectGrantProjection *projectGrantProjection
|
||||
ProjectRoleProjection *projectRoleProjection
|
||||
OrgDomainProjection *orgDomainProjection
|
||||
LoginPolicyProjection *loginPolicyProjection
|
||||
IDPProjection *idpProjection
|
||||
AppProjection *appProjection
|
||||
IDPUserLinkProjection *idpUserLinkProjection
|
||||
IDPLoginPolicyLinkProjection *idpLoginPolicyLinkProjection
|
||||
IDPTemplateProjection *idpTemplateProjection
|
||||
MailTemplateProjection *mailTemplateProjection
|
||||
MessageTextProjection *messageTextProjection
|
||||
CustomTextProjection *customTextProjection
|
||||
UserProjection *userProjection
|
||||
LoginNameProjection *loginNameProjection
|
||||
OrgMemberProjection *orgMemberProjection
|
||||
InstanceDomainProjection *instanceDomainProjection
|
||||
InstanceMemberProjection *instanceMemberProjection
|
||||
ProjectMemberProjection *projectMemberProjection
|
||||
ProjectGrantMemberProjection *projectGrantMemberProjection
|
||||
AuthNKeyProjection *authNKeyProjection
|
||||
PersonalAccessTokenProjection *personalAccessTokenProjection
|
||||
UserGrantProjection *userGrantProjection
|
||||
UserMetadataProjection *userMetadataProjection
|
||||
UserAuthMethodProjection *userAuthMethodProjection
|
||||
InstanceProjection *instanceProjection
|
||||
SecretGeneratorProjection *secretGeneratorProjection
|
||||
SMTPConfigProjection *smtpConfigProjection
|
||||
SMSConfigProjection *smsConfigProjection
|
||||
OIDCSettingsProjection *oidcSettingsProjection
|
||||
DebugNotificationProviderProjection *debugNotificationProviderProjection
|
||||
KeyProjection *keyProjection
|
||||
SecurityPolicyProjection *securityPolicyProjection
|
||||
NotificationPolicyProjection *notificationPolicyProjection
|
||||
projectionConfig handler.Config
|
||||
OrgProjection *handler.Handler
|
||||
OrgMetadataProjection *handler.Handler
|
||||
ActionProjection *handler.Handler
|
||||
FlowProjection *handler.Handler
|
||||
ProjectProjection *handler.Handler
|
||||
PasswordComplexityProjection *handler.Handler
|
||||
PasswordAgeProjection *handler.Handler
|
||||
LockoutPolicyProjection *handler.Handler
|
||||
PrivacyPolicyProjection *handler.Handler
|
||||
DomainPolicyProjection *handler.Handler
|
||||
LabelPolicyProjection *handler.Handler
|
||||
ProjectGrantProjection *handler.Handler
|
||||
ProjectRoleProjection *handler.Handler
|
||||
OrgDomainProjection *handler.Handler
|
||||
LoginPolicyProjection *handler.Handler
|
||||
IDPProjection *handler.Handler
|
||||
AppProjection *handler.Handler
|
||||
IDPUserLinkProjection *handler.Handler
|
||||
IDPLoginPolicyLinkProjection *handler.Handler
|
||||
IDPTemplateProjection *handler.Handler
|
||||
MailTemplateProjection *handler.Handler
|
||||
MessageTextProjection *handler.Handler
|
||||
CustomTextProjection *handler.Handler
|
||||
UserProjection *handler.Handler
|
||||
LoginNameProjection *handler.Handler
|
||||
OrgMemberProjection *handler.Handler
|
||||
InstanceDomainProjection *handler.Handler
|
||||
InstanceMemberProjection *handler.Handler
|
||||
ProjectMemberProjection *handler.Handler
|
||||
ProjectGrantMemberProjection *handler.Handler
|
||||
AuthNKeyProjection *handler.Handler
|
||||
PersonalAccessTokenProjection *handler.Handler
|
||||
UserGrantProjection *handler.Handler
|
||||
UserMetadataProjection *handler.Handler
|
||||
UserAuthMethodProjection *handler.Handler
|
||||
InstanceProjection *handler.Handler
|
||||
SecretGeneratorProjection *handler.Handler
|
||||
SMTPConfigProjection *handler.Handler
|
||||
SMSConfigProjection *handler.Handler
|
||||
OIDCSettingsProjection *handler.Handler
|
||||
DebugNotificationProviderProjection *handler.Handler
|
||||
KeyProjection *handler.Handler
|
||||
SecurityPolicyProjection *handler.Handler
|
||||
NotificationPolicyProjection *handler.Handler
|
||||
NotificationsProjection interface{}
|
||||
NotificationsQuotaProjection interface{}
|
||||
TelemetryPusherProjection interface{}
|
||||
DeviceAuthProjection *deviceAuthProjection
|
||||
SessionProjection *sessionProjection
|
||||
AuthRequestProjection *authRequestProjection
|
||||
MilestoneProjection *milestoneProjection
|
||||
DeviceAuthProjection *handler.Handler
|
||||
SessionProjection *handler.Handler
|
||||
AuthRequestProjection *handler.Handler
|
||||
MilestoneProjection *handler.Handler
|
||||
QuotaProjection *quotaProjection
|
||||
)
|
||||
|
||||
type projection interface {
|
||||
Start()
|
||||
Start(ctx context.Context)
|
||||
Init(ctx context.Context) error
|
||||
}
|
||||
|
||||
@@ -81,24 +80,16 @@ var (
|
||||
projections []projection
|
||||
)
|
||||
|
||||
func Create(ctx context.Context, sqlClient *database.DB, es *eventstore.Eventstore, config Config, keyEncryptionAlgorithm crypto.EncryptionAlgorithm, certEncryptionAlgorithm crypto.EncryptionAlgorithm) error {
|
||||
projectionConfig = crdb.StatementHandlerConfig{
|
||||
ProjectionHandlerConfig: handler.ProjectionHandlerConfig{
|
||||
HandlerConfig: handler.HandlerConfig{
|
||||
Eventstore: es,
|
||||
},
|
||||
RequeueEvery: config.RequeueEvery,
|
||||
RetryFailedAfter: config.RetryFailedAfter,
|
||||
Retries: config.MaxFailureCount,
|
||||
ConcurrentInstances: config.ConcurrentInstances,
|
||||
HandleActiveInstances: config.HandleActiveInstances,
|
||||
},
|
||||
Client: sqlClient,
|
||||
SequenceTable: CurrentSeqTable,
|
||||
LockTable: LocksTable,
|
||||
FailedEventsTable: FailedEventsTable,
|
||||
MaxFailureCount: config.MaxFailureCount,
|
||||
BulkLimit: config.BulkLimit,
|
||||
func Create(ctx context.Context, sqlClient *database.DB, es handler.EventStore, config Config, keyEncryptionAlgorithm crypto.EncryptionAlgorithm, certEncryptionAlgorithm crypto.EncryptionAlgorithm, systemUsers map[string]*internal_authz.SystemAPIUser) error {
|
||||
projectionConfig = handler.Config{
|
||||
Client: sqlClient,
|
||||
Eventstore: es,
|
||||
BulkLimit: uint16(config.BulkLimit),
|
||||
RequeueEvery: config.RequeueEvery,
|
||||
HandleActiveInstances: config.HandleActiveInstances,
|
||||
MaxFailureCount: config.MaxFailureCount,
|
||||
RetryFailedAfter: config.RetryFailedAfter,
|
||||
TransactionDuration: config.TransactionDuration,
|
||||
}
|
||||
|
||||
OrgProjection = newOrgProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["orgs"]))
|
||||
@@ -148,7 +139,7 @@ func Create(ctx context.Context, sqlClient *database.DB, es *eventstore.Eventsto
|
||||
DeviceAuthProjection = newDeviceAuthProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["device_auth"]))
|
||||
SessionProjection = newSessionProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["sessions"]))
|
||||
AuthRequestProjection = newAuthRequestProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["auth_requests"]))
|
||||
MilestoneProjection = newMilestoneProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["milestones"]))
|
||||
MilestoneProjection = newMilestoneProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["milestones"]), systemUsers)
|
||||
QuotaProjection = newQuotaProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["quotas"]))
|
||||
newProjectionsList()
|
||||
return nil
|
||||
@@ -163,17 +154,17 @@ func Init(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Start() {
|
||||
func Start(ctx context.Context) {
|
||||
for _, projection := range projections {
|
||||
projection.Start()
|
||||
projection.Start(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
func ApplyCustomConfig(customConfig CustomConfig) crdb.StatementHandlerConfig {
|
||||
func ApplyCustomConfig(customConfig CustomConfig) handler.Config {
|
||||
return applyCustomConfig(projectionConfig, customConfig)
|
||||
}
|
||||
|
||||
func applyCustomConfig(config crdb.StatementHandlerConfig, customConfig CustomConfig) crdb.StatementHandlerConfig {
|
||||
func applyCustomConfig(config handler.Config, customConfig CustomConfig) handler.Config {
|
||||
if customConfig.BulkLimit != nil {
|
||||
config.BulkLimit = *customConfig.BulkLimit
|
||||
}
|
||||
@@ -189,6 +180,9 @@ func applyCustomConfig(config crdb.StatementHandlerConfig, customConfig CustomCo
|
||||
if customConfig.HandleActiveInstances != nil {
|
||||
config.HandleActiveInstances = *customConfig.HandleActiveInstances
|
||||
}
|
||||
if customConfig.TransactionDuration != nil {
|
||||
config.TransactionDuration = *customConfig.TransactionDuration
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
@@ -249,6 +243,6 @@ func newProjectionsList() {
|
||||
SessionProjection,
|
||||
AuthRequestProjection,
|
||||
MilestoneProjection,
|
||||
QuotaProjection,
|
||||
QuotaProjection.handler,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
zitadel_errors "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/quota"
|
||||
)
|
||||
@@ -51,62 +51,68 @@ const (
|
||||
)
|
||||
|
||||
type quotaProjection struct {
|
||||
crdb.StatementHandler
|
||||
client *database.DB
|
||||
handler *handler.Handler
|
||||
client *database.DB
|
||||
}
|
||||
|
||||
func newQuotaProjection(ctx context.Context, config crdb.StatementHandlerConfig) *quotaProjection {
|
||||
p := new(quotaProjection)
|
||||
config.ProjectionName = QuotasProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewMultiTableCheck(
|
||||
crdb.NewTable(
|
||||
[]*crdb.Column{
|
||||
crdb.NewColumn(QuotaColumnID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(QuotaColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(QuotaColumnUnit, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(QuotaColumnAmount, crdb.ColumnTypeInt64, crdb.Nullable()),
|
||||
crdb.NewColumn(QuotaColumnFrom, crdb.ColumnTypeTimestamp, crdb.Nullable()),
|
||||
crdb.NewColumn(QuotaColumnInterval, crdb.ColumnTypeInterval, crdb.Nullable()),
|
||||
crdb.NewColumn(QuotaColumnLimit, crdb.ColumnTypeBool, crdb.Nullable()),
|
||||
},
|
||||
crdb.NewPrimaryKey(QuotaColumnInstanceID, QuotaColumnUnit),
|
||||
),
|
||||
crdb.NewSuffixedTable(
|
||||
[]*crdb.Column{
|
||||
crdb.NewColumn(QuotaPeriodColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(QuotaPeriodColumnUnit, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(QuotaPeriodColumnStart, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(QuotaPeriodColumnUsage, crdb.ColumnTypeInt64),
|
||||
},
|
||||
crdb.NewPrimaryKey(QuotaPeriodColumnInstanceID, QuotaPeriodColumnUnit, QuotaPeriodColumnStart),
|
||||
quotaPeriodsTableSuffix,
|
||||
),
|
||||
crdb.NewSuffixedTable(
|
||||
[]*crdb.Column{
|
||||
crdb.NewColumn(QuotaNotificationColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(QuotaNotificationColumnUnit, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(QuotaNotificationColumnID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(QuotaNotificationColumnCallURL, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(QuotaNotificationColumnPercent, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(QuotaNotificationColumnRepeat, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(QuotaNotificationColumnLatestDuePeriodStart, crdb.ColumnTypeTimestamp, crdb.Nullable()),
|
||||
crdb.NewColumn(QuotaNotificationColumnNextDueThreshold, crdb.ColumnTypeInt64, crdb.Nullable()),
|
||||
},
|
||||
crdb.NewPrimaryKey(QuotaNotificationColumnInstanceID, QuotaNotificationColumnUnit, QuotaNotificationColumnID),
|
||||
quotaNotificationsTableSuffix,
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
p.client = config.Client
|
||||
func newQuotaProjection(ctx context.Context, config handler.Config) *quotaProjection {
|
||||
p := "aProjection{
|
||||
client: config.Client,
|
||||
}
|
||||
p.handler = handler.NewHandler(ctx, &config, p)
|
||||
return p
|
||||
}
|
||||
|
||||
func (q *quotaProjection) reducers() []handler.AggregateReducer {
|
||||
func (*quotaProjection) Name() string {
|
||||
return QuotasProjectionTable
|
||||
}
|
||||
|
||||
func (*quotaProjection) Init() *old_handler.Check {
|
||||
return handler.NewMultiTableCheck(
|
||||
handler.NewTable(
|
||||
[]*handler.InitColumn{
|
||||
handler.NewColumn(QuotaColumnID, handler.ColumnTypeText),
|
||||
handler.NewColumn(QuotaColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(QuotaColumnUnit, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(QuotaColumnAmount, handler.ColumnTypeInt64, handler.Nullable()),
|
||||
handler.NewColumn(QuotaColumnFrom, handler.ColumnTypeTimestamp, handler.Nullable()),
|
||||
handler.NewColumn(QuotaColumnInterval, handler.ColumnTypeInterval, handler.Nullable()),
|
||||
handler.NewColumn(QuotaColumnLimit, handler.ColumnTypeBool, handler.Nullable()),
|
||||
},
|
||||
handler.NewPrimaryKey(QuotaColumnInstanceID, QuotaColumnUnit),
|
||||
),
|
||||
handler.NewSuffixedTable(
|
||||
[]*handler.InitColumn{
|
||||
handler.NewColumn(QuotaPeriodColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(QuotaPeriodColumnUnit, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(QuotaPeriodColumnStart, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(QuotaPeriodColumnUsage, handler.ColumnTypeInt64),
|
||||
},
|
||||
handler.NewPrimaryKey(QuotaPeriodColumnInstanceID, QuotaPeriodColumnUnit, QuotaPeriodColumnStart),
|
||||
quotaPeriodsTableSuffix,
|
||||
),
|
||||
handler.NewSuffixedTable(
|
||||
[]*handler.InitColumn{
|
||||
handler.NewColumn(QuotaNotificationColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(QuotaNotificationColumnUnit, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(QuotaNotificationColumnID, handler.ColumnTypeText),
|
||||
handler.NewColumn(QuotaNotificationColumnCallURL, handler.ColumnTypeText),
|
||||
handler.NewColumn(QuotaNotificationColumnPercent, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(QuotaNotificationColumnRepeat, handler.ColumnTypeBool),
|
||||
handler.NewColumn(QuotaNotificationColumnLatestDuePeriodStart, handler.ColumnTypeTimestamp, handler.Nullable()),
|
||||
handler.NewColumn(QuotaNotificationColumnNextDueThreshold, handler.ColumnTypeInt64, handler.Nullable()),
|
||||
},
|
||||
handler.NewPrimaryKey(QuotaNotificationColumnInstanceID, QuotaNotificationColumnUnit, QuotaNotificationColumnID),
|
||||
quotaNotificationsTableSuffix,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
func (q *quotaProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: q.reduceInstanceRemoved,
|
||||
@@ -115,7 +121,7 @@ func (q *quotaProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: quota.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: quota.AddedEventType,
|
||||
Reduce: q.reduceQuotaSet,
|
||||
@@ -142,7 +148,7 @@ func (q *quotaProjection) reducers() []handler.AggregateReducer {
|
||||
}
|
||||
|
||||
func (q *quotaProjection) reduceQuotaNotified(event eventstore.Event) (*handler.Statement, error) {
|
||||
return crdb.NewNoOpStatement(event), nil
|
||||
return handler.NewNoOpStatement(event), nil
|
||||
}
|
||||
|
||||
func (q *quotaProjection) reduceQuotaSet(event eventstore.Event) (*handler.Statement, error) {
|
||||
@@ -150,7 +156,7 @@ func (q *quotaProjection) reduceQuotaSet(event eventstore.Event) (*handler.State
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var statements []func(e eventstore.Event) crdb.Exec
|
||||
var statements []func(e eventstore.Event) handler.Exec
|
||||
|
||||
// 1. Insert or update quota if the event has not only notification changes
|
||||
quotaConflictColumns := []handler.Column{
|
||||
@@ -174,24 +180,24 @@ func (q *quotaProjection) reduceQuotaSet(event eventstore.Event) (*handler.State
|
||||
// TODO: Add the quota ID to the primary key in a migration?
|
||||
quotaUpdateCols = append(quotaUpdateCols, handler.NewCol(QuotaColumnID, e.Aggregate().ID))
|
||||
quotaUpdateCols = append(quotaUpdateCols, quotaConflictColumns...)
|
||||
statements = append(statements, crdb.AddUpsertStatement(quotaConflictColumns, quotaUpdateCols))
|
||||
statements = append(statements, handler.AddUpsertStatement(quotaConflictColumns, quotaUpdateCols))
|
||||
}
|
||||
|
||||
// 2. Delete existing notifications
|
||||
if e.Notifications == nil {
|
||||
return crdb.NewMultiStatement(e, statements...), nil
|
||||
return handler.NewMultiStatement(e, statements...), nil
|
||||
}
|
||||
statements = append(statements, crdb.AddDeleteStatement(
|
||||
statements = append(statements, handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(QuotaNotificationColumnInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCond(QuotaNotificationColumnUnit, e.Unit),
|
||||
},
|
||||
crdb.WithTableSuffix(quotaNotificationsTableSuffix),
|
||||
handler.WithTableSuffix(quotaNotificationsTableSuffix),
|
||||
))
|
||||
notifications := *e.Notifications
|
||||
for i := range notifications {
|
||||
notification := notifications[i]
|
||||
statements = append(statements, crdb.AddCreateStatement(
|
||||
statements = append(statements, handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(QuotaNotificationColumnInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCol(QuotaNotificationColumnUnit, e.Unit),
|
||||
@@ -200,10 +206,10 @@ func (q *quotaProjection) reduceQuotaSet(event eventstore.Event) (*handler.State
|
||||
handler.NewCol(QuotaNotificationColumnPercent, notification.Percent),
|
||||
handler.NewCol(QuotaNotificationColumnRepeat, notification.Repeat),
|
||||
},
|
||||
crdb.WithTableSuffix(quotaNotificationsTableSuffix),
|
||||
handler.WithTableSuffix(quotaNotificationsTableSuffix),
|
||||
))
|
||||
}
|
||||
return crdb.NewMultiStatement(e, statements...), nil
|
||||
return handler.NewMultiStatement(e, statements...), nil
|
||||
}
|
||||
|
||||
func (q *quotaProjection) reduceQuotaNotificationDue(event eventstore.Event) (*handler.Statement, error) {
|
||||
@@ -211,7 +217,7 @@ func (q *quotaProjection) reduceQuotaNotificationDue(event eventstore.Event) (*h
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return crdb.NewUpdateStatement(e,
|
||||
return handler.NewUpdateStatement(e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(QuotaNotificationColumnLatestDuePeriodStart, e.PeriodStart),
|
||||
handler.NewCol(QuotaNotificationColumnNextDueThreshold, e.Threshold+100), // next due_threshold is always the reached + 100 => percent (e.g. 90) in the next bucket (e.g. 190)
|
||||
@@ -221,9 +227,7 @@ func (q *quotaProjection) reduceQuotaNotificationDue(event eventstore.Event) (*h
|
||||
handler.NewCond(QuotaNotificationColumnUnit, e.Unit),
|
||||
handler.NewCond(QuotaNotificationColumnID, e.ID),
|
||||
},
|
||||
crdb.WithTableSuffix(quotaNotificationsTableSuffix),
|
||||
// The notification could have been removed in the meantime
|
||||
crdb.WithIgnoreNotFound(),
|
||||
handler.WithTableSuffix(quotaNotificationsTableSuffix),
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -232,23 +236,23 @@ func (q *quotaProjection) reduceQuotaRemoved(event eventstore.Event) (*handler.S
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(QuotaPeriodColumnInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCond(QuotaPeriodColumnUnit, e.Unit),
|
||||
},
|
||||
crdb.WithTableSuffix(quotaPeriodsTableSuffix),
|
||||
handler.WithTableSuffix(quotaPeriodsTableSuffix),
|
||||
),
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(QuotaNotificationColumnInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCond(QuotaNotificationColumnUnit, e.Unit),
|
||||
},
|
||||
crdb.WithTableSuffix(quotaNotificationsTableSuffix),
|
||||
handler.WithTableSuffix(quotaNotificationsTableSuffix),
|
||||
),
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(QuotaColumnInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCond(QuotaColumnUnit, e.Unit),
|
||||
@@ -263,21 +267,21 @@ func (q *quotaProjection) reduceInstanceRemoved(event eventstore.Event) (*handle
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(QuotaPeriodColumnInstanceID, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(quotaPeriodsTableSuffix),
|
||||
handler.WithTableSuffix(quotaPeriodsTableSuffix),
|
||||
),
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(QuotaNotificationColumnInstanceID, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(quotaNotificationsTableSuffix),
|
||||
handler.WithTableSuffix(quotaNotificationsTableSuffix),
|
||||
),
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(QuotaColumnInstanceID, e.Aggregate().InstanceID),
|
||||
},
|
||||
|
||||
@@ -12,8 +12,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/quota"
|
||||
)
|
||||
@@ -32,7 +31,7 @@ func TestQuotasProjection_reduces(t *testing.T) {
|
||||
name: "reduceQuotaSet with added type",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(quota.AddedEventType),
|
||||
quota.AddedEventType,
|
||||
quota.AggregateType,
|
||||
[]byte(`{
|
||||
"unit": 1,
|
||||
@@ -45,9 +44,8 @@ func TestQuotasProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: ("aProjection{}).reduceQuotaSet,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("quota"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("quota"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -70,7 +68,7 @@ func TestQuotasProjection_reduces(t *testing.T) {
|
||||
name: "reduceQuotaAdded with added type and notification",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(quota.AddedEventType),
|
||||
quota.AddedEventType,
|
||||
quota.AggregateType,
|
||||
[]byte(`{
|
||||
"unit": 1,
|
||||
@@ -91,9 +89,8 @@ func TestQuotasProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: ("aProjection{}).reduceQuotaSet,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("quota"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("quota"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -134,7 +131,7 @@ func TestQuotasProjection_reduces(t *testing.T) {
|
||||
name: "reduceQuotaSet with set type",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(quota.SetEventType),
|
||||
quota.SetEventType,
|
||||
quota.AggregateType,
|
||||
[]byte(`{
|
||||
"unit": 1,
|
||||
@@ -147,9 +144,8 @@ func TestQuotasProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: ("aProjection{}).reduceQuotaSet,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("quota"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("quota"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -172,7 +168,7 @@ func TestQuotasProjection_reduces(t *testing.T) {
|
||||
name: "reduceQuotaAdded with set type and notification",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(quota.SetEventType),
|
||||
quota.SetEventType,
|
||||
quota.AggregateType,
|
||||
[]byte(`{
|
||||
"unit": 1,
|
||||
@@ -193,9 +189,8 @@ func TestQuotasProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: ("aProjection{}).reduceQuotaSet,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("quota"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("quota"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -236,7 +231,7 @@ func TestQuotasProjection_reduces(t *testing.T) {
|
||||
name: "reduceQuotaNotificationDue",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(quota.NotificationDueEventType),
|
||||
quota.NotificationDueEventType,
|
||||
quota.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "id",
|
||||
@@ -250,9 +245,8 @@ func TestQuotasProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: ("aProjection{}).reduceQuotaNotificationDue,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("quota"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("quota"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -273,7 +267,7 @@ func TestQuotasProjection_reduces(t *testing.T) {
|
||||
name: "reduceQuotaRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(quota.RemovedEventType),
|
||||
quota.RemovedEventType,
|
||||
quota.AggregateType,
|
||||
[]byte(`{
|
||||
"unit": 1
|
||||
@@ -282,9 +276,8 @@ func TestQuotasProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: ("aProjection{}).reduceQuotaRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("quota"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("quota"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -315,7 +308,7 @@ func TestQuotasProjection_reduces(t *testing.T) {
|
||||
name: "reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"name": "name"
|
||||
@@ -324,9 +317,8 @@ func TestQuotasProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: ("aProjection{}).reduceInstanceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
@@ -28,42 +28,43 @@ const (
|
||||
SecretGeneratorColumnIncludeSymbols = "include_symbols"
|
||||
)
|
||||
|
||||
type secretGeneratorProjection struct {
|
||||
crdb.StatementHandler
|
||||
type secretGeneratorProjection struct{}
|
||||
|
||||
func newSecretGeneratorProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(secretGeneratorProjection))
|
||||
}
|
||||
|
||||
func newSecretGeneratorProjection(ctx context.Context, config crdb.StatementHandlerConfig) *secretGeneratorProjection {
|
||||
p := new(secretGeneratorProjection)
|
||||
config.ProjectionName = SecretGeneratorProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(SecretGeneratorColumnGeneratorType, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(SecretGeneratorColumnAggregateID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SecretGeneratorColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(SecretGeneratorColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(SecretGeneratorColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(SecretGeneratorColumnResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SecretGeneratorColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SecretGeneratorColumnLength, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(SecretGeneratorColumnExpiry, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(SecretGeneratorColumnIncludeLowerLetters, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(SecretGeneratorColumnIncludeUpperLetters, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(SecretGeneratorColumnIncludeDigits, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(SecretGeneratorColumnIncludeSymbols, crdb.ColumnTypeBool),
|
||||
func (*secretGeneratorProjection) Name() string {
|
||||
return SecretGeneratorProjectionTable
|
||||
}
|
||||
|
||||
func (*secretGeneratorProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(SecretGeneratorColumnGeneratorType, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(SecretGeneratorColumnAggregateID, handler.ColumnTypeText),
|
||||
handler.NewColumn(SecretGeneratorColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(SecretGeneratorColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(SecretGeneratorColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(SecretGeneratorColumnResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(SecretGeneratorColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(SecretGeneratorColumnLength, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(SecretGeneratorColumnExpiry, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(SecretGeneratorColumnIncludeLowerLetters, handler.ColumnTypeBool),
|
||||
handler.NewColumn(SecretGeneratorColumnIncludeUpperLetters, handler.ColumnTypeBool),
|
||||
handler.NewColumn(SecretGeneratorColumnIncludeDigits, handler.ColumnTypeBool),
|
||||
handler.NewColumn(SecretGeneratorColumnIncludeSymbols, handler.ColumnTypeBool),
|
||||
},
|
||||
crdb.NewPrimaryKey(SecretGeneratorColumnInstanceID, SecretGeneratorColumnGeneratorType, SecretGeneratorColumnAggregateID),
|
||||
handler.NewPrimaryKey(SecretGeneratorColumnInstanceID, SecretGeneratorColumnGeneratorType, SecretGeneratorColumnAggregateID),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *secretGeneratorProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *secretGeneratorProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.SecretGeneratorAddedEventType,
|
||||
Reduce: p.reduceSecretGeneratorAdded,
|
||||
@@ -90,7 +91,7 @@ func (p *secretGeneratorProjection) reduceSecretGeneratorAdded(event eventstore.
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-sk99F", "reduce.wrong.event.type %s", instance.SecretGeneratorAddedEventType)
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SecretGeneratorColumnAggregateID, e.Aggregate().ID),
|
||||
@@ -137,7 +138,7 @@ func (p *secretGeneratorProjection) reduceSecretGeneratorChanged(event eventstor
|
||||
if e.IncludeSymbols != nil {
|
||||
columns = append(columns, handler.NewCol(SecretGeneratorColumnIncludeSymbols, *e.IncludeSymbols))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
columns,
|
||||
[]handler.Condition{
|
||||
@@ -153,7 +154,7 @@ func (p *secretGeneratorProjection) reduceSecretGeneratorRemoved(event eventstor
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-fmiIf", "reduce.wrong.event.type %s", instance.SecretGeneratorRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(SecretGeneratorColumnAggregateID, e.Aggregate().ID),
|
||||
|
||||
@@ -7,8 +7,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
@@ -25,17 +24,17 @@ func TestSecretGeneratorProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceSecretGeneratorRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.SecretGeneratorRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"generatorType": 1}`),
|
||||
), instance.SecretGeneratorRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SecretGeneratorRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"generatorType": 1}`),
|
||||
), instance.SecretGeneratorRemovedEventMapper),
|
||||
},
|
||||
reduce: (&secretGeneratorProjection{}).reduceSecretGeneratorRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -53,17 +52,17 @@ func TestSecretGeneratorProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceSecretGeneratorChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.SecretGeneratorChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"generatorType": 1, "length": 4, "expiry": 10000000, "includeLowerLetters": true, "includeUpperLetters": true, "includeDigits": true, "includeSymbols": true}`),
|
||||
), instance.SecretGeneratorChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SecretGeneratorChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"generatorType": 1, "length": 4, "expiry": 10000000, "includeLowerLetters": true, "includeUpperLetters": true, "includeDigits": true, "includeSymbols": true}`),
|
||||
), instance.SecretGeneratorChangedEventMapper),
|
||||
},
|
||||
reduce: (&secretGeneratorProjection{}).reduceSecretGeneratorChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -89,17 +88,17 @@ func TestSecretGeneratorProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceSecretGeneratorAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.SecretGeneratorAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"generatorType": 1, "length": 4, "expiry": 10000000, "includeLowerLetters": true, "includeUpperLetters": true, "includeDigits": true, "includeSymbols": true}`),
|
||||
), instance.SecretGeneratorAddedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SecretGeneratorAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{"generatorType": 1, "length": 4, "expiry": 10000000, "includeLowerLetters": true, "includeUpperLetters": true, "includeDigits": true, "includeSymbols": true}`),
|
||||
), instance.SecretGeneratorAddedEventMapper),
|
||||
},
|
||||
reduce: (&secretGeneratorProjection{}).reduceSecretGeneratorAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -127,17 +126,17 @@ func TestSecretGeneratorProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(MemberInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
@@ -20,35 +20,36 @@ const (
|
||||
SecurityPolicyColumnAllowedOrigins = "origins"
|
||||
)
|
||||
|
||||
type securityPolicyProjection struct {
|
||||
crdb.StatementHandler
|
||||
type securityPolicyProjection struct{}
|
||||
|
||||
func newSecurityPolicyProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(securityPolicyProjection))
|
||||
}
|
||||
|
||||
func newSecurityPolicyProjection(ctx context.Context, config crdb.StatementHandlerConfig) *securityPolicyProjection {
|
||||
p := new(securityPolicyProjection)
|
||||
config.ProjectionName = SecurityPolicyProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(SecurityPolicyColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(SecurityPolicyColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(SecurityPolicyColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SecurityPolicyColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(SecurityPolicyColumnEnabled, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(SecurityPolicyColumnAllowedOrigins, crdb.ColumnTypeTextArray, crdb.Nullable()),
|
||||
func (*securityPolicyProjection) Name() string {
|
||||
return SecurityPolicyProjectionTable
|
||||
}
|
||||
|
||||
func (*securityPolicyProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(SecurityPolicyColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(SecurityPolicyColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(SecurityPolicyColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(SecurityPolicyColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(SecurityPolicyColumnEnabled, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(SecurityPolicyColumnAllowedOrigins, handler.ColumnTypeTextArray, handler.Nullable()),
|
||||
},
|
||||
crdb.NewPrimaryKey(SecurityPolicyColumnInstanceID),
|
||||
handler.NewPrimaryKey(SecurityPolicyColumnInstanceID),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *securityPolicyProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *securityPolicyProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.SecurityPolicySetEventType,
|
||||
Reduce: p.reduceSecurityPolicySet,
|
||||
@@ -79,7 +80,7 @@ func (p *securityPolicyProjection) reduceSecurityPolicySet(event eventstore.Even
|
||||
if e.AllowedOrigins != nil {
|
||||
changes = append(changes, handler.NewCol(SecurityPolicyColumnAllowedOrigins, e.AllowedOrigins))
|
||||
}
|
||||
return crdb.NewUpsertStatement(
|
||||
return handler.NewUpsertStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SecurityPolicyColumnInstanceID, ""),
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/session"
|
||||
"github.com/zitadel/zitadel/internal/repository/user"
|
||||
@@ -37,48 +37,49 @@ const (
|
||||
SessionColumnTokenID = "token_id"
|
||||
)
|
||||
|
||||
type sessionProjection struct {
|
||||
crdb.StatementHandler
|
||||
type sessionProjection struct{}
|
||||
|
||||
func newSessionProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(sessionProjection))
|
||||
}
|
||||
|
||||
func newSessionProjection(ctx context.Context, config crdb.StatementHandlerConfig) *sessionProjection {
|
||||
p := new(sessionProjection)
|
||||
config.ProjectionName = SessionsProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewMultiTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(SessionColumnID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SessionColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(SessionColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(SessionColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(SessionColumnState, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(SessionColumnResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SessionColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SessionColumnCreator, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SessionColumnUserID, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(SessionColumnUserCheckedAt, crdb.ColumnTypeTimestamp, crdb.Nullable()),
|
||||
crdb.NewColumn(SessionColumnPasswordCheckedAt, crdb.ColumnTypeTimestamp, crdb.Nullable()),
|
||||
crdb.NewColumn(SessionColumnIntentCheckedAt, crdb.ColumnTypeTimestamp, crdb.Nullable()),
|
||||
crdb.NewColumn(SessionColumnWebAuthNCheckedAt, crdb.ColumnTypeTimestamp, crdb.Nullable()),
|
||||
crdb.NewColumn(SessionColumnWebAuthNUserVerified, crdb.ColumnTypeBool, crdb.Nullable()),
|
||||
crdb.NewColumn(SessionColumnTOTPCheckedAt, crdb.ColumnTypeTimestamp, crdb.Nullable()),
|
||||
crdb.NewColumn(SessionColumnOTPSMSCheckedAt, crdb.ColumnTypeTimestamp, crdb.Nullable()),
|
||||
crdb.NewColumn(SessionColumnOTPEmailCheckedAt, crdb.ColumnTypeTimestamp, crdb.Nullable()),
|
||||
crdb.NewColumn(SessionColumnMetadata, crdb.ColumnTypeJSONB, crdb.Nullable()),
|
||||
crdb.NewColumn(SessionColumnTokenID, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
func (*sessionProjection) Name() string {
|
||||
return SessionsProjectionTable
|
||||
}
|
||||
|
||||
func (*sessionProjection) Init() *old_handler.Check {
|
||||
return handler.NewMultiTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(SessionColumnID, handler.ColumnTypeText),
|
||||
handler.NewColumn(SessionColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(SessionColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(SessionColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(SessionColumnState, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(SessionColumnResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(SessionColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(SessionColumnCreator, handler.ColumnTypeText),
|
||||
handler.NewColumn(SessionColumnUserID, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(SessionColumnUserCheckedAt, handler.ColumnTypeTimestamp, handler.Nullable()),
|
||||
handler.NewColumn(SessionColumnPasswordCheckedAt, handler.ColumnTypeTimestamp, handler.Nullable()),
|
||||
handler.NewColumn(SessionColumnIntentCheckedAt, handler.ColumnTypeTimestamp, handler.Nullable()),
|
||||
handler.NewColumn(SessionColumnWebAuthNCheckedAt, handler.ColumnTypeTimestamp, handler.Nullable()),
|
||||
handler.NewColumn(SessionColumnWebAuthNUserVerified, handler.ColumnTypeBool, handler.Nullable()),
|
||||
handler.NewColumn(SessionColumnTOTPCheckedAt, handler.ColumnTypeTimestamp, handler.Nullable()),
|
||||
handler.NewColumn(SessionColumnOTPSMSCheckedAt, handler.ColumnTypeTimestamp, handler.Nullable()),
|
||||
handler.NewColumn(SessionColumnOTPEmailCheckedAt, handler.ColumnTypeTimestamp, handler.Nullable()),
|
||||
handler.NewColumn(SessionColumnMetadata, handler.ColumnTypeJSONB, handler.Nullable()),
|
||||
handler.NewColumn(SessionColumnTokenID, handler.ColumnTypeText, handler.Nullable()),
|
||||
},
|
||||
crdb.NewPrimaryKey(SessionColumnInstanceID, SessionColumnID),
|
||||
handler.NewPrimaryKey(SessionColumnInstanceID, SessionColumnID),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *sessionProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *sessionProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: session.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: session.AddedType,
|
||||
Reduce: p.reduceSessionAdded,
|
||||
@@ -127,7 +128,7 @@ func (p *sessionProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(SMSColumnInstanceID),
|
||||
@@ -136,7 +137,7 @@ func (p *sessionProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: user.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: user.HumanPasswordChangedType,
|
||||
Reduce: p.reducePasswordChanged,
|
||||
@@ -152,7 +153,7 @@ func (p *sessionProjection) reduceSessionAdded(event eventstore.Event) (*handler
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Sfrgf", "reduce.wrong.event.type %s", session.AddedType)
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SessionColumnID, e.Aggregate().ID),
|
||||
@@ -172,7 +173,7 @@ func (p *sessionProjection) reduceUserChecked(event eventstore.Event) (*handler.
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-saDg5", "reduce.wrong.event.type %s", session.UserCheckedType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SessionColumnChangeDate, e.CreationDate()),
|
||||
@@ -193,7 +194,7 @@ func (p *sessionProjection) reducePasswordChecked(event eventstore.Event) (*hand
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-SDgrb", "reduce.wrong.event.type %s", session.PasswordCheckedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SessionColumnChangeDate, e.CreationDate()),
|
||||
@@ -213,7 +214,7 @@ func (p *sessionProjection) reduceIntentChecked(event eventstore.Event) (*handle
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-SDgr2", "reduce.wrong.event.type %s", session.IntentCheckedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SessionColumnChangeDate, e.CreationDate()),
|
||||
@@ -232,7 +233,7 @@ func (p *sessionProjection) reduceWebAuthNChecked(event eventstore.Event) (*hand
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-WieM4", "reduce.wrong.event.type %s", session.WebAuthNCheckedType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SessionColumnChangeDate, e.CreationDate()),
|
||||
@@ -253,7 +254,7 @@ func (p *sessionProjection) reduceTOTPChecked(event eventstore.Event) (*handler.
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Oqu8i", "reduce.wrong.event.type %s", session.TOTPCheckedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SessionColumnChangeDate, e.CreationDate()),
|
||||
@@ -273,7 +274,7 @@ func (p *sessionProjection) reduceOTPSMSChecked(event eventstore.Event) (*handle
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SessionColumnChangeDate, e.CreationDate()),
|
||||
@@ -293,7 +294,7 @@ func (p *sessionProjection) reduceOTPEmailChecked(event eventstore.Event) (*hand
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SessionColumnChangeDate, e.CreationDate()),
|
||||
@@ -313,7 +314,7 @@ func (p *sessionProjection) reduceTokenSet(event eventstore.Event) (*handler.Sta
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-SAfd3", "reduce.wrong.event.type %s", session.TokenSetType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SessionColumnChangeDate, e.CreationDate()),
|
||||
@@ -333,7 +334,7 @@ func (p *sessionProjection) reduceMetadataSet(event eventstore.Event) (*handler.
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-SAfd3", "reduce.wrong.event.type %s", session.MetadataSetType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SessionColumnChangeDate, e.CreationDate()),
|
||||
@@ -353,7 +354,7 @@ func (p *sessionProjection) reduceSessionTerminated(event eventstore.Event) (*ha
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-SAftn", "reduce.wrong.event.type %s", session.TerminateType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(SessionColumnID, e.Aggregate().ID),
|
||||
@@ -368,14 +369,14 @@ func (p *sessionProjection) reducePasswordChanged(event eventstore.Event) (*hand
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Deg3d", "reduce.wrong.event.type %s", user.HumanPasswordChangedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SessionColumnPasswordCheckedAt, nil),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(SessionColumnUserID, e.Aggregate().ID),
|
||||
crdb.NewLessThanCond(SessionColumnPasswordCheckedAt, e.CreationDate()),
|
||||
handler.NewLessThanCond(SessionColumnPasswordCheckedAt, e.CreationDate()),
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/session"
|
||||
"github.com/zitadel/zitadel/internal/repository/user"
|
||||
@@ -37,9 +36,8 @@ func TestSessionProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&sessionProjection{}).reduceSessionAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("session"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("session"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -73,9 +71,8 @@ func TestSessionProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&sessionProjection{}).reduceUserChecked,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("session"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("session"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -106,9 +103,8 @@ func TestSessionProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&sessionProjection{}).reducePasswordChecked,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("session"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("session"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -139,9 +135,8 @@ func TestSessionProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&sessionProjection{}).reduceWebAuthNChecked,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("session"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("session"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -172,9 +167,8 @@ func TestSessionProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&sessionProjection{}).reduceIntentChecked,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("session"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("session"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -204,9 +198,8 @@ func TestSessionProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&sessionProjection{}).reduceTOTPChecked,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("session"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("session"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -236,9 +229,8 @@ func TestSessionProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&sessionProjection{}).reduceTokenSet,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("session"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("session"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -270,9 +262,8 @@ func TestSessionProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&sessionProjection{}).reduceMetadataSet,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("session"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("session"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -302,9 +293,8 @@ func TestSessionProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&sessionProjection{}).reduceSessionTerminated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("session"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("session"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -321,17 +311,17 @@ func TestSessionProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(SessionColumnInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -348,7 +338,7 @@ func TestSessionProjection_reduces(t *testing.T) {
|
||||
name: "reducePasswordChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.HumanPasswordChangedType),
|
||||
user.HumanPasswordChangedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{"secret": {
|
||||
"cryptoType": 0,
|
||||
@@ -360,9 +350,8 @@ func TestSessionProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&sessionProjection{}).reducePasswordChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("user"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("user"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
@@ -32,48 +32,49 @@ const (
|
||||
SMSTwilioConfigColumnToken = "token"
|
||||
)
|
||||
|
||||
type smsConfigProjection struct {
|
||||
crdb.StatementHandler
|
||||
type smsConfigProjection struct{}
|
||||
|
||||
func newSMSConfigProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(smsConfigProjection))
|
||||
}
|
||||
|
||||
func newSMSConfigProjection(ctx context.Context, config crdb.StatementHandlerConfig) *smsConfigProjection {
|
||||
p := new(smsConfigProjection)
|
||||
config.ProjectionName = SMSConfigProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewMultiTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(SMSColumnID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMSColumnAggregateID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMSColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(SMSColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(SMSColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(SMSColumnState, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(SMSColumnResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMSColumnInstanceID, crdb.ColumnTypeText),
|
||||
func (*smsConfigProjection) Name() string {
|
||||
return SMSConfigProjectionTable
|
||||
}
|
||||
|
||||
func (*smsConfigProjection) Init() *old_handler.Check {
|
||||
return handler.NewMultiTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(SMSColumnID, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMSColumnAggregateID, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMSColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(SMSColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(SMSColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(SMSColumnState, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(SMSColumnResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMSColumnInstanceID, handler.ColumnTypeText),
|
||||
},
|
||||
crdb.NewPrimaryKey(SMSColumnInstanceID, SMSColumnID),
|
||||
handler.NewPrimaryKey(SMSColumnInstanceID, SMSColumnID),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(SMSTwilioConfigColumnSMSID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMSTwilioColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMSTwilioConfigColumnSID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMSTwilioConfigColumnSenderNumber, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMSTwilioConfigColumnToken, crdb.ColumnTypeJSONB),
|
||||
handler.NewSuffixedTable([]*handler.InitColumn{
|
||||
handler.NewColumn(SMSTwilioConfigColumnSMSID, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMSTwilioColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMSTwilioConfigColumnSID, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMSTwilioConfigColumnSenderNumber, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMSTwilioConfigColumnToken, handler.ColumnTypeJSONB),
|
||||
},
|
||||
crdb.NewPrimaryKey(SMSTwilioColumnInstanceID, SMSTwilioConfigColumnSMSID),
|
||||
handler.NewPrimaryKey(SMSTwilioColumnInstanceID, SMSTwilioConfigColumnSMSID),
|
||||
smsTwilioTableSuffix,
|
||||
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
|
||||
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *smsConfigProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *smsConfigProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.SMSConfigTwilioAddedEventType,
|
||||
Reduce: p.reduceSMSConfigTwilioAdded,
|
||||
@@ -113,9 +114,9 @@ func (p *smsConfigProjection) reduceSMSConfigTwilioAdded(event eventstore.Event)
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-s8efs", "reduce.wrong.event.type %s", instance.SMSConfigTwilioAddedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddCreateStatement(
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(SMSColumnID, e.ID),
|
||||
handler.NewCol(SMSColumnAggregateID, e.Aggregate().ID),
|
||||
@@ -127,7 +128,7 @@ func (p *smsConfigProjection) reduceSMSConfigTwilioAdded(event eventstore.Event)
|
||||
handler.NewCol(SMSColumnSequence, e.Sequence()),
|
||||
},
|
||||
),
|
||||
crdb.AddCreateStatement(
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(SMSTwilioConfigColumnSMSID, e.ID),
|
||||
handler.NewCol(SMSTwilioColumnInstanceID, e.Aggregate().InstanceID),
|
||||
@@ -135,7 +136,7 @@ func (p *smsConfigProjection) reduceSMSConfigTwilioAdded(event eventstore.Event)
|
||||
handler.NewCol(SMSTwilioConfigColumnToken, e.Token),
|
||||
handler.NewCol(SMSTwilioConfigColumnSenderNumber, e.SenderNumber),
|
||||
},
|
||||
crdb.WithTableSuffix(smsTwilioTableSuffix),
|
||||
handler.WithTableSuffix(smsTwilioTableSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -153,17 +154,17 @@ func (p *smsConfigProjection) reduceSMSConfigTwilioChanged(event eventstore.Even
|
||||
columns = append(columns, handler.NewCol(SMSTwilioConfigColumnSenderNumber, *e.SenderNumber))
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
columns,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(SMSTwilioConfigColumnSMSID, e.ID),
|
||||
handler.NewCond(SMSTwilioColumnInstanceID, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(smsTwilioTableSuffix),
|
||||
handler.WithTableSuffix(smsTwilioTableSuffix),
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(SMSColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(SMSColumnSequence, e.Sequence()),
|
||||
@@ -186,17 +187,17 @@ func (p *smsConfigProjection) reduceSMSConfigTwilioTokenChanged(event eventstore
|
||||
columns = append(columns, handler.NewCol(SMSTwilioConfigColumnToken, e.Token))
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
columns,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(SMSTwilioConfigColumnSMSID, e.ID),
|
||||
handler.NewCond(SMSTwilioColumnInstanceID, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(smsTwilioTableSuffix),
|
||||
handler.WithTableSuffix(smsTwilioTableSuffix),
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(SMSColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(SMSColumnSequence, e.Sequence()),
|
||||
@@ -214,7 +215,7 @@ func (p *smsConfigProjection) reduceSMSConfigActivated(event eventstore.Event) (
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-fj9Ef", "reduce.wrong.event.type %s", instance.SMSConfigActivatedEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SMSColumnState, domain.SMSConfigStateActive),
|
||||
@@ -233,7 +234,7 @@ func (p *smsConfigProjection) reduceSMSConfigDeactivated(event eventstore.Event)
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-dj9Js", "reduce.wrong.event.type %s", instance.SMSConfigDeactivatedEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SMSColumnState, domain.SMSConfigStateInactive),
|
||||
@@ -252,7 +253,7 @@ func (p *smsConfigProjection) reduceSMSConfigRemoved(event eventstore.Event) (*h
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-s9JJf", "reduce.wrong.event.type %s", instance.SMSConfigRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(SMSColumnID, e.ID),
|
||||
|
||||
@@ -7,8 +7,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
@@ -25,10 +24,11 @@ func TestSMSProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceSMSTwilioAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.SMSConfigTwilioAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SMSConfigTwilioAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "id",
|
||||
"sid": "sid",
|
||||
"token": {
|
||||
@@ -39,13 +39,12 @@ func TestSMSProjection_reduces(t *testing.T) {
|
||||
},
|
||||
"senderNumber": "sender-number"
|
||||
}`),
|
||||
), instance.SMSConfigTwilioAddedEventMapper),
|
||||
), instance.SMSConfigTwilioAddedEventMapper),
|
||||
},
|
||||
reduce: (&smsConfigProjection{}).reduceSMSConfigTwilioAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -83,21 +82,21 @@ func TestSMSProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceSMSConfigTwilioChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.SMSConfigTwilioChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SMSConfigTwilioChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "id",
|
||||
"sid": "sid",
|
||||
"senderNumber": "sender-number"
|
||||
}`),
|
||||
), instance.SMSConfigTwilioChangedEventMapper),
|
||||
), instance.SMSConfigTwilioChangedEventMapper),
|
||||
},
|
||||
reduce: (&smsConfigProjection{}).reduceSMSConfigTwilioChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -125,10 +124,11 @@ func TestSMSProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceSMSConfigTwilioTokenChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.SMSConfigTwilioTokenChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SMSConfigTwilioTokenChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "id",
|
||||
"token": {
|
||||
"cryptoType": 0,
|
||||
@@ -137,13 +137,12 @@ func TestSMSProjection_reduces(t *testing.T) {
|
||||
"crypted": "Y3J5cHRlZA=="
|
||||
}
|
||||
}`),
|
||||
), instance.SMSConfigTwilioTokenChangedEventMapper),
|
||||
), instance.SMSConfigTwilioTokenChangedEventMapper),
|
||||
},
|
||||
reduce: (&smsConfigProjection{}).reduceSMSConfigTwilioTokenChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -175,19 +174,19 @@ func TestSMSProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceSMSConfigActivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.SMSConfigActivatedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SMSConfigActivatedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "id"
|
||||
}`),
|
||||
), instance.SMSConfigActivatedEventMapper),
|
||||
), instance.SMSConfigActivatedEventMapper),
|
||||
},
|
||||
reduce: (&smsConfigProjection{}).reduceSMSConfigActivated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -207,19 +206,19 @@ func TestSMSProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceSMSConfigDeactivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.SMSConfigDeactivatedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SMSConfigDeactivatedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "id"
|
||||
}`),
|
||||
), instance.SMSConfigDeactivatedEventMapper),
|
||||
), instance.SMSConfigDeactivatedEventMapper),
|
||||
},
|
||||
reduce: (&smsConfigProjection{}).reduceSMSConfigDeactivated,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -239,19 +238,19 @@ func TestSMSProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceSMSConfigRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.SMSConfigRemovedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SMSConfigRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "id"
|
||||
}`),
|
||||
), instance.SMSConfigRemovedEventMapper),
|
||||
), instance.SMSConfigRemovedEventMapper),
|
||||
},
|
||||
reduce: (&smsConfigProjection{}).reduceSMSConfigRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -268,17 +267,17 @@ func TestSMSProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(SMSColumnInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
@@ -28,42 +28,43 @@ const (
|
||||
SMTPConfigColumnSMTPPassword = "password"
|
||||
)
|
||||
|
||||
type smtpConfigProjection struct {
|
||||
crdb.StatementHandler
|
||||
type smtpConfigProjection struct{}
|
||||
|
||||
func newSMTPConfigProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(smtpConfigProjection))
|
||||
}
|
||||
|
||||
func newSMTPConfigProjection(ctx context.Context, config crdb.StatementHandlerConfig) *smtpConfigProjection {
|
||||
p := new(smtpConfigProjection)
|
||||
config.ProjectionName = SMTPConfigProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(SMTPConfigColumnAggregateID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMTPConfigColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(SMTPConfigColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(SMTPConfigColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(SMTPConfigColumnResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMTPConfigColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMTPConfigColumnTLS, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(SMTPConfigColumnSenderAddress, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMTPConfigColumnSenderName, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMTPConfigColumnReplyToAddress, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMTPConfigColumnSMTPHost, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMTPConfigColumnSMTPUser, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMTPConfigColumnSMTPPassword, crdb.ColumnTypeJSONB, crdb.Nullable()),
|
||||
func (*smtpConfigProjection) Name() string {
|
||||
return SMTPConfigProjectionTable
|
||||
}
|
||||
|
||||
func (*smtpConfigProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(SMTPConfigColumnAggregateID, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(SMTPConfigColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(SMTPConfigColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(SMTPConfigColumnResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigColumnTLS, handler.ColumnTypeBool),
|
||||
handler.NewColumn(SMTPConfigColumnSenderAddress, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigColumnSenderName, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigColumnReplyToAddress, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigColumnSMTPHost, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigColumnSMTPUser, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigColumnSMTPPassword, handler.ColumnTypeJSONB, handler.Nullable()),
|
||||
},
|
||||
crdb.NewPrimaryKey(SMTPConfigColumnInstanceID, SMTPConfigColumnAggregateID),
|
||||
handler.NewPrimaryKey(SMTPConfigColumnInstanceID, SMTPConfigColumnAggregateID),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *smtpConfigProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *smtpConfigProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.SMTPConfigAddedEventType,
|
||||
Reduce: p.reduceSMTPConfigAdded,
|
||||
@@ -94,7 +95,7 @@ func (p *smtpConfigProjection) reduceSMTPConfigAdded(event eventstore.Event) (*h
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-sk99F", "reduce.wrong.event.type %s", instance.SMTPConfigAddedEventType)
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SMTPConfigColumnAggregateID, e.Aggregate().ID),
|
||||
@@ -141,7 +142,7 @@ func (p *smtpConfigProjection) reduceSMTPConfigChanged(event eventstore.Event) (
|
||||
if e.User != nil {
|
||||
columns = append(columns, handler.NewCol(SMTPConfigColumnSMTPUser, *e.User))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
columns,
|
||||
[]handler.Condition{
|
||||
@@ -157,7 +158,7 @@ func (p *smtpConfigProjection) reduceSMTPConfigPasswordChanged(event eventstore.
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-fk02f", "reduce.wrong.event.type %s", instance.SMTPConfigChangedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SMTPConfigColumnChangeDate, e.CreationDate()),
|
||||
@@ -176,7 +177,7 @@ func (p *smtpConfigProjection) reduceSMTPConfigRemoved(event eventstore.Event) (
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(SMTPConfigColumnAggregateID, e.Aggregate().ID),
|
||||
|
||||
@@ -5,8 +5,7 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
@@ -23,10 +22,11 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceSMTPConfigChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.SMTPConfigChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SMTPConfigChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"tls": true,
|
||||
"senderAddress": "sender",
|
||||
"senderName": "name",
|
||||
@@ -34,14 +34,13 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
"host": "host",
|
||||
"user": "user"
|
||||
}`,
|
||||
),
|
||||
), instance.SMTPConfigChangedEventMapper),
|
||||
),
|
||||
), instance.SMTPConfigChangedEventMapper),
|
||||
},
|
||||
reduce: (&smtpConfigProjection{}).reduceSMTPConfigChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -66,10 +65,11 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceSMTPConfigAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.SMTPConfigAddedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SMTPConfigAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"tls": true,
|
||||
"senderAddress": "sender",
|
||||
"senderName": "name",
|
||||
@@ -82,13 +82,12 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
"keyId": "key-id"
|
||||
}
|
||||
}`),
|
||||
), instance.SMTPConfigAddedEventMapper),
|
||||
), instance.SMTPConfigAddedEventMapper),
|
||||
},
|
||||
reduce: (&smtpConfigProjection{}).reduceSMTPConfigAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -116,23 +115,23 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceSMTPConfigPasswordChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.SMTPConfigPasswordChangedEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SMTPConfigPasswordChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"password": {
|
||||
"cryptoType": 0,
|
||||
"algorithm": "RSA-265",
|
||||
"keyId": "key-id"
|
||||
}
|
||||
}`),
|
||||
), instance.SMTPConfigPasswordChangedEventMapper),
|
||||
), instance.SMTPConfigPasswordChangedEventMapper),
|
||||
},
|
||||
reduce: (&smtpConfigProjection{}).reduceSMTPConfigPasswordChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -153,16 +152,15 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
name: "reduceSMTPConfigRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.SMTPConfigRemovedEventType),
|
||||
instance.SMTPConfigRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{}`),
|
||||
), instance.SMTPConfigRemovedEventMapper),
|
||||
},
|
||||
reduce: (&smtpConfigProjection{}).reduceSMTPConfigRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -179,17 +177,17 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(SMTPConfigColumnInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
+165
-164
@@ -7,17 +7,13 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/user"
|
||||
)
|
||||
|
||||
type userProjection struct {
|
||||
crdb.StatementHandler
|
||||
}
|
||||
|
||||
const (
|
||||
UserTable = "projections.users8"
|
||||
UserHumanTable = UserTable + "_" + UserHumanSuffix
|
||||
@@ -76,82 +72,87 @@ const (
|
||||
NotifyPasswordSetCol = "password_set"
|
||||
)
|
||||
|
||||
func newUserProjection(ctx context.Context, config crdb.StatementHandlerConfig) *userProjection {
|
||||
p := new(userProjection)
|
||||
config.ProjectionName = UserTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewMultiTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(UserIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(UserChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(UserSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(UserStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(UserResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserUsernameCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserTypeCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(UserOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(UserInstanceIDCol, UserIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("username", []string{UserUsernameCol})),
|
||||
crdb.WithIndex(crdb.NewIndex("resource_owner", []string{UserResourceOwnerCol})),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{UserOwnerRemovedCol})),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(HumanUserIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(HumanUserInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(HumanFirstNameCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(HumanLastNameCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(HumanNickNameCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(HumanDisplayNameCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(HumanPreferredLanguageCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(HumanGenderCol, crdb.ColumnTypeEnum, crdb.Nullable()),
|
||||
crdb.NewColumn(HumanAvatarURLCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(HumanEmailCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(HumanIsEmailVerifiedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(HumanPhoneCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(HumanIsPhoneVerifiedCol, crdb.ColumnTypeBool, crdb.Nullable()),
|
||||
},
|
||||
crdb.NewPrimaryKey(HumanUserInstanceIDCol, HumanUserIDCol),
|
||||
UserHumanSuffix,
|
||||
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(MachineUserIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(MachineUserInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(MachineNameCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(MachineDescriptionCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(MachineHasSecretCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(MachineAccessTokenTypeCol, crdb.ColumnTypeEnum, crdb.Default(0)),
|
||||
},
|
||||
crdb.NewPrimaryKey(MachineUserInstanceIDCol, MachineUserIDCol),
|
||||
UserMachineSuffix,
|
||||
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
|
||||
),
|
||||
crdb.NewSuffixedTable([]*crdb.Column{
|
||||
crdb.NewColumn(NotifyUserIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(NotifyInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(NotifyLastEmailCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(NotifyVerifiedEmailCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(NotifyLastPhoneCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(NotifyVerifiedPhoneCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(NotifyPasswordSetCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(NotifyInstanceIDCol, NotifyUserIDCol),
|
||||
UserNotifySuffix,
|
||||
crdb.WithForeignKey(crdb.NewForeignKeyOfPublicKeys()),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
type userProjection struct{}
|
||||
|
||||
func newUserProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(userProjection))
|
||||
}
|
||||
|
||||
func (p *userProjection) reducers() []handler.AggregateReducer {
|
||||
func (*userProjection) Name() string {
|
||||
return UserTable
|
||||
}
|
||||
|
||||
func (*userProjection) Init() *old_handler.Check {
|
||||
return handler.NewMultiTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(UserIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(UserChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(UserSequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(UserStateCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(UserResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserUsernameCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserTypeCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(UserOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
handler.NewPrimaryKey(UserInstanceIDCol, UserIDCol),
|
||||
handler.WithIndex(handler.NewIndex("username", []string{UserUsernameCol})),
|
||||
handler.WithIndex(handler.NewIndex("resource_owner", []string{UserResourceOwnerCol})),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{UserOwnerRemovedCol})),
|
||||
),
|
||||
handler.NewSuffixedTable([]*handler.InitColumn{
|
||||
handler.NewColumn(HumanUserIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(HumanUserInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(HumanFirstNameCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(HumanLastNameCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(HumanNickNameCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(HumanDisplayNameCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(HumanPreferredLanguageCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(HumanGenderCol, handler.ColumnTypeEnum, handler.Nullable()),
|
||||
handler.NewColumn(HumanAvatarURLCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(HumanEmailCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(HumanIsEmailVerifiedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(HumanPhoneCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(HumanIsPhoneVerifiedCol, handler.ColumnTypeBool, handler.Nullable()),
|
||||
},
|
||||
handler.NewPrimaryKey(HumanUserInstanceIDCol, HumanUserIDCol),
|
||||
UserHumanSuffix,
|
||||
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
|
||||
),
|
||||
handler.NewSuffixedTable([]*handler.InitColumn{
|
||||
handler.NewColumn(MachineUserIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(MachineUserInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(MachineNameCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(MachineDescriptionCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(MachineHasSecretCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(MachineAccessTokenTypeCol, handler.ColumnTypeEnum, handler.Default(0)),
|
||||
},
|
||||
handler.NewPrimaryKey(MachineUserInstanceIDCol, MachineUserIDCol),
|
||||
UserMachineSuffix,
|
||||
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
|
||||
),
|
||||
handler.NewSuffixedTable([]*handler.InitColumn{
|
||||
handler.NewColumn(NotifyUserIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(NotifyInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(NotifyLastEmailCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(NotifyVerifiedEmailCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(NotifyLastPhoneCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(NotifyVerifiedPhoneCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(NotifyPasswordSetCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
handler.NewPrimaryKey(NotifyInstanceIDCol, NotifyUserIDCol),
|
||||
UserNotifySuffix,
|
||||
handler.WithForeignKey(handler.NewForeignKeyOfPublicKeys()),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
func (p *userProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: user.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: user.UserV1AddedType,
|
||||
Reduce: p.reduceHumanAdded,
|
||||
@@ -292,7 +293,7 @@ func (p *userProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.OrgRemovedEventType,
|
||||
Reduce: p.reduceOwnerRemoved,
|
||||
@@ -301,7 +302,7 @@ func (p *userProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(UserInstanceIDCol),
|
||||
@@ -316,9 +317,9 @@ func (p *userProjection) reduceHumanAdded(event eventstore.Event) (*handler.Stat
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Ebynp", "reduce.wrong.event.type %s", user.HumanAddedType)
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddCreateStatement(
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserIDCol, e.Aggregate().ID),
|
||||
handler.NewCol(UserCreationDateCol, e.CreationDate()),
|
||||
@@ -331,7 +332,7 @@ func (p *userProjection) reduceHumanAdded(event eventstore.Event) (*handler.Stat
|
||||
handler.NewCol(UserTypeCol, domain.UserTypeHuman),
|
||||
},
|
||||
),
|
||||
crdb.AddCreateStatement(
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(HumanUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCol(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
@@ -344,9 +345,9 @@ func (p *userProjection) reduceHumanAdded(event eventstore.Event) (*handler.Stat
|
||||
handler.NewCol(HumanEmailCol, e.EmailAddress),
|
||||
handler.NewCol(HumanPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
|
||||
},
|
||||
crdb.WithTableSuffix(UserHumanSuffix),
|
||||
handler.WithTableSuffix(UserHumanSuffix),
|
||||
),
|
||||
crdb.AddCreateStatement(
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(NotifyUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCol(NotifyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
@@ -354,7 +355,7 @@ func (p *userProjection) reduceHumanAdded(event eventstore.Event) (*handler.Stat
|
||||
handler.NewCol(NotifyLastPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
|
||||
handler.NewCol(NotifyPasswordSetCol, user.SecretOrEncodedHash(e.Secret, e.EncodedHash) != ""),
|
||||
},
|
||||
crdb.WithTableSuffix(UserNotifySuffix),
|
||||
handler.WithTableSuffix(UserNotifySuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -364,9 +365,9 @@ func (p *userProjection) reduceHumanRegistered(event eventstore.Event) (*handler
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-xE53M", "reduce.wrong.event.type %s", user.HumanRegisteredType)
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddCreateStatement(
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserIDCol, e.Aggregate().ID),
|
||||
handler.NewCol(UserCreationDateCol, e.CreationDate()),
|
||||
@@ -379,7 +380,7 @@ func (p *userProjection) reduceHumanRegistered(event eventstore.Event) (*handler
|
||||
handler.NewCol(UserTypeCol, domain.UserTypeHuman),
|
||||
},
|
||||
),
|
||||
crdb.AddCreateStatement(
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(HumanUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCol(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
@@ -392,9 +393,9 @@ func (p *userProjection) reduceHumanRegistered(event eventstore.Event) (*handler
|
||||
handler.NewCol(HumanEmailCol, e.EmailAddress),
|
||||
handler.NewCol(HumanPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
|
||||
},
|
||||
crdb.WithTableSuffix(UserHumanSuffix),
|
||||
handler.WithTableSuffix(UserHumanSuffix),
|
||||
),
|
||||
crdb.AddCreateStatement(
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(NotifyUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCol(NotifyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
@@ -402,7 +403,7 @@ func (p *userProjection) reduceHumanRegistered(event eventstore.Event) (*handler
|
||||
handler.NewCol(NotifyLastPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
|
||||
handler.NewCol(NotifyPasswordSetCol, user.SecretOrEncodedHash(e.Secret, e.EncodedHash) != ""),
|
||||
},
|
||||
crdb.WithTableSuffix(UserNotifySuffix),
|
||||
handler.WithTableSuffix(UserNotifySuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -412,7 +413,7 @@ func (p *userProjection) reduceHumanInitCodeAdded(event eventstore.Event) (*hand
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Dvgws", "reduce.wrong.event.type %s", user.HumanInitialCodeAddedType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserStateCol, domain.UserStateInitial),
|
||||
@@ -429,7 +430,7 @@ func (p *userProjection) reduceHumanInitCodeSucceeded(event eventstore.Event) (*
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Dfvwq", "reduce.wrong.event.type %s", user.HumanInitializedCheckSucceededType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserStateCol, domain.UserStateActive),
|
||||
@@ -447,7 +448,7 @@ func (p *userProjection) reduceUserLocked(event eventstore.Event) (*handler.Stat
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-exyBF", "reduce.wrong.event.type %s", user.UserLockedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
||||
@@ -467,7 +468,7 @@ func (p *userProjection) reduceUserUnlocked(event eventstore.Event) (*handler.St
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-JIyRl", "reduce.wrong.event.type %s", user.UserUnlockedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
||||
@@ -487,7 +488,7 @@ func (p *userProjection) reduceUserDeactivated(event eventstore.Event) (*handler
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-6BNjj", "reduce.wrong.event.type %s", user.UserDeactivatedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
||||
@@ -507,7 +508,7 @@ func (p *userProjection) reduceUserReactivated(event eventstore.Event) (*handler
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-IoF6j", "reduce.wrong.event.type %s", user.UserReactivatedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
||||
@@ -527,7 +528,7 @@ func (p *userProjection) reduceUserRemoved(event eventstore.Event) (*handler.Sta
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-BQB2t", "reduce.wrong.event.type %s", user.UserRemovedType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(UserIDCol, e.Aggregate().ID),
|
||||
@@ -542,7 +543,7 @@ func (p *userProjection) reduceUserNameChanged(event eventstore.Event) (*handler
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-QNKyV", "reduce.wrong.event.type %s", user.UserUserNameChangedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
||||
@@ -562,7 +563,7 @@ func (p *userProjection) reduceDomainClaimed(event eventstore.Event) (*handler.S
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-ASwf3", "reduce.wrong.event.type %s", user.UserDomainClaimedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
||||
@@ -606,9 +607,9 @@ func (p *userProjection) reduceHumanProfileChanged(event eventstore.Event) (*han
|
||||
cols = append(cols, handler.NewCol(HumanGenderCol, *e.Gender))
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(UserSequenceCol, e.Sequence()),
|
||||
@@ -618,13 +619,13 @@ func (p *userProjection) reduceHumanProfileChanged(event eventstore.Event) (*han
|
||||
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(UserHumanSuffix),
|
||||
handler.WithTableSuffix(UserHumanSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -635,9 +636,9 @@ func (p *userProjection) reduceHumanPhoneChanged(event eventstore.Event) (*handl
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-xOGIA", "reduce.wrong.event.type %s", user.HumanPhoneChangedType)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(UserSequenceCol, e.Sequence()),
|
||||
@@ -647,7 +648,7 @@ func (p *userProjection) reduceHumanPhoneChanged(event eventstore.Event) (*handl
|
||||
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(HumanPhoneCol, e.PhoneNumber),
|
||||
handler.NewCol(HumanIsPhoneVerifiedCol, false),
|
||||
@@ -656,9 +657,9 @@ func (p *userProjection) reduceHumanPhoneChanged(event eventstore.Event) (*handl
|
||||
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(UserHumanSuffix),
|
||||
handler.WithTableSuffix(UserHumanSuffix),
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(NotifyLastPhoneCol, &sql.NullString{String: string(e.PhoneNumber), Valid: e.PhoneNumber != ""}),
|
||||
},
|
||||
@@ -666,7 +667,7 @@ func (p *userProjection) reduceHumanPhoneChanged(event eventstore.Event) (*handl
|
||||
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(NotifyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(UserNotifySuffix),
|
||||
handler.WithTableSuffix(UserNotifySuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -677,9 +678,9 @@ func (p *userProjection) reduceHumanPhoneRemoved(event eventstore.Event) (*handl
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-JI4S1", "reduce.wrong.event.type %s", user.HumanPhoneRemovedType)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(UserSequenceCol, e.Sequence()),
|
||||
@@ -689,7 +690,7 @@ func (p *userProjection) reduceHumanPhoneRemoved(event eventstore.Event) (*handl
|
||||
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(HumanPhoneCol, nil),
|
||||
handler.NewCol(HumanIsPhoneVerifiedCol, nil),
|
||||
@@ -698,9 +699,9 @@ func (p *userProjection) reduceHumanPhoneRemoved(event eventstore.Event) (*handl
|
||||
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(UserHumanSuffix),
|
||||
handler.WithTableSuffix(UserHumanSuffix),
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(NotifyLastPhoneCol, nil),
|
||||
handler.NewCol(NotifyVerifiedPhoneCol, nil),
|
||||
@@ -709,7 +710,7 @@ func (p *userProjection) reduceHumanPhoneRemoved(event eventstore.Event) (*handl
|
||||
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(NotifyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(UserNotifySuffix),
|
||||
handler.WithTableSuffix(UserNotifySuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -720,9 +721,9 @@ func (p *userProjection) reduceHumanPhoneVerified(event eventstore.Event) (*hand
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-LBnqG", "reduce.wrong.event.type %s", user.HumanPhoneVerifiedType)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(UserSequenceCol, e.Sequence()),
|
||||
@@ -732,7 +733,7 @@ func (p *userProjection) reduceHumanPhoneVerified(event eventstore.Event) (*hand
|
||||
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(HumanIsPhoneVerifiedCol, true),
|
||||
},
|
||||
@@ -740,17 +741,17 @@ func (p *userProjection) reduceHumanPhoneVerified(event eventstore.Event) (*hand
|
||||
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(UserHumanSuffix),
|
||||
handler.WithTableSuffix(UserHumanSuffix),
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
crdb.NewCopyCol(NotifyVerifiedPhoneCol, NotifyLastPhoneCol),
|
||||
handler.NewCopyCol(NotifyVerifiedPhoneCol, NotifyLastPhoneCol),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(NotifyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(UserNotifySuffix),
|
||||
handler.WithTableSuffix(UserNotifySuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -761,9 +762,9 @@ func (p *userProjection) reduceHumanEmailChanged(event eventstore.Event) (*handl
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-KwiHa", "reduce.wrong.event.type %s", user.HumanEmailChangedType)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(UserSequenceCol, e.Sequence()),
|
||||
@@ -773,7 +774,7 @@ func (p *userProjection) reduceHumanEmailChanged(event eventstore.Event) (*handl
|
||||
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(HumanEmailCol, e.EmailAddress),
|
||||
handler.NewCol(HumanIsEmailVerifiedCol, false),
|
||||
@@ -782,9 +783,9 @@ func (p *userProjection) reduceHumanEmailChanged(event eventstore.Event) (*handl
|
||||
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(UserHumanSuffix),
|
||||
handler.WithTableSuffix(UserHumanSuffix),
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(NotifyLastEmailCol, &sql.NullString{String: string(e.EmailAddress), Valid: e.EmailAddress != ""}),
|
||||
},
|
||||
@@ -792,7 +793,7 @@ func (p *userProjection) reduceHumanEmailChanged(event eventstore.Event) (*handl
|
||||
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(NotifyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(UserNotifySuffix),
|
||||
handler.WithTableSuffix(UserNotifySuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -803,9 +804,9 @@ func (p *userProjection) reduceHumanEmailVerified(event eventstore.Event) (*hand
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-JzcDq", "reduce.wrong.event.type %s", user.HumanEmailVerifiedType)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(UserSequenceCol, e.Sequence()),
|
||||
@@ -815,7 +816,7 @@ func (p *userProjection) reduceHumanEmailVerified(event eventstore.Event) (*hand
|
||||
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(HumanIsEmailVerifiedCol, true),
|
||||
},
|
||||
@@ -823,17 +824,17 @@ func (p *userProjection) reduceHumanEmailVerified(event eventstore.Event) (*hand
|
||||
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(UserHumanSuffix),
|
||||
handler.WithTableSuffix(UserHumanSuffix),
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
crdb.NewCopyCol(NotifyVerifiedEmailCol, NotifyLastEmailCol),
|
||||
handler.NewCopyCol(NotifyVerifiedEmailCol, NotifyLastEmailCol),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(NotifyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(UserNotifySuffix),
|
||||
handler.WithTableSuffix(UserNotifySuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -844,9 +845,9 @@ func (p *userProjection) reduceHumanAvatarAdded(event eventstore.Event) (*handle
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-eDEdt", "reduce.wrong.event.type %s", user.HumanAvatarAddedType)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(UserSequenceCol, e.Sequence()),
|
||||
@@ -856,7 +857,7 @@ func (p *userProjection) reduceHumanAvatarAdded(event eventstore.Event) (*handle
|
||||
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(HumanAvatarURLCol, e.StoreKey),
|
||||
},
|
||||
@@ -864,7 +865,7 @@ func (p *userProjection) reduceHumanAvatarAdded(event eventstore.Event) (*handle
|
||||
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(UserHumanSuffix),
|
||||
handler.WithTableSuffix(UserHumanSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -875,9 +876,9 @@ func (p *userProjection) reduceHumanAvatarRemoved(event eventstore.Event) (*hand
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-KhETX", "reduce.wrong.event.type %s", user.HumanAvatarRemovedType)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(UserSequenceCol, e.Sequence()),
|
||||
@@ -887,7 +888,7 @@ func (p *userProjection) reduceHumanAvatarRemoved(event eventstore.Event) (*hand
|
||||
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(HumanAvatarURLCol, nil),
|
||||
},
|
||||
@@ -895,7 +896,7 @@ func (p *userProjection) reduceHumanAvatarRemoved(event eventstore.Event) (*hand
|
||||
handler.NewCond(HumanUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(HumanUserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(UserHumanSuffix),
|
||||
handler.WithTableSuffix(UserHumanSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -906,7 +907,7 @@ func (p *userProjection) reduceHumanPasswordChanged(event eventstore.Event) (*ha
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-jqXUY", "reduce.wrong.event.type %s", user.HumanPasswordChangedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(NotifyPasswordSetCol, true),
|
||||
@@ -915,7 +916,7 @@ func (p *userProjection) reduceHumanPasswordChanged(event eventstore.Event) (*ha
|
||||
handler.NewCond(NotifyUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(NotifyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(UserNotifySuffix),
|
||||
handler.WithTableSuffix(UserNotifySuffix),
|
||||
), nil
|
||||
}
|
||||
|
||||
@@ -924,9 +925,9 @@ func (p *userProjection) reduceMachineSecretSet(event eventstore.Event) (*handle
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-x0p1n1i", "reduce.wrong.event.type %s", user.MachineSecretSetType)
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(UserSequenceCol, e.Sequence()),
|
||||
@@ -936,7 +937,7 @@ func (p *userProjection) reduceMachineSecretSet(event eventstore.Event) (*handle
|
||||
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(MachineHasSecretCol, true),
|
||||
},
|
||||
@@ -944,7 +945,7 @@ func (p *userProjection) reduceMachineSecretSet(event eventstore.Event) (*handle
|
||||
handler.NewCond(MachineUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(MachineUserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(UserMachineSuffix),
|
||||
handler.WithTableSuffix(UserMachineSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -955,9 +956,9 @@ func (p *userProjection) reduceMachineSecretRemoved(event eventstore.Event) (*ha
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-x0p6n1i", "reduce.wrong.event.type %s", user.MachineSecretRemovedType)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(UserSequenceCol, e.Sequence()),
|
||||
@@ -967,7 +968,7 @@ func (p *userProjection) reduceMachineSecretRemoved(event eventstore.Event) (*ha
|
||||
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(MachineHasSecretCol, false),
|
||||
},
|
||||
@@ -975,7 +976,7 @@ func (p *userProjection) reduceMachineSecretRemoved(event eventstore.Event) (*ha
|
||||
handler.NewCond(MachineUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(MachineUserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(UserMachineSuffix),
|
||||
handler.WithTableSuffix(UserMachineSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -986,9 +987,9 @@ func (p *userProjection) reduceMachineAdded(event eventstore.Event) (*handler.St
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-q7ier", "reduce.wrong.event.type %s", user.MachineAddedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddCreateStatement(
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserIDCol, e.Aggregate().ID),
|
||||
handler.NewCol(UserCreationDateCol, e.CreationDate()),
|
||||
@@ -1001,7 +1002,7 @@ func (p *userProjection) reduceMachineAdded(event eventstore.Event) (*handler.St
|
||||
handler.NewCol(UserTypeCol, domain.UserTypeMachine),
|
||||
},
|
||||
),
|
||||
crdb.AddCreateStatement(
|
||||
handler.AddCreateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(MachineUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCol(MachineUserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
@@ -1009,7 +1010,7 @@ func (p *userProjection) reduceMachineAdded(event eventstore.Event) (*handler.St
|
||||
handler.NewCol(MachineDescriptionCol, &sql.NullString{String: e.Description, Valid: e.Description != ""}),
|
||||
handler.NewCol(MachineAccessTokenTypeCol, e.AccessTokenType),
|
||||
},
|
||||
crdb.WithTableSuffix(UserMachineSuffix),
|
||||
handler.WithTableSuffix(UserMachineSuffix),
|
||||
),
|
||||
), nil
|
||||
}
|
||||
@@ -1031,12 +1032,12 @@ func (p *userProjection) reduceMachineChanged(event eventstore.Event) (*handler.
|
||||
cols = append(cols, handler.NewCol(MachineAccessTokenTypeCol, e.AccessTokenType))
|
||||
}
|
||||
if len(cols) == 0 {
|
||||
return crdb.NewNoOpStatement(e), nil
|
||||
return handler.NewNoOpStatement(e), nil
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(UserSequenceCol, e.Sequence()),
|
||||
@@ -1046,13 +1047,13 @@ func (p *userProjection) reduceMachineChanged(event eventstore.Event) (*handler.
|
||||
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(MachineUserIDCol, e.Aggregate().ID),
|
||||
handler.NewCond(MachineUserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
crdb.WithTableSuffix(UserMachineSuffix),
|
||||
handler.WithTableSuffix(UserMachineSuffix),
|
||||
),
|
||||
), nil
|
||||
|
||||
@@ -1064,7 +1065,7 @@ func (p *userProjection) reduceOwnerRemoved(event eventstore.Event) (*handler.St
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-NCsdV", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(UserInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/user"
|
||||
@@ -29,42 +29,43 @@ const (
|
||||
UserAuthMethodOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type userAuthMethodProjection struct {
|
||||
crdb.StatementHandler
|
||||
type userAuthMethodProjection struct{}
|
||||
|
||||
func newUserAuthMethodProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(userAuthMethodProjection))
|
||||
}
|
||||
|
||||
func newUserAuthMethodProjection(ctx context.Context, config crdb.StatementHandlerConfig) *userAuthMethodProjection {
|
||||
p := new(userAuthMethodProjection)
|
||||
config.ProjectionName = UserAuthMethodTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(UserAuthMethodUserIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserAuthMethodTypeCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(UserAuthMethodTokenIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserAuthMethodCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(UserAuthMethodChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(UserAuthMethodSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(UserAuthMethodStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(UserAuthMethodResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserAuthMethodInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserAuthMethodNameCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserAuthMethodOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*userAuthMethodProjection) Name() string {
|
||||
return UserAuthMethodTable
|
||||
}
|
||||
|
||||
func (*userAuthMethodProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(UserAuthMethodUserIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserAuthMethodTypeCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(UserAuthMethodTokenIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserAuthMethodCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(UserAuthMethodChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(UserAuthMethodSequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(UserAuthMethodStateCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(UserAuthMethodResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserAuthMethodInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserAuthMethodNameCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserAuthMethodOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(UserAuthMethodInstanceIDCol, UserAuthMethodUserIDCol, UserAuthMethodTypeCol, UserAuthMethodTokenIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("resource_owner", []string{UserAuthMethodResourceOwnerCol})),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{UserAuthMethodOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(UserAuthMethodInstanceIDCol, UserAuthMethodUserIDCol, UserAuthMethodTypeCol, UserAuthMethodTokenIDCol),
|
||||
handler.WithIndex(handler.NewIndex("resource_owner", []string{UserAuthMethodResourceOwnerCol})),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{UserAuthMethodOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *userAuthMethodProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *userAuthMethodProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: user.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: user.HumanPasswordlessTokenAddedType,
|
||||
Reduce: p.reduceInitAuthMethod,
|
||||
@@ -129,7 +130,7 @@ func (p *userAuthMethodProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.OrgRemovedEventType,
|
||||
Reduce: p.reduceOwnerRemoved,
|
||||
@@ -138,7 +139,7 @@ func (p *userAuthMethodProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(UserAuthMethodInstanceIDCol),
|
||||
@@ -164,7 +165,7 @@ func (p *userAuthMethodProjection) reduceInitAuthMethod(event eventstore.Event)
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-f92f", "reduce.wrong.event.type %v", []eventstore.EventType{user.HumanPasswordlessTokenAddedType, user.HumanU2FTokenAddedType})
|
||||
}
|
||||
|
||||
return crdb.NewUpsertStatement(
|
||||
return handler.NewUpsertStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserAuthMethodInstanceIDCol, nil),
|
||||
@@ -174,8 +175,8 @@ func (p *userAuthMethodProjection) reduceInitAuthMethod(event eventstore.Event)
|
||||
},
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserAuthMethodTokenIDCol, tokenID),
|
||||
handler.NewCol(UserAuthMethodCreationDateCol, event.CreationDate()),
|
||||
handler.NewCol(UserAuthMethodChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(UserAuthMethodCreationDateCol, event.CreatedAt()),
|
||||
handler.NewCol(UserAuthMethodChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(UserAuthMethodResourceOwnerCol, event.Aggregate().ResourceOwner),
|
||||
handler.NewCol(UserAuthMethodInstanceIDCol, event.Aggregate().InstanceID),
|
||||
handler.NewCol(UserAuthMethodUserIDCol, event.Aggregate().ID),
|
||||
@@ -208,10 +209,10 @@ func (p *userAuthMethodProjection) reduceActivateEvent(event eventstore.Event) (
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-f92f", "reduce.wrong.event.type %v", []eventstore.EventType{user.HumanPasswordlessTokenAddedType, user.HumanU2FTokenAddedType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserAuthMethodChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(UserAuthMethodChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(UserAuthMethodSequenceCol, event.Sequence()),
|
||||
handler.NewCol(UserAuthMethodNameCol, name),
|
||||
handler.NewCol(UserAuthMethodStateCol, domain.MFAStateReady),
|
||||
@@ -237,12 +238,12 @@ func (p *userAuthMethodProjection) reduceAddAuthMethod(event eventstore.Event) (
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-DS4g3", "reduce.wrong.event.type %v", []eventstore.EventType{user.HumanOTPSMSAddedType, user.HumanOTPEmailAddedType})
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserAuthMethodTokenIDCol, ""),
|
||||
handler.NewCol(UserAuthMethodCreationDateCol, event.CreationDate()),
|
||||
handler.NewCol(UserAuthMethodChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(UserAuthMethodCreationDateCol, event.CreatedAt()),
|
||||
handler.NewCol(UserAuthMethodChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(UserAuthMethodResourceOwnerCol, event.Aggregate().ResourceOwner),
|
||||
handler.NewCol(UserAuthMethodInstanceIDCol, event.Aggregate().InstanceID),
|
||||
handler.NewCol(UserAuthMethodUserIDCol, event.Aggregate().ID),
|
||||
@@ -286,7 +287,7 @@ func (p *userAuthMethodProjection) reduceRemoveAuthMethod(event eventstore.Event
|
||||
if tokenID != "" {
|
||||
conditions = append(conditions, handler.NewCond(UserAuthMethodTokenIDCol, tokenID))
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
event,
|
||||
conditions,
|
||||
), nil
|
||||
@@ -298,7 +299,7 @@ func (p *userAuthMethodProjection) reduceOwnerRemoved(event eventstore.Event) (*
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-FwDZ8", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(UserAuthMethodInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -6,8 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/user"
|
||||
@@ -26,19 +25,19 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAddedPasswordless",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.HumanPasswordlessTokenAddedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.HumanPasswordlessTokenAddedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"webAuthNTokenId": "token-id"
|
||||
}`),
|
||||
), user.HumanPasswordlessAddedEventMapper),
|
||||
), user.HumanPasswordlessAddedEventMapper),
|
||||
},
|
||||
reduce: (&userAuthMethodProjection{}).reduceInitAuthMethod,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -63,19 +62,19 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAddedU2F",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.HumanU2FTokenAddedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.HumanU2FTokenAddedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"webAuthNTokenId": "token-id"
|
||||
}`),
|
||||
), user.HumanU2FAddedEventMapper),
|
||||
), user.HumanU2FAddedEventMapper),
|
||||
},
|
||||
reduce: (&userAuthMethodProjection{}).reduceInitAuthMethod,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -100,18 +99,18 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAddedTOTP",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.HumanMFAOTPAddedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.HumanMFAOTPAddedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
}`),
|
||||
), user.HumanOTPAddedEventMapper),
|
||||
), user.HumanOTPAddedEventMapper),
|
||||
},
|
||||
reduce: (&userAuthMethodProjection{}).reduceInitAuthMethod,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -136,20 +135,20 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceVerifiedPasswordless",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.HumanPasswordlessTokenVerifiedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.HumanPasswordlessTokenVerifiedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"webAuthNTokenId": "token-id",
|
||||
"webAuthNTokenName": "name"
|
||||
}`),
|
||||
), user.HumanPasswordlessVerifiedEventMapper),
|
||||
), user.HumanPasswordlessVerifiedEventMapper),
|
||||
},
|
||||
reduce: (&userAuthMethodProjection{}).reduceActivateEvent,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -173,20 +172,20 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceVerifiedU2F",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.HumanU2FTokenVerifiedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.HumanU2FTokenVerifiedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"webAuthNTokenId": "token-id",
|
||||
"webAuthNTokenName": "name"
|
||||
}`),
|
||||
), user.HumanU2FVerifiedEventMapper),
|
||||
), user.HumanU2FVerifiedEventMapper),
|
||||
},
|
||||
reduce: (&userAuthMethodProjection{}).reduceActivateEvent,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -210,18 +209,18 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceVerifiedTOTP",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.HumanMFAOTPVerifiedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.HumanMFAOTPVerifiedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
}`),
|
||||
), user.HumanOTPVerifiedEventMapper),
|
||||
), user.HumanOTPVerifiedEventMapper),
|
||||
},
|
||||
reduce: (&userAuthMethodProjection{}).reduceActivateEvent,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -246,16 +245,15 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
|
||||
name: "reduceAddedOTPSMS",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.HumanOTPSMSAddedType),
|
||||
user.HumanOTPSMSAddedType,
|
||||
user.AggregateType,
|
||||
nil,
|
||||
), eventstore.GenericEventMapper[user.HumanOTPSMSAddedEvent]),
|
||||
},
|
||||
reduce: (&userAuthMethodProjection{}).reduceAddAuthMethod,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -281,16 +279,15 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
|
||||
name: "reduceAddedOTPEmail",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.HumanOTPEmailAddedType),
|
||||
user.HumanOTPEmailAddedType,
|
||||
user.AggregateType,
|
||||
nil,
|
||||
), eventstore.GenericEventMapper[user.HumanOTPEmailAddedEvent]),
|
||||
},
|
||||
reduce: (&userAuthMethodProjection{}).reduceAddAuthMethod,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -316,7 +313,7 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
|
||||
name: "reduceRemoveOTPPasswordless",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.HumanPasswordlessTokenRemovedType),
|
||||
user.HumanPasswordlessTokenRemovedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"webAuthNTokenId": "token-id"
|
||||
@@ -325,9 +322,8 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&userAuthMethodProjection{}).reduceRemoveAuthMethod,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -348,7 +344,7 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
|
||||
name: "reduceRemoveOTPU2F",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.HumanU2FTokenRemovedType),
|
||||
user.HumanU2FTokenRemovedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"webAuthNTokenId": "token-id"
|
||||
@@ -357,9 +353,8 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
|
||||
},
|
||||
reduce: (&userAuthMethodProjection{}).reduceRemoveAuthMethod,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -380,16 +375,15 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
|
||||
name: "reduceRemoveTOTP",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.HumanMFAOTPRemovedType),
|
||||
user.HumanMFAOTPRemovedType,
|
||||
user.AggregateType,
|
||||
nil,
|
||||
), user.HumanOTPRemovedEventMapper),
|
||||
},
|
||||
reduce: (&userAuthMethodProjection{}).reduceRemoveAuthMethod,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -409,16 +403,15 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
|
||||
name: "reduceRemoveOTPSMS",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.HumanOTPSMSRemovedType),
|
||||
user.HumanOTPSMSRemovedType,
|
||||
user.AggregateType,
|
||||
nil,
|
||||
), eventstore.GenericEventMapper[user.HumanOTPSMSRemovedEvent]),
|
||||
},
|
||||
reduce: (&userAuthMethodProjection{}).reduceRemoveAuthMethod,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -438,16 +431,15 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
|
||||
name: "reduceRemovePhone",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.HumanPhoneRemovedType),
|
||||
user.HumanPhoneRemovedType,
|
||||
user.AggregateType,
|
||||
nil,
|
||||
), user.HumanPhoneRemovedEventMapper),
|
||||
},
|
||||
reduce: (&userAuthMethodProjection{}).reduceRemoveAuthMethod,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -467,16 +459,15 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
|
||||
name: "reduceRemoveOTPEmail",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.HumanOTPEmailRemovedType),
|
||||
user.HumanOTPEmailRemovedType,
|
||||
user.AggregateType,
|
||||
nil,
|
||||
), eventstore.GenericEventMapper[user.HumanOTPEmailRemovedEvent]),
|
||||
},
|
||||
reduce: (&userAuthMethodProjection{}).reduceRemoveAuthMethod,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -496,16 +487,16 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
|
||||
name: "org reduceOwnerRemoved",
|
||||
reduce: (&userAuthMethodProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -522,17 +513,17 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(UserAuthMethodInstanceIDCol),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/project"
|
||||
@@ -41,53 +41,55 @@ const (
|
||||
)
|
||||
|
||||
type userGrantProjection struct {
|
||||
crdb.StatementHandler
|
||||
es handler.EventStore
|
||||
}
|
||||
|
||||
func newUserGrantProjection(ctx context.Context, config crdb.StatementHandlerConfig) *userGrantProjection {
|
||||
p := new(userGrantProjection)
|
||||
config.ProjectionName = UserGrantProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(UserGrantID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserGrantCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(UserGrantChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(UserGrantSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(UserGrantState, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(UserGrantResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserGrantInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserGrantUserID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserGrantResourceOwnerUser, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserGrantUserOwnerRemoved, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(UserGrantProjectID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserGrantResourceOwnerProject, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserGrantProjectOwnerRemoved, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(UserGrantGrantID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserGrantGrantedOrg, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserGrantGrantedOrgRemoved, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(UserGrantRoles, crdb.ColumnTypeTextArray, crdb.Nullable()),
|
||||
crdb.NewColumn(UserGrantOwnerRemoved, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func newUserGrantProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, &userGrantProjection{es: config.Eventstore})
|
||||
}
|
||||
|
||||
func (*userGrantProjection) Name() string {
|
||||
return UserGrantProjectionTable
|
||||
}
|
||||
|
||||
func (*userGrantProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(UserGrantID, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserGrantCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(UserGrantChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(UserGrantSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(UserGrantState, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(UserGrantResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserGrantInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserGrantUserID, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserGrantResourceOwnerUser, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserGrantUserOwnerRemoved, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(UserGrantProjectID, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserGrantResourceOwnerProject, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserGrantProjectOwnerRemoved, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(UserGrantGrantID, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserGrantGrantedOrg, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserGrantGrantedOrgRemoved, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(UserGrantRoles, handler.ColumnTypeTextArray, handler.Nullable()),
|
||||
handler.NewColumn(UserGrantOwnerRemoved, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(UserGrantInstanceID, UserGrantID),
|
||||
crdb.WithIndex(crdb.NewIndex("user_id", []string{UserGrantUserID})),
|
||||
crdb.WithIndex(crdb.NewIndex("resource_owner", []string{UserGrantResourceOwner})),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{UserGrantOwnerRemoved})),
|
||||
crdb.WithIndex(crdb.NewIndex("user_owner_removed", []string{UserGrantUserOwnerRemoved})),
|
||||
crdb.WithIndex(crdb.NewIndex("project_owner_removed", []string{UserGrantProjectOwnerRemoved})),
|
||||
crdb.WithIndex(crdb.NewIndex("granted_org_removed", []string{UserGrantGrantedOrgRemoved})),
|
||||
handler.NewPrimaryKey(UserGrantInstanceID, UserGrantID),
|
||||
handler.WithIndex(handler.NewIndex("user_id", []string{UserGrantUserID})),
|
||||
handler.WithIndex(handler.NewIndex("resource_owner", []string{UserGrantResourceOwner})),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{UserGrantOwnerRemoved})),
|
||||
handler.WithIndex(handler.NewIndex("user_owner_removed", []string{UserGrantUserOwnerRemoved})),
|
||||
handler.WithIndex(handler.NewIndex("project_owner_removed", []string{UserGrantProjectOwnerRemoved})),
|
||||
handler.WithIndex(handler.NewIndex("granted_org_removed", []string{UserGrantGrantedOrgRemoved})),
|
||||
),
|
||||
)
|
||||
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *userGrantProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *userGrantProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: usergrant.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: usergrant.UserGrantAddedType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -120,7 +122,7 @@ func (p *userGrantProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: user.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: user.UserRemovedType,
|
||||
Reduce: p.reduceUserRemoved,
|
||||
@@ -129,7 +131,7 @@ func (p *userGrantProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: project.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: project.ProjectRemovedType,
|
||||
Reduce: p.reduceProjectRemoved,
|
||||
@@ -154,7 +156,7 @@ func (p *userGrantProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.OrgRemovedEventType,
|
||||
Reduce: p.reduceOwnerRemoved,
|
||||
@@ -163,7 +165,7 @@ func (p *userGrantProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(UserGrantInstanceID),
|
||||
@@ -180,7 +182,7 @@ func (p *userGrantProjection) reduceAdded(event eventstore.Event) (*handler.Stat
|
||||
}
|
||||
|
||||
ctx := setUserGrantContext(e.Aggregate())
|
||||
userOwner, err := getResourceOwnerOfUser(ctx, p.Eventstore, e.Aggregate().InstanceID, e.UserID)
|
||||
userOwner, err := getResourceOwnerOfUser(ctx, p.es, e.Aggregate().InstanceID, e.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -188,25 +190,25 @@ func (p *userGrantProjection) reduceAdded(event eventstore.Event) (*handler.Stat
|
||||
projectOwner := ""
|
||||
grantOwner := ""
|
||||
if e.ProjectGrantID != "" {
|
||||
grantOwner, err = getGrantedOrgOfGrantedProject(ctx, p.Eventstore, e.Aggregate().InstanceID, e.ProjectID, e.ProjectGrantID)
|
||||
grantOwner, err = getGrantedOrgOfGrantedProject(ctx, p.es, e.Aggregate().InstanceID, e.ProjectID, e.ProjectGrantID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
projectOwner, err = getResourceOwnerOfProject(ctx, p.Eventstore, e.Aggregate().InstanceID, e.ProjectID)
|
||||
projectOwner, err = getResourceOwnerOfProject(ctx, p.es, e.Aggregate().InstanceID, e.ProjectID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserGrantID, e.Aggregate().ID),
|
||||
handler.NewCol(UserGrantResourceOwner, e.Aggregate().ResourceOwner),
|
||||
handler.NewCol(UserGrantInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCol(UserGrantCreationDate, e.CreationDate()),
|
||||
handler.NewCol(UserGrantChangeDate, e.CreationDate()),
|
||||
handler.NewCol(UserGrantCreationDate, e.CreatedAt()),
|
||||
handler.NewCol(UserGrantChangeDate, e.CreatedAt()),
|
||||
handler.NewCol(UserGrantSequence, e.Sequence()),
|
||||
handler.NewCol(UserGrantUserID, e.UserID),
|
||||
handler.NewCol(UserGrantResourceOwnerUser, userOwner),
|
||||
@@ -214,14 +216,14 @@ func (p *userGrantProjection) reduceAdded(event eventstore.Event) (*handler.Stat
|
||||
handler.NewCol(UserGrantResourceOwnerProject, projectOwner),
|
||||
handler.NewCol(UserGrantGrantID, e.ProjectGrantID),
|
||||
handler.NewCol(UserGrantGrantedOrg, grantOwner),
|
||||
handler.NewCol(UserGrantRoles, database.StringArray(e.RoleKeys)),
|
||||
handler.NewCol(UserGrantRoles, database.TextArray[string](e.RoleKeys)),
|
||||
handler.NewCol(UserGrantState, domain.UserGrantStateActive),
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *userGrantProjection) reduceChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
var roles database.StringArray
|
||||
var roles database.TextArray[string]
|
||||
|
||||
switch e := event.(type) {
|
||||
case *usergrant.UserGrantChangedEvent:
|
||||
@@ -232,10 +234,10 @@ func (p *userGrantProjection) reduceChanged(event eventstore.Event) (*handler.St
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-hOr1E", "reduce.wrong.event.type %v", []eventstore.EventType{usergrant.UserGrantChangedType, usergrant.UserGrantCascadeChangedType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserGrantChangeDate, event.CreationDate()),
|
||||
handler.NewCol(UserGrantChangeDate, event.CreatedAt()),
|
||||
handler.NewCol(UserGrantRoles, roles),
|
||||
handler.NewCol(UserGrantSequence, event.Sequence()),
|
||||
},
|
||||
@@ -254,7 +256,7 @@ func (p *userGrantProjection) reduceRemoved(event eventstore.Event) (*handler.St
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-7OBEC", "reduce.wrong.event.type %v", []eventstore.EventType{usergrant.UserGrantRemovedType, usergrant.UserGrantCascadeRemovedType})
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
event,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(UserGrantID, event.Aggregate().ID),
|
||||
@@ -268,10 +270,10 @@ func (p *userGrantProjection) reduceDeactivated(event eventstore.Event) (*handle
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-oP7Gm", "reduce.wrong.event.type %s", usergrant.UserGrantDeactivatedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserGrantChangeDate, event.CreationDate()),
|
||||
handler.NewCol(UserGrantChangeDate, event.CreatedAt()),
|
||||
handler.NewCol(UserGrantState, domain.UserGrantStateInactive),
|
||||
handler.NewCol(UserGrantSequence, event.Sequence()),
|
||||
},
|
||||
@@ -287,10 +289,10 @@ func (p *userGrantProjection) reduceReactivated(event eventstore.Event) (*handle
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-DGsKh", "reduce.wrong.event.type %s", usergrant.UserGrantReactivatedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserGrantChangeDate, event.CreationDate()),
|
||||
handler.NewCol(UserGrantChangeDate, event.CreatedAt()),
|
||||
handler.NewCol(UserGrantState, domain.UserGrantStateActive),
|
||||
handler.NewCol(UserGrantSequence, event.Sequence()),
|
||||
},
|
||||
@@ -306,7 +308,7 @@ func (p *userGrantProjection) reduceUserRemoved(event eventstore.Event) (*handle
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Bner2a", "reduce.wrong.event.type %s", user.UserRemovedType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
event,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(UserGrantUserID, event.Aggregate().ID),
|
||||
@@ -320,7 +322,7 @@ func (p *userGrantProjection) reduceProjectRemoved(event eventstore.Event) (*han
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Bne2a", "reduce.wrong.event.type %s", project.ProjectRemovedType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
event,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(UserGrantProjectID, event.Aggregate().ID),
|
||||
@@ -335,7 +337,7 @@ func (p *userGrantProjection) reduceProjectGrantRemoved(event eventstore.Event)
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-dGr2a", "reduce.wrong.event.type %s", project.GrantRemovedType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
event,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(UserGrantGrantID, e.GrantID),
|
||||
@@ -350,10 +352,10 @@ func (p *userGrantProjection) reduceRoleRemoved(event eventstore.Event) (*handle
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-dswg2", "reduce.wrong.event.type %s", project.RoleRemovedType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
crdb.NewArrayRemoveCol(UserGrantRoles, e.Key),
|
||||
handler.NewArrayRemoveCol(UserGrantRoles, e.Key),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(UserGrantProjectID, e.Aggregate().ID),
|
||||
@@ -364,7 +366,7 @@ func (p *userGrantProjection) reduceRoleRemoved(event eventstore.Event) (*handle
|
||||
|
||||
func (p *userGrantProjection) reduceProjectGrantChanged(event eventstore.Event) (*handler.Statement, error) {
|
||||
var grantID string
|
||||
var keys []string
|
||||
var keys database.TextArray[string]
|
||||
switch e := event.(type) {
|
||||
case *project.GrantChangedEvent:
|
||||
grantID = e.GrantID
|
||||
@@ -376,10 +378,10 @@ func (p *userGrantProjection) reduceProjectGrantChanged(event eventstore.Event)
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Fh3gw", "reduce.wrong.event.type %v", []eventstore.EventType{project.GrantChangedType, project.GrantCascadeChangedType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
crdb.NewArrayIntersectCol(UserGrantRoles, database.StringArray(keys)),
|
||||
handler.NewArrayIntersectCol(UserGrantRoles, keys),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(UserGrantGrantID, grantID),
|
||||
@@ -394,27 +396,27 @@ func (p *userGrantProjection) reduceOwnerRemoved(event eventstore.Event) (*handl
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-jpIvp", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(UserGrantInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCond(UserGrantResourceOwner, e.Aggregate().ID),
|
||||
},
|
||||
),
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(UserGrantInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCond(UserGrantResourceOwnerUser, e.Aggregate().ID),
|
||||
},
|
||||
),
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(UserGrantInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCond(UserGrantResourceOwnerProject, e.Aggregate().ID),
|
||||
},
|
||||
),
|
||||
crdb.AddDeleteStatement(
|
||||
handler.AddDeleteStatement(
|
||||
[]handler.Condition{
|
||||
handler.NewCond(UserGrantInstanceID, e.Aggregate().InstanceID),
|
||||
handler.NewCond(UserGrantGrantedOrg, e.Aggregate().ID),
|
||||
@@ -423,10 +425,11 @@ func (p *userGrantProjection) reduceOwnerRemoved(event eventstore.Event) (*handl
|
||||
), nil
|
||||
}
|
||||
|
||||
func getResourceOwnerOfUser(ctx context.Context, es *eventstore.Eventstore, instanceID, aggID string) (string, error) {
|
||||
func getResourceOwnerOfUser(ctx context.Context, es handler.EventStore, instanceID, aggID string) (string, error) {
|
||||
events, err := es.Filter(
|
||||
ctx,
|
||||
eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
AwaitOpenTransactions().
|
||||
InstanceID(instanceID).
|
||||
AddQuery().
|
||||
AggregateTypes(user.AggregateType).
|
||||
@@ -443,10 +446,11 @@ func getResourceOwnerOfUser(ctx context.Context, es *eventstore.Eventstore, inst
|
||||
return events[0].Aggregate().ResourceOwner, nil
|
||||
}
|
||||
|
||||
func getResourceOwnerOfProject(ctx context.Context, es *eventstore.Eventstore, instanceID, aggID string) (string, error) {
|
||||
func getResourceOwnerOfProject(ctx context.Context, es handler.EventStore, instanceID, aggID string) (string, error) {
|
||||
events, err := es.Filter(
|
||||
ctx,
|
||||
eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
AwaitOpenTransactions().
|
||||
InstanceID(instanceID).
|
||||
AddQuery().
|
||||
AggregateTypes(project.AggregateType).
|
||||
@@ -463,10 +467,11 @@ func getResourceOwnerOfProject(ctx context.Context, es *eventstore.Eventstore, i
|
||||
return events[0].Aggregate().ResourceOwner, nil
|
||||
}
|
||||
|
||||
func getGrantedOrgOfGrantedProject(ctx context.Context, es *eventstore.Eventstore, instanceID, projectID, grantID string) (string, error) {
|
||||
func getGrantedOrgOfGrantedProject(ctx context.Context, es handler.EventStore, instanceID, projectID, grantID string) (string, error) {
|
||||
events, err := es.Filter(
|
||||
ctx,
|
||||
eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
AwaitOpenTransactions().
|
||||
InstanceID(instanceID).
|
||||
AddQuery().
|
||||
AggregateTypes(project.AggregateType).
|
||||
@@ -490,6 +495,6 @@ func getGrantedOrgOfGrantedProject(ctx context.Context, es *eventstore.Eventstor
|
||||
return grantAddedEvent.GrantedOrgID, nil
|
||||
}
|
||||
|
||||
func setUserGrantContext(event eventstore.Aggregate) context.Context {
|
||||
return authz.WithInstanceID(context.Background(), event.InstanceID)
|
||||
func setUserGrantContext(aggregate *eventstore.Aggregate) context.Context {
|
||||
return authz.WithInstanceID(context.Background(), aggregate.InstanceID)
|
||||
}
|
||||
|
||||
@@ -10,9 +10,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/project"
|
||||
@@ -33,30 +31,33 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAdded",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(usergrant.UserGrantAddedType),
|
||||
usergrant.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
usergrant.UserGrantAddedType,
|
||||
usergrant.AggregateType,
|
||||
[]byte(`{
|
||||
"userId": "user-id",
|
||||
"projectId": "project-id",
|
||||
"roleKeys": ["role"]
|
||||
}`),
|
||||
), usergrant.UserGrantAddedEventMapper),
|
||||
), usergrant.UserGrantAddedEventMapper),
|
||||
},
|
||||
reduce: (&userGrantProjection{
|
||||
StatementHandler: getStatementHandlerWithFilters(
|
||||
user.NewHumanAddedEvent(context.Background(),
|
||||
&user.NewAggregate("user-id", "org1").Aggregate,
|
||||
"username1",
|
||||
"firstname1",
|
||||
"lastname1",
|
||||
"nickname1",
|
||||
"displayname1",
|
||||
language.German,
|
||||
domain.GenderMale,
|
||||
"email1",
|
||||
true,
|
||||
),
|
||||
es: newMockEventStore().
|
||||
appendFilterResponse([]eventstore.Event{
|
||||
user.NewHumanAddedEvent(context.Background(),
|
||||
&user.NewAggregate("user-id", "org1").Aggregate,
|
||||
"username1",
|
||||
"firstname1",
|
||||
"lastname1",
|
||||
"nickname1",
|
||||
"displayname1",
|
||||
language.German,
|
||||
domain.GenderMale,
|
||||
"email1",
|
||||
true,
|
||||
),
|
||||
}).appendFilterResponse([]eventstore.Event{
|
||||
project.NewProjectAddedEvent(context.Background(),
|
||||
&project.NewAggregate("project-id", "org2").Aggregate,
|
||||
"project",
|
||||
@@ -65,11 +66,11 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
false,
|
||||
domain.PrivateLabelingSettingUnspecified,
|
||||
),
|
||||
)(t)}).reduceAdded,
|
||||
}),
|
||||
}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: usergrant.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: usergrant.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -87,7 +88,7 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
"org2",
|
||||
"",
|
||||
"",
|
||||
database.StringArray{"role"},
|
||||
database.TextArray[string]{"role"},
|
||||
domain.UserGrantStateActive,
|
||||
},
|
||||
},
|
||||
@@ -98,42 +99,45 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceAdded with projectgrant",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(usergrant.UserGrantAddedType),
|
||||
usergrant.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
usergrant.UserGrantAddedType,
|
||||
usergrant.AggregateType,
|
||||
[]byte(`{
|
||||
"userId": "user-id",
|
||||
"projectId": "project-id",
|
||||
"grantId": "grant-id",
|
||||
"roleKeys": ["role"]
|
||||
}`),
|
||||
), usergrant.UserGrantAddedEventMapper),
|
||||
), usergrant.UserGrantAddedEventMapper),
|
||||
},
|
||||
reduce: (&userGrantProjection{
|
||||
StatementHandler: getStatementHandlerWithFilters(
|
||||
user.NewHumanAddedEvent(context.Background(),
|
||||
&user.NewAggregate("user-id", "org1").Aggregate,
|
||||
"username1",
|
||||
"firstname1",
|
||||
"lastname1",
|
||||
"nickname1",
|
||||
"displayname1",
|
||||
language.German,
|
||||
domain.GenderMale,
|
||||
"email1",
|
||||
true,
|
||||
),
|
||||
es: newMockEventStore().
|
||||
appendFilterResponse([]eventstore.Event{
|
||||
user.NewHumanAddedEvent(context.Background(),
|
||||
&user.NewAggregate("user-id", "org1").Aggregate,
|
||||
"username1",
|
||||
"firstname1",
|
||||
"lastname1",
|
||||
"nickname1",
|
||||
"displayname1",
|
||||
language.German,
|
||||
domain.GenderMale,
|
||||
"email1",
|
||||
true,
|
||||
),
|
||||
}).appendFilterResponse([]eventstore.Event{
|
||||
project.NewGrantAddedEvent(context.Background(),
|
||||
&project.NewAggregate("project-id", "org2").Aggregate,
|
||||
"grant-id",
|
||||
"org3",
|
||||
[]string{},
|
||||
),
|
||||
)(t)}).reduceAdded,
|
||||
}),
|
||||
}).reduceAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: usergrant.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: usergrant.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -151,7 +155,7 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
"",
|
||||
"grant-id",
|
||||
"org3",
|
||||
database.StringArray{"role"},
|
||||
database.TextArray[string]{"role"},
|
||||
domain.UserGrantStateActive,
|
||||
},
|
||||
},
|
||||
@@ -162,26 +166,26 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(usergrant.UserGrantChangedType),
|
||||
usergrant.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
usergrant.UserGrantChangedType,
|
||||
usergrant.AggregateType,
|
||||
[]byte(`{
|
||||
"roleKeys": ["role"]
|
||||
}`),
|
||||
), usergrant.UserGrantChangedEventMapper),
|
||||
), usergrant.UserGrantChangedEventMapper),
|
||||
},
|
||||
reduce: (&userGrantProjection{}).reduceChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: usergrant.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: usergrant.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.user_grants3 SET (change_date, roles, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
database.StringArray{"role"},
|
||||
database.TextArray[string]{"role"},
|
||||
uint64(15),
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
@@ -194,26 +198,26 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceCascadeChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(usergrant.UserGrantCascadeChangedType),
|
||||
usergrant.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
usergrant.UserGrantCascadeChangedType,
|
||||
usergrant.AggregateType,
|
||||
[]byte(`{
|
||||
"roleKeys": ["role"]
|
||||
}`),
|
||||
), usergrant.UserGrantCascadeChangedEventMapper),
|
||||
), usergrant.UserGrantCascadeChangedEventMapper),
|
||||
},
|
||||
reduce: (&userGrantProjection{}).reduceChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: usergrant.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: usergrant.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.user_grants3 SET (change_date, roles, sequence) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
database.StringArray{"role"},
|
||||
database.TextArray[string]{"role"},
|
||||
uint64(15),
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
@@ -226,17 +230,17 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(usergrant.UserGrantRemovedType),
|
||||
usergrant.AggregateType,
|
||||
nil,
|
||||
), usergrant.UserGrantRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
usergrant.UserGrantRemovedType,
|
||||
usergrant.AggregateType,
|
||||
nil,
|
||||
), usergrant.UserGrantRemovedEventMapper),
|
||||
},
|
||||
reduce: (&userGrantProjection{}).reduceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: usergrant.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: usergrant.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -253,17 +257,17 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(UserGrantInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -279,17 +283,17 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceCascadeRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(usergrant.UserGrantCascadeRemovedType),
|
||||
usergrant.AggregateType,
|
||||
nil,
|
||||
), usergrant.UserGrantCascadeRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
usergrant.UserGrantCascadeRemovedType,
|
||||
usergrant.AggregateType,
|
||||
nil,
|
||||
), usergrant.UserGrantCascadeRemovedEventMapper),
|
||||
},
|
||||
reduce: (&userGrantProjection{}).reduceRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: usergrant.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: usergrant.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -306,17 +310,17 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceDeactivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(usergrant.UserGrantDeactivatedType),
|
||||
usergrant.AggregateType,
|
||||
nil,
|
||||
), usergrant.UserGrantDeactivatedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
usergrant.UserGrantDeactivatedType,
|
||||
usergrant.AggregateType,
|
||||
nil,
|
||||
), usergrant.UserGrantDeactivatedEventMapper),
|
||||
},
|
||||
reduce: (&userGrantProjection{}).reduceDeactivated,
|
||||
want: wantReduce{
|
||||
aggregateType: usergrant.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: usergrant.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -336,17 +340,17 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceReactivated",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(usergrant.UserGrantReactivatedType),
|
||||
usergrant.AggregateType,
|
||||
nil,
|
||||
), usergrant.UserGrantDeactivatedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
usergrant.UserGrantReactivatedType,
|
||||
usergrant.AggregateType,
|
||||
nil,
|
||||
), usergrant.UserGrantDeactivatedEventMapper),
|
||||
},
|
||||
reduce: (&userGrantProjection{}).reduceReactivated,
|
||||
want: wantReduce{
|
||||
aggregateType: usergrant.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: usergrant.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -366,17 +370,17 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceUserRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.UserRemovedType),
|
||||
user.AggregateType,
|
||||
nil,
|
||||
), user.UserRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.UserRemovedType,
|
||||
user.AggregateType,
|
||||
nil,
|
||||
), user.UserRemovedEventMapper),
|
||||
},
|
||||
reduce: (&userGrantProjection{}).reduceUserRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -393,17 +397,17 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.ProjectRemovedType),
|
||||
project.AggregateType,
|
||||
nil,
|
||||
), project.ProjectRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.ProjectRemovedType,
|
||||
project.AggregateType,
|
||||
nil,
|
||||
), project.ProjectRemovedEventMapper),
|
||||
},
|
||||
reduce: (&userGrantProjection{}).reduceProjectRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -420,17 +424,17 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectGrantRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.GrantRemovedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grantID"}`),
|
||||
), project.GrantRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.GrantRemovedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grantID"}`),
|
||||
), project.GrantRemovedEventMapper),
|
||||
},
|
||||
reduce: (&userGrantProjection{}).reduceProjectGrantRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -447,17 +451,17 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceRoleRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.RoleRemovedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"key": "key"}`),
|
||||
), project.RoleRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.RoleRemovedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"key": "key"}`),
|
||||
), project.RoleRemovedEventMapper),
|
||||
},
|
||||
reduce: (&userGrantProjection{}).reduceRoleRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -475,23 +479,23 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceProjectGrantChanged",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(project.GrantChangedType),
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grantID", "roleKeys": ["key"]}`),
|
||||
), project.GrantChangedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
project.GrantChangedType,
|
||||
project.AggregateType,
|
||||
[]byte(`{"grantId": "grantID", "roleKeys": ["key"]}`),
|
||||
), project.GrantChangedEventMapper),
|
||||
},
|
||||
reduce: (&userGrantProjection{}).reduceProjectGrantChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: project.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.user_grants3 SET (roles) = (SELECT ARRAY( SELECT UNNEST(roles) INTERSECT SELECT UNNEST ($1::TEXT[]))) WHERE (grant_id = $2) AND (instance_id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
database.StringArray{"key"},
|
||||
database.TextArray[string]{"key"},
|
||||
"grantID",
|
||||
"instance-id",
|
||||
},
|
||||
@@ -504,16 +508,16 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
name: "org.reduceOwnerRemoved",
|
||||
reduce: (&userGrantProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -563,29 +567,3 @@ func TestUserGrantProjection_reduces(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func getStatementHandlerWithFilters(events ...eventstore.Command) func(t *testing.T) crdb.StatementHandler {
|
||||
filters := make([]expect, 0)
|
||||
for _, event := range events {
|
||||
filters = append(filters,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
event,
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
return func(t *testing.T) crdb.StatementHandler {
|
||||
return crdb.StatementHandler{
|
||||
ProjectionHandler: &handler.ProjectionHandler{
|
||||
Handler: handler.Handler{
|
||||
Eventstore: eventstoreExpect(
|
||||
t,
|
||||
filters...,
|
||||
),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/user"
|
||||
@@ -26,41 +26,41 @@ const (
|
||||
UserMetadataColumnOwnerRemoved = "owner_removed"
|
||||
)
|
||||
|
||||
type userMetadataProjection struct {
|
||||
crdb.StatementHandler
|
||||
type userMetadataProjection struct{}
|
||||
|
||||
func newUserMetadataProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(userMetadataProjection))
|
||||
}
|
||||
|
||||
func newUserMetadataProjection(ctx context.Context, config crdb.StatementHandlerConfig) *userMetadataProjection {
|
||||
p := new(userMetadataProjection)
|
||||
config.ProjectionName = UserMetadataProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(UserMetadataColumnUserID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserMetadataColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(UserMetadataColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(UserMetadataColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(UserMetadataColumnResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserMetadataColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserMetadataColumnKey, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(UserMetadataColumnValue, crdb.ColumnTypeBytes, crdb.Nullable()),
|
||||
crdb.NewColumn(UserMetadataColumnOwnerRemoved, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*userMetadataProjection) Name() string {
|
||||
return UserMetadataProjectionTable
|
||||
}
|
||||
|
||||
func (*userMetadataProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(UserMetadataColumnUserID, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserMetadataColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(UserMetadataColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(UserMetadataColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(UserMetadataColumnResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserMetadataColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserMetadataColumnKey, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserMetadataColumnValue, handler.ColumnTypeBytes, handler.Nullable()),
|
||||
handler.NewColumn(UserMetadataColumnOwnerRemoved, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(UserMetadataColumnInstanceID, UserMetadataColumnUserID, UserMetadataColumnKey),
|
||||
crdb.WithIndex(crdb.NewIndex("resource_owner", []string{UserGrantResourceOwner})),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{UserMetadataColumnOwnerRemoved})),
|
||||
handler.NewPrimaryKey(UserMetadataColumnInstanceID, UserMetadataColumnUserID, UserMetadataColumnKey),
|
||||
handler.WithIndex(handler.NewIndex("resource_owner", []string{UserGrantResourceOwner})),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{UserMetadataColumnOwnerRemoved})),
|
||||
),
|
||||
)
|
||||
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *userMetadataProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *userMetadataProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: user.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: user.MetadataSetType,
|
||||
Reduce: p.reduceMetadataSet,
|
||||
@@ -81,7 +81,7 @@ func (p *userMetadataProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.OrgRemovedEventType,
|
||||
Reduce: p.reduceOwnerRemoved,
|
||||
@@ -90,7 +90,7 @@ func (p *userMetadataProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(UserMetadataColumnInstanceID),
|
||||
@@ -105,7 +105,7 @@ func (p *userMetadataProjection) reduceMetadataSet(event eventstore.Event) (*han
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Ghn52", "reduce.wrong.event.type %s", user.MetadataSetType)
|
||||
}
|
||||
return crdb.NewUpsertStatement(
|
||||
return handler.NewUpsertStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserMetadataColumnInstanceID, nil),
|
||||
@@ -130,7 +130,7 @@ func (p *userMetadataProjection) reduceMetadataRemoved(event eventstore.Event) (
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Bm542", "reduce.wrong.event.type %s", user.MetadataRemovedType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(UserMetadataColumnUserID, e.Aggregate().ID),
|
||||
@@ -148,7 +148,7 @@ func (p *userMetadataProjection) reduceMetadataRemovedAll(event eventstore.Event
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-Bmnf2", "reduce.wrong.event.type %v", []eventstore.EventType{user.MetadataRemovedAllType, user.UserRemovedType})
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
event,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(UserMetadataColumnUserID, event.Aggregate().ID),
|
||||
@@ -163,7 +163,7 @@ func (p *userMetadataProjection) reduceOwnerRemoved(event eventstore.Event) (*ha
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-oqwul", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(UserMetadataColumnInstanceID, e.Aggregate().InstanceID),
|
||||
|
||||
@@ -5,8 +5,7 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/user"
|
||||
@@ -25,20 +24,20 @@ func TestUserMetadataProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceMetadataSet",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.MetadataSetType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.MetadataSetType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "key",
|
||||
"value": "dmFsdWU="
|
||||
}`),
|
||||
), user.MetadataSetEventMapper),
|
||||
), user.MetadataSetEventMapper),
|
||||
},
|
||||
reduce: (&userMetadataProjection{}).reduceMetadataSet,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -61,19 +60,19 @@ func TestUserMetadataProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceMetadataRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.MetadataRemovedType),
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.MetadataRemovedType,
|
||||
user.AggregateType,
|
||||
[]byte(`{
|
||||
"key": "key"
|
||||
}`),
|
||||
), user.MetadataRemovedEventMapper),
|
||||
), user.MetadataRemovedEventMapper),
|
||||
},
|
||||
reduce: (&userMetadataProjection{}).reduceMetadataRemoved,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -91,17 +90,17 @@ func TestUserMetadataProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceMetadataRemovedAll",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.MetadataRemovedAllType),
|
||||
user.AggregateType,
|
||||
nil,
|
||||
), user.MetadataRemovedAllEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.MetadataRemovedAllType,
|
||||
user.AggregateType,
|
||||
nil,
|
||||
), user.MetadataRemovedAllEventMapper),
|
||||
},
|
||||
reduce: (&userMetadataProjection{}).reduceMetadataRemovedAll,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -118,17 +117,17 @@ func TestUserMetadataProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "reduceMetadataRemovedAll (user removed)",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(user.UserRemovedType),
|
||||
user.AggregateType,
|
||||
nil,
|
||||
), user.UserRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
user.UserRemovedType,
|
||||
user.AggregateType,
|
||||
nil,
|
||||
), user.UserRemovedEventMapper),
|
||||
},
|
||||
reduce: (&userMetadataProjection{}).reduceMetadataRemovedAll,
|
||||
want: wantReduce{
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: user.AggregateType,
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -146,16 +145,16 @@ func TestUserMetadataProjection_reduces(t *testing.T) {
|
||||
name: "org reduceOwnerRemoved",
|
||||
reduce: (&userMetadataProjection{}).reduceOwnerRemoved,
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(org.OrgRemovedEventType),
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
org.OrgRemovedEventType,
|
||||
org.AggregateType,
|
||||
nil,
|
||||
), org.OrgRemovedEventMapper),
|
||||
},
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("org"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
@@ -172,17 +171,17 @@ func TestUserMetadataProjection_reduces(t *testing.T) {
|
||||
{
|
||||
name: "instance reduceInstanceRemoved",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.InstanceRemovedEventType),
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.InstanceRemovedEventType,
|
||||
instance.AggregateType,
|
||||
nil,
|
||||
), instance.InstanceRemovedEventMapper),
|
||||
},
|
||||
reduce: reduceInstanceRemovedHelper(UserMetadataColumnInstanceID),
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
previousSequence: 10,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user