@@ -12,31 +12,40 @@ import (
1212 unit_model "code.gitea.io/gitea/models/unit"
1313)
1414
15- func UpdateTeam (ctx context.Context , team * org_model.Team , teamName , description string , isAdmin , includesAllRepositories , canCreateOrgRepo bool , unitPerms map [unit_model.Type ]perm.AccessMode ) error {
15+ type UpdateTeamOptions struct {
16+ TeamName string
17+ Description string
18+ IsAdmin bool
19+ IncludesAllRepositories bool
20+ CanCreateOrgRepo bool
21+ UnitPerms map [unit_model.Type ]perm.AccessMode
22+ }
23+
24+ func UpdateTeam (ctx context.Context , team * org_model.Team , opts UpdateTeamOptions ) error {
1625 var changedCols []string
1726
1827 newAccessMode := perm .AccessModeRead
19- if isAdmin {
28+ if opts . IsAdmin {
2029 newAccessMode = perm .AccessModeAdmin
2130 } else {
2231 // if newAccessMode is less than admin accessmode, then it should be general accessmode,
2332 // so we should calculate the minial accessmode from units accessmodes.
24- newAccessMode = unit_model .MinUnitAccessMode (unitPerms )
33+ newAccessMode = unit_model .MinUnitAccessMode (opts . UnitPerms )
2534 }
2635
2736 if ! team .IsOwnerTeam () {
28- team .Name = teamName
37+ team .Name = opts . TeamName
2938 if team .AccessMode != newAccessMode {
3039 team .AccessMode = newAccessMode
3140 changedCols = append (changedCols , "authorize" )
3241 }
3342
34- if team .IncludesAllRepositories != includesAllRepositories {
35- team .IncludesAllRepositories = includesAllRepositories
43+ if team .IncludesAllRepositories != opts . IncludesAllRepositories {
44+ team .IncludesAllRepositories = opts . IncludesAllRepositories
3645 changedCols = append (changedCols , "includes_all_repositories" )
3746 }
38- units := make ([]* org_model.TeamUnit , 0 , len (unitPerms ))
39- for tp , perm := range unitPerms {
47+ units := make ([]* org_model.TeamUnit , 0 , len (opts . UnitPerms ))
48+ for tp , perm := range opts . UnitPerms {
4049 units = append (units , & org_model.TeamUnit {
4150 OrgID : team .OrgID ,
4251 TeamID : team .ID ,
@@ -46,8 +55,8 @@ func UpdateTeam(ctx context.Context, team *org_model.Team, teamName, description
4655 }
4756 team .Units = units
4857 changedCols = append (changedCols , "units" )
49- if team .CanCreateOrgRepo != canCreateOrgRepo {
50- team .CanCreateOrgRepo = canCreateOrgRepo
58+ if team .CanCreateOrgRepo != opts . CanCreateOrgRepo {
59+ team .CanCreateOrgRepo = opts . CanCreateOrgRepo
5160 changedCols = append (changedCols , "can_create_org_repo" )
5261 }
5362 } else {
@@ -56,9 +65,9 @@ func UpdateTeam(ctx context.Context, team *org_model.Team, teamName, description
5665 changedCols = append (changedCols , "can_create_org_repo" , "includes_all_repositories" )
5766 }
5867
59- if team .Description != description {
68+ if team .Description != opts . Description {
6069 changedCols = append (changedCols , "description" )
61- team .Description = description
70+ team .Description = opts . Description
6271 }
6372
6473 return models .UpdateTeam (ctx , team , changedCols ... )
0 commit comments