mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 18:07:31 +00:00
feat(api): reworking AddOrganization() API call to return all admins (#9900)
This commit is contained in:
@@ -54,7 +54,11 @@ type orgSetupCommands struct {
|
||||
|
||||
type CreatedOrg struct {
|
||||
ObjectDetails *domain.ObjectDetails
|
||||
CreatedAdmins []*CreatedOrgAdmin
|
||||
OrgAdmins []OrgAdmin
|
||||
}
|
||||
|
||||
type OrgAdmin interface {
|
||||
GetID() string
|
||||
}
|
||||
|
||||
type CreatedOrgAdmin struct {
|
||||
@@ -65,6 +69,18 @@ type CreatedOrgAdmin struct {
|
||||
MachineKey *MachineKey
|
||||
}
|
||||
|
||||
func (a *CreatedOrgAdmin) GetID() string {
|
||||
return a.ID
|
||||
}
|
||||
|
||||
type AssignedOrgAdmin struct {
|
||||
ID string
|
||||
}
|
||||
|
||||
func (a *AssignedOrgAdmin) GetID() string {
|
||||
return a.ID
|
||||
}
|
||||
|
||||
func (o *OrgSetup) Validate() (err error) {
|
||||
if o.OrgID != "" && strings.TrimSpace(o.OrgID) == "" {
|
||||
return zerrors.ThrowInvalidArgument(nil, "ORG-4ABd3", "Errors.Invalid.Argument")
|
||||
@@ -188,14 +204,15 @@ func (c *orgSetupCommands) push(ctx context.Context) (_ *CreatedOrg, err error)
|
||||
EventDate: events[len(events)-1].CreatedAt(),
|
||||
ResourceOwner: c.aggregate.ID,
|
||||
},
|
||||
CreatedAdmins: c.createdAdmins(),
|
||||
OrgAdmins: c.createdAdmins(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *orgSetupCommands) createdAdmins() []*CreatedOrgAdmin {
|
||||
users := make([]*CreatedOrgAdmin, 0, len(c.admins))
|
||||
func (c *orgSetupCommands) createdAdmins() []OrgAdmin {
|
||||
users := make([]OrgAdmin, 0, len(c.admins))
|
||||
for _, admin := range c.admins {
|
||||
if admin.ID != "" && admin.Human == nil {
|
||||
users = append(users, &AssignedOrgAdmin{ID: admin.ID})
|
||||
continue
|
||||
}
|
||||
if admin.Human != nil {
|
||||
|
@@ -1531,8 +1531,8 @@ func TestCommandSide_SetUpOrg(t *testing.T) {
|
||||
ObjectDetails: &domain.ObjectDetails{
|
||||
ResourceOwner: "orgID",
|
||||
},
|
||||
CreatedAdmins: []*CreatedOrgAdmin{
|
||||
{
|
||||
OrgAdmins: []OrgAdmin{
|
||||
&CreatedOrgAdmin{
|
||||
ID: "userID",
|
||||
},
|
||||
},
|
||||
@@ -1574,7 +1574,7 @@ func TestCommandSide_SetUpOrg(t *testing.T) {
|
||||
ObjectDetails: &domain.ObjectDetails{
|
||||
ResourceOwner: "custom-org-ID",
|
||||
},
|
||||
CreatedAdmins: []*CreatedOrgAdmin{},
|
||||
OrgAdmins: []OrgAdmin{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1641,7 +1641,11 @@ func TestCommandSide_SetUpOrg(t *testing.T) {
|
||||
ObjectDetails: &domain.ObjectDetails{
|
||||
ResourceOwner: "orgID",
|
||||
},
|
||||
CreatedAdmins: []*CreatedOrgAdmin{},
|
||||
OrgAdmins: []OrgAdmin{
|
||||
&AssignedOrgAdmin{
|
||||
ID: "userID",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1751,8 +1755,8 @@ func TestCommandSide_SetUpOrg(t *testing.T) {
|
||||
ObjectDetails: &domain.ObjectDetails{
|
||||
ResourceOwner: "orgID",
|
||||
},
|
||||
CreatedAdmins: []*CreatedOrgAdmin{
|
||||
{
|
||||
OrgAdmins: []OrgAdmin{
|
||||
&CreatedOrgAdmin{
|
||||
ID: "userID",
|
||||
PAT: &PersonalAccessToken{
|
||||
ObjectRoot: models.ObjectRoot{
|
||||
|
Reference in New Issue
Block a user