From 088cffb688fc4f183dc5ca7b99ab4a21f386bc97 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 6 Dec 2024 16:26:56 -0800 Subject: [PATCH] Fix update team --- services/org/team.go | 9 ++++----- services/org/team_test.go | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/services/org/team.go b/services/org/team.go index a8157f4798..2e3c1bd125 100644 --- a/services/org/team.go +++ b/services/org/team.go @@ -12,7 +12,6 @@ import ( git_model "code.gitea.io/gitea/models/git" issues_model "code.gitea.io/gitea/models/issues" "code.gitea.io/gitea/models/organization" - org_model "code.gitea.io/gitea/models/organization" "code.gitea.io/gitea/models/perm" access_model "code.gitea.io/gitea/models/perm/access" repo_model "code.gitea.io/gitea/models/repo" @@ -101,7 +100,7 @@ type UpdateTeamOptions struct { UnitPerms map[unit_model.Type]perm.AccessMode } -func UpdateTeam(ctx context.Context, team *org_model.Team, opts UpdateTeamOptions) error { +func UpdateTeam(ctx context.Context, team *organization.Team, opts UpdateTeamOptions) error { var changedCols []string newAccessMode := team.AccessMode @@ -130,9 +129,9 @@ func UpdateTeam(ctx context.Context, team *org_model.Team, opts UpdateTeamOption changedCols = append(changedCols, "includes_all_repositories") } if len(opts.UnitPerms) > 0 { - units := make([]*org_model.TeamUnit, 0, len(opts.UnitPerms)) + units := make([]*organization.TeamUnit, 0, len(opts.UnitPerms)) for tp, perm := range opts.UnitPerms { - units = append(units, &org_model.TeamUnit{ + units = append(units, &organization.TeamUnit{ OrgID: team.OrgID, TeamID: team.ID, Type: tp, @@ -157,7 +156,7 @@ func UpdateTeam(ctx context.Context, team *org_model.Team, opts UpdateTeamOption team.Description = opts.Description } - return org_model.UpdateTeam(ctx, team, changedCols...) + return organization.UpdateTeam(ctx, team, changedCols...) } // UpdateTeam updates information of team. diff --git a/services/org/team_test.go b/services/org/team_test.go index 9597a9a342..2617c5a090 100644 --- a/services/org/team_test.go +++ b/services/org/team_test.go @@ -78,11 +78,14 @@ func TestUpdateTeam(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 2}) - team.LowerName = "newname" team.Name = "newName" team.Description = strings.Repeat("A long description!", 100) team.AccessMode = perm.AccessModeAdmin - assert.NoError(t, UpdateTeam(db.DefaultContext, team, "name", "lower_name", "description", "authorize")) + assert.NoError(t, UpdateTeam(db.DefaultContext, team, UpdateTeamOptions{ + TeamName: "name", + Description: "description", + IsAdmin: true, + })) team = unittest.AssertExistsAndLoadBean(t, &organization.Team{Name: "newName"}) assert.True(t, strings.HasPrefix(team.Description, "A long description!")) @@ -101,7 +104,10 @@ func TestUpdateTeam2(t *testing.T) { team.LowerName = "owners" team.Name = "Owners" team.Description = strings.Repeat("A long description!", 100) - err := UpdateTeam(db.DefaultContext, team, "name", "lower_name", "description", "authorize") + err := UpdateTeam(db.DefaultContext, team, UpdateTeamOptions{ + TeamName: "name", + Description: "description", + }) assert.True(t, organization.IsErrTeamAlreadyExist(err)) unittest.CheckConsistencyFor(t, &organization.Team{ID: team.ID}) @@ -277,7 +283,10 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) { teams[4].IncludesAllRepositories = true teamRepos[4] = repoIDs for i, team := range teams { - assert.NoError(t, UpdateTeam(db.DefaultContext, team, false, true), "%s: UpdateTeam", team.Name) + assert.NoError(t, UpdateTeam(db.DefaultContext, team, UpdateTeamOptions{ + IncludesAllRepositories: false, + CanCreateOrgRepo: true, + }), "%s: UpdateTeam", team.Name) testTeamRepositories(team.ID, teamRepos[i]) }