diff --git a/internal/api/grpc/org/v2/integration_test/org_test.go b/internal/api/grpc/org/v2/integration_test/org_test.go index 96ad7d5fb..9298e63b3 100644 --- a/internal/api/grpc/org/v2/integration_test/org_test.go +++ b/internal/api/grpc/org/v2/integration_test/org_test.go @@ -96,6 +96,31 @@ func TestServer_AddOrganization(t *testing.T) { CreatedAdmins: []*org.AddOrganizationResponse_CreatedAdmin{}, }, }, + { + name: "no admin, custom organization ID", + ctx: CTX, + req: &org.AddOrganizationRequest{ + Name: integration.OrganizationName(), + OrganizationId: gu.Ptr("custom-organization-ID"), + }, + want: &org.AddOrganizationResponse{ + OrganizationId: "custom-organization-ID", + CreatedAdmins: []*org.AddOrganizationResponse_CreatedAdmin{}, + }, + }, + { + name: "no admin, custom organization ID (precedence over org ID)", + ctx: CTX, + req: &org.AddOrganizationRequest{ + Name: integration.OrganizationName(), + OrganizationId: gu.Ptr("custom-organization-ID2"), + OrgId: gu.Ptr("custom-org-ID"), // will be ignored in favor of OrganizationId + }, + want: &org.AddOrganizationResponse{ + OrganizationId: "custom-organization-ID2", + CreatedAdmins: []*org.AddOrganizationResponse_CreatedAdmin{}, + }, + }, { name: "admin with init with userID passed for Human admin", ctx: CTX, diff --git a/internal/api/grpc/org/v2/org.go b/internal/api/grpc/org/v2/org.go index d10315974..b3333be5e 100644 --- a/internal/api/grpc/org/v2/org.go +++ b/internal/api/grpc/org/v2/org.go @@ -142,11 +142,15 @@ func addOrganizationRequestToCommand(request *org.AddOrganizationRequest) (*comm if err != nil { return nil, err } + id := request.GetOrganizationId() + if id == "" { + id = request.GetOrgId() //nolint:staticcheck + } return &command.OrgSetup{ Name: request.GetName(), CustomDomain: "", Admins: admins, - OrgID: request.GetOrgId(), + OrgID: id, }, nil } diff --git a/internal/api/grpc/org/v2/org_test.go b/internal/api/grpc/org/v2/org_test.go index 564c5597e..01a692480 100644 --- a/internal/api/grpc/org/v2/org_test.go +++ b/internal/api/grpc/org/v2/org_test.go @@ -54,6 +54,37 @@ func Test_addOrganizationRequestToCommand(t *testing.T) { OrgID: "org-ID", }, }, + { + name: "custom organization ID", + args: args{ + request: &org.AddOrganizationRequest{ + Name: "custom org ID", + OrganizationId: gu.Ptr("organization-ID"), + }, + }, + want: &command.OrgSetup{ + Name: "custom org ID", + CustomDomain: "", + Admins: []*command.OrgSetupAdmin{}, + OrgID: "organization-ID", + }, + }, + { + name: "custom organization ID (precedence over org ID)", + args: args{ + request: &org.AddOrganizationRequest{ + Name: "custom org ID", + OrganizationId: gu.Ptr("organization-ID"), + OrgId: gu.Ptr("org-ID"), // will be ignored in favor of OrganizationId + }, + }, + want: &command.OrgSetup{ + Name: "custom org ID", + CustomDomain: "", + Admins: []*command.OrgSetupAdmin{}, + OrgID: "organization-ID", + }, + }, { name: "user ID", args: args{ diff --git a/proto/zitadel/org/v2/org_service.proto b/proto/zitadel/org/v2/org_service.proto index 0e97e1b37..e4838d5a5 100644 --- a/proto/zitadel/org/v2/org_service.proto +++ b/proto/zitadel/org/v2/org_service.proto @@ -577,6 +577,7 @@ message AddOrganizationRequest{ // which is the recommended way. The generated ID will be returned in the response. // // Deprecated: use 'organization_id' field instead. + // If both org_id and organization_id are set, organization_id will take precedence. optional string org_id = 3 [ deprecated = true, (validate.rules).string = {min_len: 1, max_len: 200},