Skip to content

Commit afade2f

Browse files
committed
Fix test
1 parent 253ec37 commit afade2f

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

models/org_team_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func TestUpdateTeam(t *testing.T) {
8484
team.Name = "newName"
8585
team.Description = strings.Repeat("A long description!", 100)
8686
team.AccessMode = perm.AccessModeAdmin
87-
assert.NoError(t, UpdateTeam(db.DefaultContext, team, "authorize"))
87+
assert.NoError(t, UpdateTeam(db.DefaultContext, team, "name", "lower_name", "description", "authorize"))
8888

8989
team = unittest.AssertExistsAndLoadBean(t, &organization.Team{Name: "newName"})
9090
assert.True(t, strings.HasPrefix(team.Description, "A long description!"))
@@ -103,7 +103,7 @@ func TestUpdateTeam2(t *testing.T) {
103103
team.LowerName = "owners"
104104
team.Name = "Owners"
105105
team.Description = strings.Repeat("A long description!", 100)
106-
err := UpdateTeam(db.DefaultContext, team, "authorize")
106+
err := UpdateTeam(db.DefaultContext, team, "name", "lower_name", "description", "authorize")
107107
assert.True(t, organization.IsErrTeamAlreadyExist(err))
108108

109109
unittest.CheckConsistencyFor(t, &organization.Team{ID: team.ID})

modules/structs/org_team.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type EditTeamOption struct {
4444
Description *string `json:"description" binding:"MaxSize(255)"`
4545
IncludesAllRepositories *bool `json:"includes_all_repositories"`
4646
// enum: read,write,admin
47-
Permission string `json:"permission" binding:"Required;In(read,write,admin)"`
47+
Permission string `json:"permission"`
4848
// example: ["repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.pulls","repo.releases","repo.projects","repo.ext_wiki"]
4949
// Deprecated: This variable should be replaced by UnitsMap and will be dropped in later versions.
5050
Units []string `json:"units"`

services/forms/org.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (f *UpdateOrgSettingForm) Validate(req *http.Request, errs binding.Errors)
5757
type CreateTeamForm struct {
5858
TeamName string `binding:"Required;AlphaDashDot;MaxSize(255)"`
5959
Description string `binding:"MaxSize(255)"`
60-
Permission string `binding:"Required;In(read,write,admin)"`
60+
Permission string `binding:"Required;In(,read,write,admin)"`
6161
RepoAccess string `binding:"Required;In(specified, all)"`
6262
CanCreateOrgRepo bool
6363
}

services/org/team.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package org
55

66
import (
77
"context"
8+
"strings"
89

910
"code.gitea.io/gitea/models"
1011
org_model "code.gitea.io/gitea/models/organization"
@@ -34,7 +35,12 @@ func UpdateTeam(ctx context.Context, team *org_model.Team, opts UpdateTeamOption
3435
}
3536

3637
if !team.IsOwnerTeam() {
37-
team.Name = opts.TeamName
38+
if team.Name != opts.TeamName {
39+
team.Name = opts.TeamName
40+
team.LowerName = strings.ToLower(opts.TeamName)
41+
changedCols = append(changedCols, "name", "lower_name")
42+
}
43+
3844
if team.AccessMode != newAccessMode {
3945
team.AccessMode = newAccessMode
4046
changedCols = append(changedCols, "authorize")
@@ -44,22 +50,24 @@ func UpdateTeam(ctx context.Context, team *org_model.Team, opts UpdateTeamOption
4450
team.IncludesAllRepositories = opts.IncludesAllRepositories
4551
changedCols = append(changedCols, "includes_all_repositories")
4652
}
47-
units := make([]*org_model.TeamUnit, 0, len(opts.UnitPerms))
48-
for tp, perm := range opts.UnitPerms {
49-
units = append(units, &org_model.TeamUnit{
50-
OrgID: team.OrgID,
51-
TeamID: team.ID,
52-
Type: tp,
53-
AccessMode: perm,
54-
})
53+
if len(opts.UnitPerms) > 0 {
54+
units := make([]*org_model.TeamUnit, 0, len(opts.UnitPerms))
55+
for tp, perm := range opts.UnitPerms {
56+
units = append(units, &org_model.TeamUnit{
57+
OrgID: team.OrgID,
58+
TeamID: team.ID,
59+
Type: tp,
60+
AccessMode: perm,
61+
})
62+
}
63+
team.Units = units
64+
changedCols = append(changedCols, "units")
5565
}
56-
team.Units = units
57-
changedCols = append(changedCols, "units")
5866
if team.CanCreateOrgRepo != opts.CanCreateOrgRepo {
5967
team.CanCreateOrgRepo = opts.CanCreateOrgRepo
6068
changedCols = append(changedCols, "can_create_org_repo")
6169
}
62-
} else {
70+
} else { // make the possible legacy data correct, we force to update these fields
6371
team.CanCreateOrgRepo = true
6472
team.IncludesAllRepositories = true
6573
changedCols = append(changedCols, "can_create_org_repo", "includes_all_repositories")

0 commit comments

Comments
 (0)