@@ -5,6 +5,7 @@ package org
55
66import (
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