|
|
@ -308,40 +308,38 @@ func ToTeam(ctx context.Context, team *organization.Team, loadOrg ...bool) (*api |
|
|
|
|
|
|
|
|
|
|
|
// ToTeams convert models.Team list to api.Team list
|
|
|
|
// ToTeams convert models.Team list to api.Team list
|
|
|
|
func ToTeams(ctx context.Context, teams []*organization.Team, loadOrgs bool) ([]*api.Team, error) { |
|
|
|
func ToTeams(ctx context.Context, teams []*organization.Team, loadOrgs bool) ([]*api.Team, error) { |
|
|
|
if len(teams) == 0 || teams[0] == nil { |
|
|
|
|
|
|
|
return nil, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cache := make(map[int64]*api.Organization) |
|
|
|
cache := make(map[int64]*api.Organization) |
|
|
|
apiTeams := make([]*api.Team, len(teams)) |
|
|
|
apiTeams := make([]*api.Team, 0, len(teams)) |
|
|
|
for i := range teams { |
|
|
|
for _, t := range teams { |
|
|
|
if err := teams[i].LoadUnits(ctx); err != nil { |
|
|
|
if err := t.LoadUnits(ctx); err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
apiTeams[i] = &api.Team{ |
|
|
|
apiTeam := &api.Team{ |
|
|
|
ID: teams[i].ID, |
|
|
|
ID: t.ID, |
|
|
|
Name: teams[i].Name, |
|
|
|
Name: t.Name, |
|
|
|
Description: teams[i].Description, |
|
|
|
Description: t.Description, |
|
|
|
IncludesAllRepositories: teams[i].IncludesAllRepositories, |
|
|
|
IncludesAllRepositories: t.IncludesAllRepositories, |
|
|
|
CanCreateOrgRepo: teams[i].CanCreateOrgRepo, |
|
|
|
CanCreateOrgRepo: t.CanCreateOrgRepo, |
|
|
|
Permission: teams[i].AccessMode.String(), |
|
|
|
Permission: t.AccessMode.String(), |
|
|
|
Units: teams[i].GetUnitNames(), |
|
|
|
Units: t.GetUnitNames(), |
|
|
|
UnitsMap: teams[i].GetUnitsMap(), |
|
|
|
UnitsMap: t.GetUnitsMap(), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if loadOrgs { |
|
|
|
if loadOrgs { |
|
|
|
apiOrg, ok := cache[teams[i].OrgID] |
|
|
|
apiOrg, ok := cache[t.OrgID] |
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
org, err := organization.GetOrgByID(ctx, teams[i].OrgID) |
|
|
|
org, err := organization.GetOrgByID(ctx, t.OrgID) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
apiOrg = ToOrganization(ctx, org) |
|
|
|
apiOrg = ToOrganization(ctx, org) |
|
|
|
cache[teams[i].OrgID] = apiOrg |
|
|
|
cache[t.OrgID] = apiOrg |
|
|
|
} |
|
|
|
} |
|
|
|
apiTeams[i].Organization = apiOrg |
|
|
|
apiTeam.Organization = apiOrg |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apiTeams = append(apiTeams, apiTeam) |
|
|
|
} |
|
|
|
} |
|
|
|
return apiTeams, nil |
|
|
|
return apiTeams, nil |
|
|
|
} |
|
|
|
} |
|
|
|