From 19dca0f298d65714e63349829bfe9300a80c5b90 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Sun, 19 Feb 2023 00:53:28 +0900 Subject: [PATCH 1/2] rename GetUnit to LoadUnit --- models/organization/team.go | 10 +++------- models/organization/team_list.go | 2 +- routers/api/v1/org/team.go | 2 +- services/convert/convert.go | 2 +- tests/integration/api_team_test.go | 6 +++--- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/models/organization/team.go b/models/organization/team.go index 0c2577dab15ae..5e3c9ecffe22b 100644 --- a/models/organization/team.go +++ b/models/organization/team.go @@ -111,12 +111,8 @@ func (t *Team) ColorFormat(s fmt.State) { t.AccessMode) } -// GetUnits return a list of available units for a team -func (t *Team) GetUnits() error { - return t.getUnits(db.DefaultContext) -} - -func (t *Team) getUnits(ctx context.Context) (err error) { +// LoadUnits load a list of available units for a team +func (t *Team) LoadUnits(ctx context.Context) (err error) { if t.Units != nil { return nil } @@ -193,7 +189,7 @@ func (t *Team) UnitEnabled(ctx context.Context, tp unit.Type) bool { // UnitAccessMode returns if the team has the given unit type enabled func (t *Team) UnitAccessMode(ctx context.Context, tp unit.Type) perm.AccessMode { - if err := t.getUnits(ctx); err != nil { + if err := t.LoadUnits(ctx); err != nil { log.Warn("Error loading team (ID: %d) units: %s", t.ID, err.Error()) } diff --git a/models/organization/team_list.go b/models/organization/team_list.go index 5d3bd555cc285..efb3104ad5971 100644 --- a/models/organization/team_list.go +++ b/models/organization/team_list.go @@ -19,7 +19,7 @@ type TeamList []*Team func (t TeamList) LoadUnits(ctx context.Context) error { for _, team := range t { - if err := team.getUnits(ctx); err != nil { + if err := team.LoadUnits(ctx); err != nil { return err } } diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index 686e48ece3d64..f92556227cb8b 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -256,7 +256,7 @@ func EditTeam(ctx *context.APIContext) { form := web.GetForm(ctx).(*api.EditTeamOption) team := ctx.Org.Team - if err := team.GetUnits(); err != nil { + if err := team.LoadUnits(ctx.Context); err != nil { ctx.InternalServerError(err) return } diff --git a/services/convert/convert.go b/services/convert/convert.go index 16daad849b331..5f2100a039409 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -304,7 +304,7 @@ func ToTeams(ctx context.Context, teams []*organization.Team, loadOrgs bool) ([] cache := make(map[int64]*api.Organization) apiTeams := make([]*api.Team, len(teams)) for i := range teams { - if err := teams[i].GetUnits(); err != nil { + if err := teams[i].LoadUnits(ctx); err != nil { return nil, err } diff --git a/tests/integration/api_team_test.go b/tests/integration/api_team_test.go index 7920513136547..2801fdc98934e 100644 --- a/tests/integration/api_team_test.go +++ b/tests/integration/api_team_test.go @@ -111,7 +111,7 @@ func TestAPITeam(t *testing.T) { // Read team. teamRead := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID}) - assert.NoError(t, teamRead.GetUnits()) + assert.NoError(t, teamRead.LoadUnits(db.DefaultContext)) req = NewRequestf(t, "GET", "/api/v1/teams/%d?token="+token, teamID) resp = MakeRequest(t, req, http.StatusOK) apiTeam = api.Team{} @@ -181,7 +181,7 @@ func TestAPITeam(t *testing.T) { resp = MakeRequest(t, req, http.StatusOK) apiTeam = api.Team{} DecodeJSON(t, resp, &apiTeam) - assert.NoError(t, teamRead.GetUnits()) + assert.NoError(t, teamRead.LoadUnits(db.DefaultContext)) checkTeamResponse(t, "ReadTeam2", &apiTeam, teamRead.Name, *teamToEditDesc.Description, teamRead.IncludesAllRepositories, teamRead.AccessMode.String(), teamRead.GetUnitNames(), teamRead.GetUnitsMap()) @@ -210,7 +210,7 @@ func checkTeamResponse(t *testing.T, testName string, apiTeam *api.Team, name, d func checkTeamBean(t *testing.T, id int64, name, description string, includesAllRepositories bool, permission string, units []string, unitsMap map[string]string) { team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: id}) - assert.NoError(t, team.GetUnits(), "GetUnits") + assert.NoError(t, team.LoadUnits(db.DefaultContext), "LoadUnits") apiTeam, err := convert.ToTeam(db.DefaultContext, team) assert.NoError(t, err) checkTeamResponse(t, fmt.Sprintf("checkTeamBean/%s_%s", name, description), apiTeam, name, description, includesAllRepositories, permission, units, unitsMap) From c40582704303c30c3481c57bf3c561eb0235afce Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Sun, 19 Feb 2023 13:34:52 +0900 Subject: [PATCH 2/2] Update routers/api/v1/org/team.go --- routers/api/v1/org/team.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index f92556227cb8b..0c6926759a768 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -256,7 +256,7 @@ func EditTeam(ctx *context.APIContext) { form := web.GetForm(ctx).(*api.EditTeamOption) team := ctx.Org.Team - if err := team.LoadUnits(ctx.Context); err != nil { + if err := team.LoadUnits(ctx); err != nil { ctx.InternalServerError(err) return }