From c0edbd4d676b71575f078ef8ab57561770b3651f Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 30 Oct 2024 15:34:13 -0700 Subject: [PATCH] Fix test --- models/org_team.go | 2 +- routers/api/v1/org/team.go | 7 ++++++- services/org/team.go | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) 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)