mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 04:17:32 +00:00
fix: handle default org id (#3769)
This commit is contained in:
@@ -39,8 +39,8 @@ var (
|
||||
name: projection.InstanceColumnSequence,
|
||||
table: instanceTable,
|
||||
}
|
||||
InstanceColumnGlobalOrgID = Column{
|
||||
name: projection.InstanceColumnGlobalOrgID,
|
||||
InstanceColumnDefaultOrgID = Column{
|
||||
name: projection.InstanceColumnDefaultOrgID,
|
||||
table: instanceTable,
|
||||
}
|
||||
InstanceColumnProjectID = Column{
|
||||
@@ -68,7 +68,7 @@ type Instance struct {
|
||||
Sequence uint64
|
||||
Name string
|
||||
|
||||
GlobalOrgID string
|
||||
DefaultOrgID string
|
||||
IAMProjectID string
|
||||
ConsoleID string
|
||||
ConsoleAppID string
|
||||
@@ -110,6 +110,10 @@ func (i *Instance) DefaultLanguage() language.Tag {
|
||||
return i.DefaultLang
|
||||
}
|
||||
|
||||
func (i *Instance) DefaultOrganisationID() string {
|
||||
return i.DefaultOrgID
|
||||
}
|
||||
|
||||
type InstanceSearchQueries struct {
|
||||
SearchRequest
|
||||
Queries []SearchQuery
|
||||
@@ -196,7 +200,7 @@ func prepareInstanceQuery(host string) (sq.SelectBuilder, func(*sql.Row) (*Insta
|
||||
InstanceColumnCreationDate.identifier(),
|
||||
InstanceColumnChangeDate.identifier(),
|
||||
InstanceColumnSequence.identifier(),
|
||||
InstanceColumnGlobalOrgID.identifier(),
|
||||
InstanceColumnDefaultOrgID.identifier(),
|
||||
InstanceColumnProjectID.identifier(),
|
||||
InstanceColumnConsoleID.identifier(),
|
||||
InstanceColumnConsoleAppID.identifier(),
|
||||
@@ -211,7 +215,7 @@ func prepareInstanceQuery(host string) (sq.SelectBuilder, func(*sql.Row) (*Insta
|
||||
&instance.CreationDate,
|
||||
&instance.ChangeDate,
|
||||
&instance.Sequence,
|
||||
&instance.GlobalOrgID,
|
||||
&instance.DefaultOrgID,
|
||||
&instance.IAMProjectID,
|
||||
&instance.ConsoleID,
|
||||
&instance.ConsoleAppID,
|
||||
@@ -235,7 +239,7 @@ func prepareInstancesQuery() (sq.SelectBuilder, func(*sql.Rows) (*Instances, err
|
||||
InstanceColumnChangeDate.identifier(),
|
||||
InstanceColumnSequence.identifier(),
|
||||
InstanceColumnName.identifier(),
|
||||
InstanceColumnGlobalOrgID.identifier(),
|
||||
InstanceColumnDefaultOrgID.identifier(),
|
||||
InstanceColumnProjectID.identifier(),
|
||||
InstanceColumnConsoleID.identifier(),
|
||||
InstanceColumnConsoleAppID.identifier(),
|
||||
@@ -254,7 +258,7 @@ func prepareInstancesQuery() (sq.SelectBuilder, func(*sql.Rows) (*Instances, err
|
||||
&instance.ChangeDate,
|
||||
&instance.Sequence,
|
||||
&instance.Name,
|
||||
&instance.GlobalOrgID,
|
||||
&instance.DefaultOrgID,
|
||||
&instance.IAMProjectID,
|
||||
&instance.ConsoleID,
|
||||
&instance.ConsoleAppID,
|
||||
@@ -288,7 +292,7 @@ func prepareInstanceDomainQuery(host string) (sq.SelectBuilder, func(*sql.Rows)
|
||||
InstanceColumnChangeDate.identifier(),
|
||||
InstanceColumnSequence.identifier(),
|
||||
InstanceColumnName.identifier(),
|
||||
InstanceColumnGlobalOrgID.identifier(),
|
||||
InstanceColumnDefaultOrgID.identifier(),
|
||||
InstanceColumnProjectID.identifier(),
|
||||
InstanceColumnConsoleID.identifier(),
|
||||
InstanceColumnConsoleAppID.identifier(),
|
||||
@@ -324,7 +328,7 @@ func prepareInstanceDomainQuery(host string) (sq.SelectBuilder, func(*sql.Rows)
|
||||
&instance.ChangeDate,
|
||||
&instance.Sequence,
|
||||
&instance.Name,
|
||||
&instance.GlobalOrgID,
|
||||
&instance.DefaultOrgID,
|
||||
&instance.IAMProjectID,
|
||||
&instance.ConsoleID,
|
||||
&instance.ConsoleAppID,
|
||||
|
@@ -36,7 +36,7 @@ func Test_InstancePrepares(t *testing.T) {
|
||||
` projections.instances.creation_date,`+
|
||||
` projections.instances.change_date,`+
|
||||
` projections.instances.sequence,`+
|
||||
` projections.instances.global_org_id,`+
|
||||
` projections.instances.default_org_id,`+
|
||||
` projections.instances.iam_project_id,`+
|
||||
` projections.instances.console_client_id,`+
|
||||
` projections.instances.console_app_id,`+
|
||||
@@ -65,7 +65,7 @@ func Test_InstancePrepares(t *testing.T) {
|
||||
` projections.instances.creation_date,`+
|
||||
` projections.instances.change_date,`+
|
||||
` projections.instances.sequence,`+
|
||||
` projections.instances.global_org_id,`+
|
||||
` projections.instances.default_org_id,`+
|
||||
` projections.instances.iam_project_id,`+
|
||||
` projections.instances.console_client_id,`+
|
||||
` projections.instances.console_app_id,`+
|
||||
@@ -76,7 +76,7 @@ func Test_InstancePrepares(t *testing.T) {
|
||||
"creation_date",
|
||||
"change_date",
|
||||
"sequence",
|
||||
"global_org_id",
|
||||
"default_org_id",
|
||||
"iam_project_id",
|
||||
"console_client_id",
|
||||
"console_app_id",
|
||||
@@ -100,7 +100,7 @@ func Test_InstancePrepares(t *testing.T) {
|
||||
CreationDate: testNow,
|
||||
ChangeDate: testNow,
|
||||
Sequence: 20211108,
|
||||
GlobalOrgID: "global-org-id",
|
||||
DefaultOrgID: "global-org-id",
|
||||
IAMProjectID: "project-id",
|
||||
ConsoleID: "client-id",
|
||||
ConsoleAppID: "app-id",
|
||||
@@ -118,7 +118,7 @@ func Test_InstancePrepares(t *testing.T) {
|
||||
` projections.instances.creation_date,`+
|
||||
` projections.instances.change_date,`+
|
||||
` projections.instances.sequence,`+
|
||||
` projections.instances.global_org_id,`+
|
||||
` projections.instances.default_org_id,`+
|
||||
` projections.instances.iam_project_id,`+
|
||||
` projections.instances.console_client_id,`+
|
||||
` projections.instances.console_app_id,`+
|
||||
|
@@ -37,7 +37,7 @@ func (q *Queries) GetProjectMemberRoles(ctx context.Context) ([]string, error) {
|
||||
return nil, err
|
||||
}
|
||||
roles := make([]string, 0)
|
||||
global := authz.GetCtxData(ctx).OrgID == iam.GlobalOrgID
|
||||
global := authz.GetCtxData(ctx).OrgID == iam.DefaultOrgID
|
||||
for _, roleMap := range q.zitadelRoles {
|
||||
if strings.HasPrefix(roleMap.Role, "PROJECT") && !strings.HasPrefix(roleMap.Role, "PROJECT_GRANT") {
|
||||
if global && !strings.HasSuffix(roleMap.Role, "GLOBAL") {
|
||||
|
@@ -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