fix(api): correctly handle organization_id on creation (#11396)

# Which Problems Are Solved

While moving the some requests from the v2beta organization service to
v2, the `org_id` property of the `AddOrganization` request was
deprecated in favor of `organization_id`. However, the internal logic
was adjusted, resulting in a ingored `organization_id`.

# How the Problems Are Solved

- properly favor `organization_id` over `org_id` and added a note to the
proto.

# Additional Changes

none

# Additional Context

- closes #11269
- requires backport to v4.x
This commit is contained in:
Livio Spring
2026-01-22 06:19:16 +00:00
committed by GitHub
parent 09f67a931a
commit 30d91cde58
4 changed files with 62 additions and 1 deletions
@@ -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,
+5 -1
View File
@@ -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
}
+31
View File
@@ -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{
+1
View File
@@ -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},