mirror of
https://github.com/zitadel/zitadel.git
synced 2025-02-28 23:17:23 +00:00
fix: custom userID not being added when specified in zitadel.org.v2.AddOrganizationRequest.AddOrganization() request (#9334)
# Which Problems Are Solved When specifying a `user_id` as a human admin in `zitadel.org.v2.AddOrganizationRequest.AddOrganization()` the `user_id` specified in the request should have been used, before it was being ignored, this has been fixed with this PR # Additional Context - Closes https://github.com/zitadel/zitadel/issues/9308 --------- Co-authored-by: Iraq Jaber <IraqJaber@gmail.com>
This commit is contained in:
parent
bd4e53314d
commit
66296db971
@ -43,6 +43,7 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
func TestServer_AddOrganization(t *testing.T) {
|
func TestServer_AddOrganization(t *testing.T) {
|
||||||
idpResp := Instance.AddGenericOAuthProvider(CTX, Instance.DefaultOrg.Id)
|
idpResp := Instance.AddGenericOAuthProvider(CTX, Instance.DefaultOrg.Id)
|
||||||
|
userId := "userID"
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -81,7 +82,7 @@ func TestServer_AddOrganization(t *testing.T) {
|
|||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "admin with init",
|
name: "admin with init with userID passed for Human admin",
|
||||||
ctx: CTX,
|
ctx: CTX,
|
||||||
req: &org.AddOrganizationRequest{
|
req: &org.AddOrganizationRequest{
|
||||||
Name: gofakeit.AppName(),
|
Name: gofakeit.AppName(),
|
||||||
@ -89,6 +90,7 @@ func TestServer_AddOrganization(t *testing.T) {
|
|||||||
{
|
{
|
||||||
UserType: &org.AddOrganizationRequest_Admin_Human{
|
UserType: &org.AddOrganizationRequest_Admin_Human{
|
||||||
Human: &user.AddHumanUserRequest{
|
Human: &user.AddHumanUserRequest{
|
||||||
|
UserId: &userId,
|
||||||
Profile: &user.SetHumanProfile{
|
Profile: &user.SetHumanProfile{
|
||||||
GivenName: "firstname",
|
GivenName: "firstname",
|
||||||
FamilyName: "lastname",
|
FamilyName: "lastname",
|
||||||
@ -108,7 +110,7 @@ func TestServer_AddOrganization(t *testing.T) {
|
|||||||
OrganizationId: integration.NotEmpty,
|
OrganizationId: integration.NotEmpty,
|
||||||
CreatedAdmins: []*org.AddOrganizationResponse_CreatedAdmin{
|
CreatedAdmins: []*org.AddOrganizationResponse_CreatedAdmin{
|
||||||
{
|
{
|
||||||
UserId: integration.NotEmpty,
|
UserId: userId,
|
||||||
EmailCode: gu.Ptr(integration.NotEmpty),
|
EmailCode: gu.Ptr(integration.NotEmpty),
|
||||||
PhoneCode: nil,
|
PhoneCode: nil,
|
||||||
},
|
},
|
||||||
@ -140,7 +142,7 @@ func TestServer_AddOrganization(t *testing.T) {
|
|||||||
IdpLinks: []*user.IDPLink{
|
IdpLinks: []*user.IDPLink{
|
||||||
{
|
{
|
||||||
IdpId: idpResp.Id,
|
IdpId: idpResp.Id,
|
||||||
UserId: "userID",
|
UserId: userId,
|
||||||
UserName: "username",
|
UserName: "username",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -57,6 +57,7 @@ func addOrganizationRequestAdminToCommand(admin *org.AddOrganizationRequest_Admi
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &command.OrgSetupAdmin{
|
return &command.OrgSetupAdmin{
|
||||||
Human: human,
|
Human: human,
|
||||||
Roles: admin.GetRoles(),
|
Roles: admin.GetRoles(),
|
||||||
|
@ -96,16 +96,24 @@ func (c *orgSetupCommands) setupOrgAdmin(admin *OrgSetupAdmin, allowInitialMail
|
|||||||
c.validations = append(c.validations, c.commands.AddOrgMemberCommand(c.aggregate, admin.ID, orgAdminRoles(admin.Roles)...))
|
c.validations = append(c.validations, c.commands.AddOrgMemberCommand(c.aggregate, admin.ID, orgAdminRoles(admin.Roles)...))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
userID, err := c.commands.idGenerator.Next()
|
|
||||||
|
var userID string
|
||||||
|
if admin.Human != nil && admin.Human.ID != "" {
|
||||||
|
userID = admin.Human.ID
|
||||||
|
} else {
|
||||||
|
var err error
|
||||||
|
userID, err = c.commands.idGenerator.Next()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if admin.Human != nil {
|
if admin.Human != nil {
|
||||||
admin.Human.ID = userID
|
admin.Human.ID = userID
|
||||||
c.validations = append(c.validations, c.commands.AddHumanCommand(admin.Human, c.aggregate.ID, c.commands.userPasswordHasher, c.commands.userEncryption, allowInitialMail))
|
c.validations = append(c.validations, c.commands.AddHumanCommand(admin.Human, c.aggregate.ID, c.commands.userPasswordHasher, c.commands.userEncryption, allowInitialMail))
|
||||||
} else if admin.Machine != nil {
|
} else if admin.Machine != nil {
|
||||||
admin.Machine.Machine.AggregateID = userID
|
admin.Machine.Machine.AggregateID = userID
|
||||||
if err = c.setupOrgAdminMachine(c.aggregate, admin.Machine); err != nil {
|
if err := c.setupOrgAdminMachine(c.aggregate, admin.Machine); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,7 +187,7 @@ func (c *orgSetupCommands) push(ctx context.Context) (_ *CreatedOrg, err error)
|
|||||||
func (c *orgSetupCommands) createdAdmins() []*CreatedOrgAdmin {
|
func (c *orgSetupCommands) createdAdmins() []*CreatedOrgAdmin {
|
||||||
users := make([]*CreatedOrgAdmin, 0, len(c.admins))
|
users := make([]*CreatedOrgAdmin, 0, len(c.admins))
|
||||||
for _, admin := range c.admins {
|
for _, admin := range c.admins {
|
||||||
if admin.ID != "" {
|
if admin.ID != "" && admin.Human == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if admin.Human != nil {
|
if admin.Human != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user