Skip to content

Commit 088cffb

Browse files
committed
Fix update team
1 parent c7262d6 commit 088cffb

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

services/org/team.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
git_model "code.gitea.io/gitea/models/git"
1313
issues_model "code.gitea.io/gitea/models/issues"
1414
"code.gitea.io/gitea/models/organization"
15-
org_model "code.gitea.io/gitea/models/organization"
1615
"code.gitea.io/gitea/models/perm"
1716
access_model "code.gitea.io/gitea/models/perm/access"
1817
repo_model "code.gitea.io/gitea/models/repo"
@@ -101,7 +100,7 @@ type UpdateTeamOptions struct {
101100
UnitPerms map[unit_model.Type]perm.AccessMode
102101
}
103102

104-
func UpdateTeam(ctx context.Context, team *org_model.Team, opts UpdateTeamOptions) error {
103+
func UpdateTeam(ctx context.Context, team *organization.Team, opts UpdateTeamOptions) error {
105104
var changedCols []string
106105

107106
newAccessMode := team.AccessMode
@@ -130,9 +129,9 @@ func UpdateTeam(ctx context.Context, team *org_model.Team, opts UpdateTeamOption
130129
changedCols = append(changedCols, "includes_all_repositories")
131130
}
132131
if len(opts.UnitPerms) > 0 {
133-
units := make([]*org_model.TeamUnit, 0, len(opts.UnitPerms))
132+
units := make([]*organization.TeamUnit, 0, len(opts.UnitPerms))
134133
for tp, perm := range opts.UnitPerms {
135-
units = append(units, &org_model.TeamUnit{
134+
units = append(units, &organization.TeamUnit{
136135
OrgID: team.OrgID,
137136
TeamID: team.ID,
138137
Type: tp,
@@ -157,7 +156,7 @@ func UpdateTeam(ctx context.Context, team *org_model.Team, opts UpdateTeamOption
157156
team.Description = opts.Description
158157
}
159158

160-
return org_model.UpdateTeam(ctx, team, changedCols...)
159+
return organization.UpdateTeam(ctx, team, changedCols...)
161160
}
162161

163162
// UpdateTeam updates information of team.

services/org/team_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,14 @@ func TestUpdateTeam(t *testing.T) {
7878
assert.NoError(t, unittest.PrepareTestDatabase())
7979

8080
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 2})
81-
team.LowerName = "newname"
8281
team.Name = "newName"
8382
team.Description = strings.Repeat("A long description!", 100)
8483
team.AccessMode = perm.AccessModeAdmin
85-
assert.NoError(t, UpdateTeam(db.DefaultContext, team, "name", "lower_name", "description", "authorize"))
84+
assert.NoError(t, UpdateTeam(db.DefaultContext, team, UpdateTeamOptions{
85+
TeamName: "name",
86+
Description: "description",
87+
IsAdmin: true,
88+
}))
8689

8790
team = unittest.AssertExistsAndLoadBean(t, &organization.Team{Name: "newName"})
8891
assert.True(t, strings.HasPrefix(team.Description, "A long description!"))
@@ -101,7 +104,10 @@ func TestUpdateTeam2(t *testing.T) {
101104
team.LowerName = "owners"
102105
team.Name = "Owners"
103106
team.Description = strings.Repeat("A long description!", 100)
104-
err := UpdateTeam(db.DefaultContext, team, "name", "lower_name", "description", "authorize")
107+
err := UpdateTeam(db.DefaultContext, team, UpdateTeamOptions{
108+
TeamName: "name",
109+
Description: "description",
110+
})
105111
assert.True(t, organization.IsErrTeamAlreadyExist(err))
106112

107113
unittest.CheckConsistencyFor(t, &organization.Team{ID: team.ID})
@@ -277,7 +283,10 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
277283
teams[4].IncludesAllRepositories = true
278284
teamRepos[4] = repoIDs
279285
for i, team := range teams {
280-
assert.NoError(t, UpdateTeam(db.DefaultContext, team, false, true), "%s: UpdateTeam", team.Name)
286+
assert.NoError(t, UpdateTeam(db.DefaultContext, team, UpdateTeamOptions{
287+
IncludesAllRepositories: false,
288+
CanCreateOrgRepo: true,
289+
}), "%s: UpdateTeam", team.Name)
281290
testTeamRepositories(team.ID, teamRepos[i])
282291
}
283292

0 commit comments

Comments
 (0)