mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:37:32 +00:00
feat: add custom org ID to AddOrganizationRequest (#9720)
# Which Problems Are Solved - It is not possible to specify a custom organization ID when creating an organization. According to https://github.com/zitadel/zitadel/discussions/9202#discussioncomment-11929464 this is "an inconsistency in the V2 API". # How the Problems Are Solved - Adds the `org_id` as an optional parameter to the `AddOrganizationRequest` in the `v2beta` API. # Additional Changes None. # Additional Context - Discussion [#9202](https://github.com/zitadel/zitadel/discussions/9202) - I was mostly interested in how much work it'd be to add this field. Then after completing this, I thought I'd submit this PR. I won't be angry if you just close this PR with the reasoning "we didn't ask for it". 😄 - Even though I don't think this is a breaking change, I didn't add this to the `v2` API yet (don't know what the process for this is TBH). The changes should be analogous, so if you want me to, just request it. --------- Co-authored-by: Stefan Benz <46600784+stebenz@users.noreply.github.com>
This commit is contained in:
@@ -81,6 +81,18 @@ func TestServer_AddOrganization(t *testing.T) {
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "no admin, custom org ID",
|
||||
ctx: CTX,
|
||||
req: &org.AddOrganizationRequest{
|
||||
Name: gofakeit.AppName(),
|
||||
OrgId: gu.Ptr("custom-org-ID"),
|
||||
},
|
||||
want: &org.AddOrganizationResponse{
|
||||
OrganizationId: "custom-org-ID",
|
||||
CreatedAdmins: []*org.AddOrganizationResponse_CreatedAdmin{},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "admin with init with userID passed for Human admin",
|
||||
ctx: CTX,
|
||||
|
@@ -38,6 +38,16 @@ func createOrganization(ctx context.Context, name string) orgAttr {
|
||||
}
|
||||
}
|
||||
|
||||
func createOrganizationWithCustomOrgID(ctx context.Context, name string, orgID string) orgAttr {
|
||||
orgResp := Instance.CreateOrganizationWithCustomOrgID(ctx, name, orgID)
|
||||
orgResp.Details.CreationDate = orgResp.Details.ChangeDate
|
||||
return orgAttr{
|
||||
ID: orgResp.GetOrganizationId(),
|
||||
Name: name,
|
||||
Details: orgResp.GetDetails(),
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_ListOrganizations(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
@@ -163,6 +173,35 @@ func TestServer_ListOrganizations(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "list org by custom id, ok",
|
||||
args: args{
|
||||
CTX,
|
||||
&org.ListOrganizationsRequest{},
|
||||
func(ctx context.Context, request *org.ListOrganizationsRequest) ([]orgAttr, error) {
|
||||
orgs := make([]orgAttr, 1)
|
||||
name := fmt.Sprintf("ListOrgs-%s", gofakeit.AppName())
|
||||
orgID := gofakeit.Company()
|
||||
orgs[0] = createOrganizationWithCustomOrgID(ctx, name, orgID)
|
||||
request.Queries = []*org.SearchQuery{
|
||||
OrganizationIdQuery(orgID),
|
||||
}
|
||||
return orgs, nil
|
||||
},
|
||||
},
|
||||
want: &org.ListOrganizationsResponse{
|
||||
Details: &object.ListDetails{
|
||||
TotalResult: 1,
|
||||
Timestamp: timestamppb.Now(),
|
||||
},
|
||||
SortingColumn: 0,
|
||||
Result: []*org.Organization{
|
||||
{
|
||||
State: org.OrganizationState_ORGANIZATION_STATE_ACTIVE,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "list org by name, ok",
|
||||
args: args{
|
||||
|
@@ -31,6 +31,7 @@ func addOrganizationRequestToCommand(request *org.AddOrganizationRequest) (*comm
|
||||
Name: request.GetName(),
|
||||
CustomDomain: "",
|
||||
Admins: admins,
|
||||
OrgID: request.GetOrgId(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@@ -38,6 +38,21 @@ func Test_addOrganizationRequestToCommand(t *testing.T) {
|
||||
},
|
||||
wantErr: zerrors.ThrowUnimplementedf(nil, "ORGv2-SD2r1", "userType oneOf %T in method AddOrganization not implemented", nil),
|
||||
},
|
||||
{
|
||||
name: "custom org ID",
|
||||
args: args{
|
||||
request: &org.AddOrganizationRequest{
|
||||
Name: "custom org ID",
|
||||
OrgId: gu.Ptr("org-ID"),
|
||||
},
|
||||
},
|
||||
want: &command.OrgSetup{
|
||||
Name: "custom org ID",
|
||||
CustomDomain: "",
|
||||
Admins: []*command.OrgSetupAdmin{},
|
||||
OrgID: "org-ID",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "user ID",
|
||||
args: args{
|
||||
|
@@ -79,6 +79,18 @@ func TestServer_AddOrganization(t *testing.T) {
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "no admin, custom org ID",
|
||||
ctx: CTX,
|
||||
req: &org.AddOrganizationRequest{
|
||||
Name: gofakeit.AppName(),
|
||||
OrgId: gu.Ptr("custom-org-ID"),
|
||||
},
|
||||
want: &org.AddOrganizationResponse{
|
||||
OrganizationId: "custom-org-ID",
|
||||
CreatedAdmins: []*org.AddOrganizationResponse_CreatedAdmin{},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "admin with init",
|
||||
ctx: CTX,
|
||||
|
@@ -31,6 +31,7 @@ func addOrganizationRequestToCommand(request *org.AddOrganizationRequest) (*comm
|
||||
Name: request.GetName(),
|
||||
CustomDomain: "",
|
||||
Admins: admins,
|
||||
OrgID: request.GetOrgId(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@@ -39,6 +39,21 @@ func Test_addOrganizationRequestToCommand(t *testing.T) {
|
||||
},
|
||||
wantErr: zerrors.ThrowUnimplementedf(nil, "ORGv2-SD2r1", "userType oneOf %T in method AddOrganization not implemented", nil),
|
||||
},
|
||||
{
|
||||
name: "custom org ID",
|
||||
args: args{
|
||||
request: &org.AddOrganizationRequest{
|
||||
Name: "custom org ID",
|
||||
OrgId: gu.Ptr("org-ID"),
|
||||
},
|
||||
},
|
||||
want: &command.OrgSetup{
|
||||
Name: "custom org ID",
|
||||
CustomDomain: "",
|
||||
Admins: []*command.OrgSetupAdmin{},
|
||||
OrgID: "org-ID",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "user ID",
|
||||
args: args{
|
||||
|
Reference in New Issue
Block a user