From cfe405f225a41415044cd4c1bacc0a0459d092f7 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 20 Nov 2020 02:29:37 +0100 Subject: [PATCH 1/8] Refactor: teams to api convert --- integrations/api_team_test.go | 4 +- modules/convert/convert.go | 49 +++++++++++++++++------ modules/convert/pull_review.go | 7 +++- routers/api/v1/org/team.go | 71 ++++++++++++++++------------------ 4 files changed, 81 insertions(+), 50 deletions(-) diff --git a/integrations/api_team_test.go b/integrations/api_team_test.go index d89385447092f..1fc86c3f5d087 100644 --- a/integrations/api_team_test.go +++ b/integrations/api_team_test.go @@ -127,7 +127,9 @@ func checkTeamResponse(t *testing.T, apiTeam *api.Team, name, description string func checkTeamBean(t *testing.T, id int64, name, description string, includesAllRepositories bool, permission string, units []string) { team := models.AssertExistsAndLoadBean(t, &models.Team{ID: id}).(*models.Team) assert.NoError(t, team.GetUnits(), "GetUnits") - checkTeamResponse(t, convert.ToTeam(team), name, description, includesAllRepositories, permission, units) + apiTeam, err := convert.ToTeam(team) + assert.NoError(t, err) + checkTeamResponse(t, apiTeam, name, description, includesAllRepositories, permission, units) } type TeamSearchResults struct { diff --git a/modules/convert/convert.go b/modules/convert/convert.go index 9b20c683bee27..67fe8b03de01e 100644 --- a/modules/convert/convert.go +++ b/modules/convert/convert.go @@ -284,20 +284,47 @@ func ToOrganization(org *models.User) *api.Organization { } // ToTeam convert models.Team to api.Team -func ToTeam(team *models.Team) *api.Team { - if team == nil { - return nil +func ToTeam(team *models.Team) (*api.Team, error) { + teams, err := ToTeams([]*models.Team{team}) + if err != nil { + return nil, err + } + return teams[0], nil +} + +// ToTeams convert models.Team list to api.Team list +func ToTeams(teams []*models.Team) ([]*api.Team, error) { + if len(teams) == 0 { + return nil, nil } - return &api.Team{ - ID: team.ID, - Name: team.Name, - Description: team.Description, - IncludesAllRepositories: team.IncludesAllRepositories, - CanCreateOrgRepo: team.CanCreateOrgRepo, - Permission: team.Authorize.String(), - Units: team.GetUnitNames(), + cache := make(map[int64]*api.Organization) + apiTeams := make([]*api.Team, len(teams)) + for i := range teams { + apiOrg, ok := cache[teams[i].OrgID] + if !ok { + org, err := models.GetUserByID(teams[i].OrgID) + if err != nil { + return nil, err + } + apiOrg = ToOrganization(org) + cache[teams[i].OrgID] = apiOrg + } + if err := teams[i].GetUnits(); err != nil { + return nil, err + } + apiTeams[i] = &api.Team{ + ID: teams[i].ID, + Name: teams[i].Name, + Description: teams[i].Description, + IncludesAllRepositories: teams[i].IncludesAllRepositories, + CanCreateOrgRepo: teams[i].CanCreateOrgRepo, + Permission: teams[i].Authorize.String(), + Units: teams[i].GetUnitNames(), + } + apiTeams[i].Organization = apiOrg } + return apiTeams, nil } // ToAnnotatedTag convert git.Tag to api.AnnotatedTag diff --git a/modules/convert/pull_review.go b/modules/convert/pull_review.go index 0ef1fec39cd57..40ada64296de7 100644 --- a/modules/convert/pull_review.go +++ b/modules/convert/pull_review.go @@ -25,10 +25,15 @@ func ToPullReview(r *models.Review, doer *models.User) (*api.PullReview, error) auth = doer.IsAdmin || doer.ID == r.ReviewerID } + apiTeam, err := ToTeam(r.ReviewerTeam) + if err != nil { + return nil, err + } + result := &api.PullReview{ ID: r.ID, Reviewer: ToUser(r.Reviewer, doer != nil, auth), - ReviewerTeam: ToTeam(r.ReviewerTeam), + ReviewerTeam: apiTeam, State: api.ReviewStateUnknown, Body: r.Content, CommitID: r.CommitID, diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index 443784fb8b8ef..7531c33899cda 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -52,15 +52,12 @@ func ListTeams(ctx *context.APIContext) { return } - apiTeams := make([]*api.Team, len(org.Teams)) - for i := range org.Teams { - if err := org.Teams[i].GetUnits(); err != nil { - ctx.Error(http.StatusInternalServerError, "GetUnits", err) - return - } - - apiTeams[i] = convert.ToTeam(org.Teams[i]) + apiTeams, err := convert.ToTeams(org.Teams) + if err != nil { + ctx.Error(http.StatusInternalServerError, "ConvertToTeams", err) + return } + ctx.JSON(http.StatusOK, apiTeams) } @@ -90,22 +87,12 @@ func ListUserTeams(ctx *context.APIContext) { return } - cache := make(map[int64]*api.Organization) - apiTeams := make([]*api.Team, len(teams)) - for i := range teams { - apiOrg, ok := cache[teams[i].OrgID] - if !ok { - org, err := models.GetUserByID(teams[i].OrgID) - if err != nil { - ctx.Error(http.StatusInternalServerError, "GetUserByID", err) - return - } - apiOrg = convert.ToOrganization(org) - cache[teams[i].OrgID] = apiOrg - } - apiTeams[i] = convert.ToTeam(teams[i]) - apiTeams[i].Organization = apiOrg + apiTeams, err := convert.ToTeams(teams) + if err != nil { + ctx.Error(http.StatusInternalServerError, "ConvertToTeams", err) + return } + ctx.JSON(http.StatusOK, apiTeams) } @@ -127,7 +114,13 @@ func GetTeam(ctx *context.APIContext) { // "200": // "$ref": "#/responses/Team" - ctx.JSON(http.StatusOK, convert.ToTeam(ctx.Org.Team)) + apiTeam, err := convert.ToTeam(ctx.Org.Team) + if err != nil { + ctx.InternalServerError(err) + return + } + + ctx.JSON(http.StatusOK, apiTeam) } // CreateTeam api for create a team @@ -186,7 +179,12 @@ func CreateTeam(ctx *context.APIContext, form api.CreateTeamOption) { return } - ctx.JSON(http.StatusCreated, convert.ToTeam(team)) + apiTeam, err := convert.ToTeam(ctx.Org.Team) + if err != nil { + ctx.InternalServerError(err) + return + } + ctx.JSON(http.StatusCreated, apiTeam) } // EditTeam api for edit a team @@ -265,7 +263,13 @@ func EditTeam(ctx *context.APIContext, form api.EditTeamOption) { ctx.Error(http.StatusInternalServerError, "EditTeam", err) return } - ctx.JSON(http.StatusOK, convert.ToTeam(team)) + + apiTeam, err := convert.ToTeam(ctx.Org.Team) + if err != nil { + ctx.InternalServerError(err) + return + } + ctx.JSON(http.StatusOK, apiTeam) } // DeleteTeam api for delete a team @@ -671,17 +675,10 @@ func SearchTeam(ctx *context.APIContext) { return } - apiTeams := make([]*api.Team, len(teams)) - for i := range teams { - if err := teams[i].GetUnits(); err != nil { - log.Error("Team GetUnits failed: %v", err) - ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ - "ok": false, - "error": "SearchTeam failed to get units", - }) - return - } - apiTeams[i] = convert.ToTeam(teams[i]) + apiTeams, err := convert.ToTeams(teams) + if err != nil { + ctx.InternalServerError(err) + return } ctx.SetLinkHeader(int(maxResults), listOptions.PageSize) From 8989fd86d6a79009450de5e53d2365c61897ec2e Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 30 Mar 2021 19:47:43 +0200 Subject: [PATCH 2/8] adopt --- routers/api/v1/repo/teams.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/routers/api/v1/repo/teams.go b/routers/api/v1/repo/teams.go index 1348205ec95b8..5714d117f6c29 100644 --- a/routers/api/v1/repo/teams.go +++ b/routers/api/v1/repo/teams.go @@ -11,7 +11,6 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" - api "code.gitea.io/gitea/modules/structs" ) // ListTeams list a repository's teams @@ -47,14 +46,10 @@ func ListTeams(ctx *context.APIContext) { return } - apiTeams := make([]*api.Team, len(teams)) - for i := range teams { - if err := teams[i].GetUnits(); err != nil { - ctx.Error(http.StatusInternalServerError, "GetUnits", err) - return - } - - apiTeams[i] = convert.ToTeam(teams[i]) + apiTeams, err := convert.ToTeams(teams) + if err != nil { + ctx.InternalServerError(err) + return } ctx.JSON(http.StatusOK, apiTeams) @@ -102,11 +97,11 @@ func IsTeam(ctx *context.APIContext) { } if team.HasRepository(ctx.Repo.Repository.ID) { - if err := team.GetUnits(); err != nil { - ctx.Error(http.StatusInternalServerError, "GetUnits", err) + apiTeam, err := convert.ToTeam(team) + if err != nil { + ctx.InternalServerError(err) return } - apiTeam := convert.ToTeam(team) ctx.JSON(http.StatusOK, apiTeam) return } From 2bf358d9a9ba5cdf671c750a8fbb95bddd3d4a41 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 22 Oct 2021 18:26:51 +0200 Subject: [PATCH 3/8] Update modules/convert/convert.go Co-authored-by: delvh --- modules/convert/convert.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/convert/convert.go b/modules/convert/convert.go index 412be33a6e5e3..e6a1407efdc1c 100644 --- a/modules/convert/convert.go +++ b/modules/convert/convert.go @@ -318,13 +318,13 @@ func ToTeams(teams []*models.Team) ([]*api.Team, error) { apiTeams[i] = &api.Team{ ID: teams[i].ID, Name: teams[i].Name, + Organization: apiOrg, Description: teams[i].Description, IncludesAllRepositories: teams[i].IncludesAllRepositories, CanCreateOrgRepo: teams[i].CanCreateOrgRepo, Permission: teams[i].Authorize.String(), Units: teams[i].GetUnitNames(), } - apiTeams[i].Organization = apiOrg } return apiTeams, nil } From 2e2ea9c99b1e8092976107cc86413504d2e310c6 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 4 Jan 2022 06:26:56 +0100 Subject: [PATCH 4/8] adapt --- modules/convert/issue_comment.go | 2 +- modules/convert/repository.go | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/modules/convert/issue_comment.go b/modules/convert/issue_comment.go index caba2b506e435..6d72849bca253 100644 --- a/modules/convert/issue_comment.go +++ b/modules/convert/issue_comment.go @@ -152,7 +152,7 @@ func ToTimelineComment(c *models.Comment, doer *user_model.User) *api.TimelineCo comment.Assignee = ToUser(c.Assignee, nil) } if c.AssigneeTeam != nil { - comment.AssigneeTeam = ToTeam(c.AssigneeTeam) + comment.AssigneeTeam, _ = ToTeam(c.AssigneeTeam) } if c.ResolveDoer != nil { diff --git a/modules/convert/repository.go b/modules/convert/repository.go index 725b04e2ca8a4..4ec8826910dfa 100644 --- a/modules/convert/repository.go +++ b/modules/convert/repository.go @@ -172,10 +172,7 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo // ToRepoTransfer convert a models.RepoTransfer to a structs.RepeTransfer func ToRepoTransfer(t *models.RepoTransfer) *api.RepoTransfer { - var teams []*api.Team - for _, v := range t.Teams { - teams = append(teams, ToTeam(v)) - } + teams, _ := ToTeams(t.Teams) return &api.RepoTransfer{ Doer: ToUser(t.Doer, nil), From 1fa3cccce213b9185cfca506697ee0d177e02fd1 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 12 May 2022 22:02:05 +0200 Subject: [PATCH 5/8] fix nil issue --- modules/convert/convert.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/convert/convert.go b/modules/convert/convert.go index 3c657b34812a3..a9554f018874c 100644 --- a/modules/convert/convert.go +++ b/modules/convert/convert.go @@ -307,7 +307,7 @@ func ToOrganization(org *organization.Organization) *api.Organization { // ToTeam convert models.Team to api.Team func ToTeam(team *organization.Team) (*api.Team, error) { teams, err := ToTeams([]*organization.Team{team}) - if err != nil { + if err != nil || len(teams) == 0 { return nil, err } return teams[0], nil From 9b3d786ad8cfe20108d5c6e380f61da85e4f3778 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 13 May 2022 00:00:15 +0200 Subject: [PATCH 6/8] make org load optional --- modules/convert/convert.go | 30 +++++++++++++++++------------- modules/convert/repository.go | 2 +- routers/api/v1/org/team.go | 6 +++--- routers/api/v1/repo/teams.go | 2 +- routers/web/org/teams.go | 2 +- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/modules/convert/convert.go b/modules/convert/convert.go index a9554f018874c..53357e75055f8 100644 --- a/modules/convert/convert.go +++ b/modules/convert/convert.go @@ -305,8 +305,8 @@ func ToOrganization(org *organization.Organization) *api.Organization { } // ToTeam convert models.Team to api.Team -func ToTeam(team *organization.Team) (*api.Team, error) { - teams, err := ToTeams([]*organization.Team{team}) +func ToTeam(team *organization.Team, loadOrg ...bool) (*api.Team, error) { + teams, err := ToTeams([]*organization.Team{team}, len(loadOrg) != 0 && loadOrg[0]) if err != nil || len(teams) == 0 { return nil, err } @@ -314,7 +314,7 @@ func ToTeam(team *organization.Team) (*api.Team, error) { } // ToTeams convert models.Team list to api.Team list -func ToTeams(teams []*organization.Team) ([]*api.Team, error) { +func ToTeams(teams []*organization.Team, loadOrgs bool) ([]*api.Team, error) { if len(teams) == 0 || teams[0] == nil { return nil, nil } @@ -322,22 +322,13 @@ func ToTeams(teams []*organization.Team) ([]*api.Team, error) { cache := make(map[int64]*api.Organization) apiTeams := make([]*api.Team, len(teams)) for i := range teams { - apiOrg, ok := cache[teams[i].OrgID] - if !ok { - org, err := organization.GetOrgByID(teams[i].OrgID) - if err != nil { - return nil, err - } - apiOrg = ToOrganization(org) - cache[teams[i].OrgID] = apiOrg - } if err := teams[i].GetUnits(); err != nil { return nil, err } + apiTeams[i] = &api.Team{ ID: teams[i].ID, Name: teams[i].Name, - Organization: apiOrg, // todo!!! Description: teams[i].Description, IncludesAllRepositories: teams[i].IncludesAllRepositories, CanCreateOrgRepo: teams[i].CanCreateOrgRepo, @@ -345,6 +336,19 @@ func ToTeams(teams []*organization.Team) ([]*api.Team, error) { Units: teams[i].GetUnitNames(), UnitsMap: teams[i].GetUnitsMap(), } + + if loadOrgs { + apiOrg, ok := cache[teams[i].OrgID] + if !ok { + org, err := organization.GetOrgByID(teams[i].OrgID) + if err != nil { + return nil, err + } + apiOrg = ToOrganization(org) + cache[teams[i].OrgID] = apiOrg + } + apiTeams[i].Organization = apiOrg + } } return apiTeams, nil } diff --git a/modules/convert/repository.go b/modules/convert/repository.go index cc8bf3fa8e4d3..b813d696994c3 100644 --- a/modules/convert/repository.go +++ b/modules/convert/repository.go @@ -186,7 +186,7 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo // ToRepoTransfer convert a models.RepoTransfer to a structs.RepeTransfer func ToRepoTransfer(t *models.RepoTransfer) *api.RepoTransfer { - teams, _ := ToTeams(t.Teams) + teams, _ := ToTeams(t.Teams, false) return &api.RepoTransfer{ Doer: ToUser(t.Doer, nil), diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index 321b13b9bacaf..516e9a9c02db2 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -58,7 +58,7 @@ func ListTeams(ctx *context.APIContext) { return } - apiTeams, err := convert.ToTeams(teams) + apiTeams, err := convert.ToTeams(teams, false) if err != nil { ctx.Error(http.StatusInternalServerError, "ConvertToTeams", err) return @@ -97,7 +97,7 @@ func ListUserTeams(ctx *context.APIContext) { return } - apiTeams, err := convert.ToTeams(teams) + apiTeams, err := convert.ToTeams(teams, true) if err != nil { ctx.Error(http.StatusInternalServerError, "ConvertToTeams", err) return @@ -775,7 +775,7 @@ func SearchTeam(ctx *context.APIContext) { return } - apiTeams, err := convert.ToTeams(teams) + apiTeams, err := convert.ToTeams(teams, false) if err != nil { ctx.InternalServerError(err) return diff --git a/routers/api/v1/repo/teams.go b/routers/api/v1/repo/teams.go index 6890cc6824336..e414d8b60ed05 100644 --- a/routers/api/v1/repo/teams.go +++ b/routers/api/v1/repo/teams.go @@ -47,7 +47,7 @@ func ListTeams(ctx *context.APIContext) { return } - apiTeams, err := convert.ToTeams(teams) + apiTeams, err := convert.ToTeams(teams, false) if err != nil { ctx.InternalServerError(err) return diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index 5ea097a153295..3689ffe93d9ac 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -356,7 +356,7 @@ func SearchTeam(ctx *context.Context) { return } - apiTeams, err := convert.ToTeams(teams) + apiTeams, err := convert.ToTeams(teams, false) if err != nil { log.Error("convert ToTeams failed: %v", err) ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ From c061ec9f9fb59c7b5f152b7ac82f3dc05a1bb413 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 13 May 2022 00:18:15 +0200 Subject: [PATCH 7/8] more info in tests --- integrations/api_team_test.go | 22 +++++++++++----------- integrations/org_test.go | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/integrations/api_team_test.go b/integrations/api_team_test.go index 8dbf4496efcfa..d571342c3d618 100644 --- a/integrations/api_team_test.go +++ b/integrations/api_team_test.go @@ -69,7 +69,7 @@ func TestAPITeam(t *testing.T) { resp = session.MakeRequest(t, req, http.StatusCreated) apiTeam = api.Team{} DecodeJSON(t, resp, &apiTeam) - checkTeamResponse(t, &apiTeam, teamToCreate.Name, teamToCreate.Description, teamToCreate.IncludesAllRepositories, + checkTeamResponse(t, "CreateTeam1", &apiTeam, teamToCreate.Name, teamToCreate.Description, teamToCreate.IncludesAllRepositories, teamToCreate.Permission, teamToCreate.Units, nil) checkTeamBean(t, apiTeam.ID, teamToCreate.Name, teamToCreate.Description, teamToCreate.IncludesAllRepositories, teamToCreate.Permission, teamToCreate.Units, nil) @@ -90,7 +90,7 @@ func TestAPITeam(t *testing.T) { resp = session.MakeRequest(t, req, http.StatusOK) apiTeam = api.Team{} DecodeJSON(t, resp, &apiTeam) - checkTeamResponse(t, &apiTeam, teamToEdit.Name, *teamToEdit.Description, *teamToEdit.IncludesAllRepositories, + checkTeamResponse(t, "EditTeam1", &apiTeam, teamToEdit.Name, *teamToEdit.Description, *teamToEdit.IncludesAllRepositories, teamToEdit.Permission, unit.AllUnitKeyNames(), nil) checkTeamBean(t, apiTeam.ID, teamToEdit.Name, *teamToEdit.Description, *teamToEdit.IncludesAllRepositories, teamToEdit.Permission, unit.AllUnitKeyNames(), nil) @@ -102,7 +102,7 @@ func TestAPITeam(t *testing.T) { resp = session.MakeRequest(t, req, http.StatusOK) apiTeam = api.Team{} DecodeJSON(t, resp, &apiTeam) - checkTeamResponse(t, &apiTeam, teamToEdit.Name, *teamToEditDesc.Description, *teamToEdit.IncludesAllRepositories, + checkTeamResponse(t, "EditTeam1_DescOnly", &apiTeam, teamToEdit.Name, *teamToEditDesc.Description, *teamToEdit.IncludesAllRepositories, teamToEdit.Permission, unit.AllUnitKeyNames(), nil) checkTeamBean(t, apiTeam.ID, teamToEdit.Name, *teamToEditDesc.Description, *teamToEdit.IncludesAllRepositories, teamToEdit.Permission, unit.AllUnitKeyNames(), nil) @@ -114,7 +114,7 @@ func TestAPITeam(t *testing.T) { resp = session.MakeRequest(t, req, http.StatusOK) apiTeam = api.Team{} DecodeJSON(t, resp, &apiTeam) - checkTeamResponse(t, &apiTeam, teamRead.Name, *teamToEditDesc.Description, teamRead.IncludesAllRepositories, + checkTeamResponse(t, "ReadTeam1", &apiTeam, teamRead.Name, *teamToEditDesc.Description, teamRead.IncludesAllRepositories, teamRead.AccessMode.String(), teamRead.GetUnitNames(), teamRead.GetUnitsMap()) // Delete team. @@ -135,7 +135,7 @@ func TestAPITeam(t *testing.T) { resp = session.MakeRequest(t, req, http.StatusCreated) apiTeam = api.Team{} DecodeJSON(t, resp, &apiTeam) - checkTeamResponse(t, &apiTeam, teamToCreate.Name, teamToCreate.Description, teamToCreate.IncludesAllRepositories, + checkTeamResponse(t, "CreateTeam2", &apiTeam, teamToCreate.Name, teamToCreate.Description, teamToCreate.IncludesAllRepositories, "read", nil, teamToCreate.UnitsMap) checkTeamBean(t, apiTeam.ID, teamToCreate.Name, teamToCreate.Description, teamToCreate.IncludesAllRepositories, "read", nil, teamToCreate.UnitsMap) @@ -156,7 +156,7 @@ func TestAPITeam(t *testing.T) { resp = session.MakeRequest(t, req, http.StatusOK) apiTeam = api.Team{} DecodeJSON(t, resp, &apiTeam) - checkTeamResponse(t, &apiTeam, teamToEdit.Name, *teamToEdit.Description, *teamToEdit.IncludesAllRepositories, + checkTeamResponse(t, "EditTeam2", &apiTeam, teamToEdit.Name, *teamToEdit.Description, *teamToEdit.IncludesAllRepositories, "read", nil, teamToEdit.UnitsMap) checkTeamBean(t, apiTeam.ID, teamToEdit.Name, *teamToEdit.Description, *teamToEdit.IncludesAllRepositories, "read", nil, teamToEdit.UnitsMap) @@ -168,7 +168,7 @@ func TestAPITeam(t *testing.T) { resp = session.MakeRequest(t, req, http.StatusOK) apiTeam = api.Team{} DecodeJSON(t, resp, &apiTeam) - checkTeamResponse(t, &apiTeam, teamToEdit.Name, *teamToEditDesc.Description, *teamToEdit.IncludesAllRepositories, + checkTeamResponse(t, "EditTeam2_DescOnly", &apiTeam, teamToEdit.Name, *teamToEditDesc.Description, *teamToEdit.IncludesAllRepositories, "read", nil, teamToEdit.UnitsMap) checkTeamBean(t, apiTeam.ID, teamToEdit.Name, *teamToEditDesc.Description, *teamToEdit.IncludesAllRepositories, "read", nil, teamToEdit.UnitsMap) @@ -180,7 +180,7 @@ func TestAPITeam(t *testing.T) { apiTeam = api.Team{} DecodeJSON(t, resp, &apiTeam) assert.NoError(t, teamRead.GetUnits()) - checkTeamResponse(t, &apiTeam, teamRead.Name, *teamToEditDesc.Description, teamRead.IncludesAllRepositories, + checkTeamResponse(t, "ReadTeam2", &apiTeam, teamRead.Name, *teamToEditDesc.Description, teamRead.IncludesAllRepositories, teamRead.AccessMode.String(), teamRead.GetUnitNames(), teamRead.GetUnitsMap()) // Delete team. @@ -189,8 +189,8 @@ func TestAPITeam(t *testing.T) { unittest.AssertNotExistsBean(t, &organization.Team{ID: teamID}) } -func checkTeamResponse(t *testing.T, apiTeam *api.Team, name, description string, includesAllRepositories bool, permission string, units []string, unitsMap map[string]string) { - t.Run(name+description, func(t *testing.T) { +func checkTeamResponse(t *testing.T, testName string, apiTeam *api.Team, name, description string, includesAllRepositories bool, permission string, units []string, unitsMap map[string]string) { + t.Run(testName, func(t *testing.T) { assert.Equal(t, name, apiTeam.Name, "name") assert.Equal(t, description, apiTeam.Description, "description") assert.Equal(t, includesAllRepositories, apiTeam.IncludesAllRepositories, "includesAllRepositories") @@ -211,7 +211,7 @@ func checkTeamBean(t *testing.T, id int64, name, description string, includesAll assert.NoError(t, team.GetUnits(), "GetUnits") apiTeam, err := convert.ToTeam(team) assert.NoError(t, err) - checkTeamResponse(t, apiTeam, name, description, includesAllRepositories, permission, units, unitsMap) + checkTeamResponse(t, fmt.Sprintf("checkTeamBean/%s_%s", name, description), apiTeam, name, description, includesAllRepositories, permission, units, unitsMap) } type TeamSearchResults struct { diff --git a/integrations/org_test.go b/integrations/org_test.go index 227a1b8d40376..d755385726a55 100644 --- a/integrations/org_test.go +++ b/integrations/org_test.go @@ -157,7 +157,7 @@ func TestOrgRestrictedUser(t *testing.T) { resp := adminSession.MakeRequest(t, req, http.StatusCreated) DecodeJSON(t, resp, &apiTeam) - checkTeamResponse(t, &apiTeam, teamToCreate.Name, teamToCreate.Description, teamToCreate.IncludesAllRepositories, + checkTeamResponse(t, "CreateTeam_codereader", &apiTeam, teamToCreate.Name, teamToCreate.Description, teamToCreate.IncludesAllRepositories, teamToCreate.Permission, teamToCreate.Units, nil) checkTeamBean(t, apiTeam.ID, teamToCreate.Name, teamToCreate.Description, teamToCreate.IncludesAllRepositories, teamToCreate.Permission, teamToCreate.Units, nil) From e1502690d115952c1d2307753e91314327975157 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 13 May 2022 00:22:33 +0200 Subject: [PATCH 8/8] fix long standing issue --- routers/api/v1/org/team.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index 516e9a9c02db2..f8c37303d6759 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -223,7 +223,7 @@ func CreateTeam(ctx *context.APIContext) { return } - apiTeam, err := convert.ToTeam(ctx.Org.Team) + apiTeam, err := convert.ToTeam(team) if err != nil { ctx.InternalServerError(err) return @@ -306,7 +306,7 @@ func EditTeam(ctx *context.APIContext) { return } - apiTeam, err := convert.ToTeam(ctx.Org.Team) + apiTeam, err := convert.ToTeam(team) if err != nil { ctx.InternalServerError(err) return