mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 04:57:33 +00:00
fix: handle default org id (#3769)
This commit is contained in:
@@ -17,7 +17,7 @@ const (
|
||||
InstanceColumnName = "name"
|
||||
InstanceColumnChangeDate = "change_date"
|
||||
InstanceColumnCreationDate = "creation_date"
|
||||
InstanceColumnGlobalOrgID = "global_org_id"
|
||||
InstanceColumnDefaultOrgID = "default_org_id"
|
||||
InstanceColumnProjectID = "iam_project_id"
|
||||
InstanceColumnConsoleID = "console_client_id"
|
||||
InstanceColumnConsoleAppID = "console_app_id"
|
||||
@@ -39,7 +39,7 @@ func NewInstanceProjection(ctx context.Context, config crdb.StatementHandlerConf
|
||||
crdb.NewColumn(InstanceColumnName, crdb.ColumnTypeText, crdb.Default("")),
|
||||
crdb.NewColumn(InstanceColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(InstanceColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(InstanceColumnGlobalOrgID, crdb.ColumnTypeText, crdb.Default("")),
|
||||
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("")),
|
||||
@@ -63,8 +63,8 @@ func (p *InstanceProjection) reducers() []handler.AggregateReducer {
|
||||
Reduce: p.reduceInstanceAdded,
|
||||
},
|
||||
{
|
||||
Event: instance.GlobalOrgSetEventType,
|
||||
Reduce: p.reduceGlobalOrgSet,
|
||||
Event: instance.DefaultOrgSetEventType,
|
||||
Reduce: p.reduceDefaultOrgSet,
|
||||
},
|
||||
{
|
||||
Event: instance.ProjectSetEventType,
|
||||
@@ -100,17 +100,17 @@ func (p *InstanceProjection) reduceInstanceAdded(event eventstore.Event) (*handl
|
||||
), nil
|
||||
}
|
||||
|
||||
func (p *InstanceProjection) reduceGlobalOrgSet(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*instance.GlobalOrgSetEvent)
|
||||
func (p *InstanceProjection) reduceDefaultOrgSet(event eventstore.Event) (*handler.Statement, error) {
|
||||
e, ok := event.(*instance.DefaultOrgSetEvent)
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-2n9f2", "reduce.wrong.event.type %s", instance.GlobalOrgSetEventType)
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-2n9f2", "reduce.wrong.event.type %s", instance.DefaultOrgSetEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(InstanceColumnChangeDate, e.CreationDate()),
|
||||
handler.NewCol(InstanceColumnSequence, e.Sequence()),
|
||||
handler.NewCol(InstanceColumnGlobalOrgID, e.OrgID),
|
||||
handler.NewCol(InstanceColumnDefaultOrgID, e.OrgID),
|
||||
},
|
||||
[]handler.Condition{
|
||||
handler.NewCond(InstanceColumnID, e.Aggregate().InstanceID),
|
||||
|
@@ -51,15 +51,15 @@ func TestInstanceProjection_reduces(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "reduceGlobalOrgSet",
|
||||
name: "reduceDefaultOrgSet",
|
||||
args: args{
|
||||
event: getEvent(testEvent(
|
||||
repository.EventType(instance.GlobalOrgSetEventType),
|
||||
repository.EventType(instance.DefaultOrgSetEventType),
|
||||
instance.AggregateType,
|
||||
[]byte(`{"globalOrgId": "orgid"}`),
|
||||
), instance.GlobalOrgSetMapper),
|
||||
[]byte(`{"orgId": "orgid"}`),
|
||||
), instance.DefaultOrgSetMapper),
|
||||
},
|
||||
reduce: (&InstanceProjection{}).reduceGlobalOrgSet,
|
||||
reduce: (&InstanceProjection{}).reduceDefaultOrgSet,
|
||||
want: wantReduce{
|
||||
projection: InstanceProjectionTable,
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
@@ -68,7 +68,7 @@ func TestInstanceProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.instances SET (change_date, sequence, global_org_id) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedStmt: "UPDATE projections.instances SET (change_date, sequence, default_org_id) = ($1, $2, $3) WHERE (id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
|
Reference in New Issue
Block a user