diff --git a/models/org_team.go b/models/org_team.go index b4ea63d651..443e78996d 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -255,7 +255,7 @@ func UpdateTeam(ctx context.Context, t *organization.Team, updateCols ...string) } // update units for team - if len(t.Units) > 0 { + if slices.Contains(updateCols, "units") { for _, unit := range t.Units { unit.TeamID = t.ID } diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index 858bd66b20..4ca8c8f852 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -320,10 +320,15 @@ func EditTeam(ctx *context.APIContext) { } } + isAdmin := team.AccessMode == perm.AccessModeAdmin + if form.Permission != "" && form.Permission == "admin" { + isAdmin = true + } + if err := org_service.UpdateTeam(ctx, team, org_service.UpdateTeamOptions{ TeamName: teamName, Description: description, - IsAdmin: form.Permission == "admin", + IsAdmin: isAdmin, IncludesAllRepositories: includeAllRepos, CanCreateOrgRepo: canCreateOrgRepo, UnitPerms: unitPerms, diff --git a/services/org/team.go b/services/org/team.go index 26389bcf69..6dccc7a8f8 100644 --- a/services/org/team.go +++ b/services/org/team.go @@ -25,10 +25,10 @@ type UpdateTeamOptions struct { func UpdateTeam(ctx context.Context, team *org_model.Team, opts UpdateTeamOptions) error { var changedCols []string - var newAccessMode perm.AccessMode + newAccessMode := team.AccessMode if opts.IsAdmin { newAccessMode = perm.AccessModeAdmin - } else { + } else if len(opts.UnitPerms) > 0 { // if newAccessMode is less than admin accessmode, then it should be general accessmode, // so we should calculate the minial accessmode from units accessmodes. newAccessMode = unit_model.MinUnitAccessMode(opts.UnitPerms)