diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index c554888c3d..858bd66b20 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -320,14 +320,14 @@ func EditTeam(ctx *context.APIContext) { } } - if err := org_service.UpdateTeam(ctx, team, - teamName, - description, - form.Permission == "admin", - includeAllRepos, - canCreateOrgRepo, - unitPerms, - ); err != nil { + if err := org_service.UpdateTeam(ctx, team, org_service.UpdateTeamOptions{ + TeamName: teamName, + Description: description, + IsAdmin: form.Permission == "admin", + IncludesAllRepositories: includeAllRepos, + CanCreateOrgRepo: canCreateOrgRepo, + UnitPerms: unitPerms, + }); err != nil { ctx.Error(http.StatusInternalServerError, "EditTeam", err) return } diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index 30e38b93c4..ee54c44653 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -494,12 +494,14 @@ func EditTeamPost(ctx *context.Context) { return } - if err := org_service.UpdateTeam(ctx, t, form.TeamName, form.Description, - form.Permission == "admin", - form.RepoAccess == "all", - form.CanCreateOrgRepo, - unitPerms, - ); err != nil { + if err := org_service.UpdateTeam(ctx, t, org_service.UpdateTeamOptions{ + TeamName: form.TeamName, + Description: form.Description, + IsAdmin: form.Permission == "admin", + IncludesAllRepositories: form.RepoAccess == "all", + CanCreateOrgRepo: form.CanCreateOrgRepo, + UnitPerms: unitPerms, + }); err != nil { ctx.Data["Err_TeamName"] = true switch { case org_model.IsErrTeamAlreadyExist(err): diff --git a/services/org/team.go b/services/org/team.go index a913715a9e..82951aa4e2 100644 --- a/services/org/team.go +++ b/services/org/team.go @@ -12,31 +12,40 @@ import ( unit_model "code.gitea.io/gitea/models/unit" ) -func UpdateTeam(ctx context.Context, team *org_model.Team, teamName, description string, isAdmin, includesAllRepositories, canCreateOrgRepo bool, unitPerms map[unit_model.Type]perm.AccessMode) error { +type UpdateTeamOptions struct { + TeamName string + Description string + IsAdmin bool + IncludesAllRepositories bool + CanCreateOrgRepo bool + UnitPerms map[unit_model.Type]perm.AccessMode +} + +func UpdateTeam(ctx context.Context, team *org_model.Team, opts UpdateTeamOptions) error { var changedCols []string newAccessMode := perm.AccessModeRead - if isAdmin { + if opts.IsAdmin { newAccessMode = perm.AccessModeAdmin } else { // 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(unitPerms) + newAccessMode = unit_model.MinUnitAccessMode(opts.UnitPerms) } if !team.IsOwnerTeam() { - team.Name = teamName + team.Name = opts.TeamName if team.AccessMode != newAccessMode { team.AccessMode = newAccessMode changedCols = append(changedCols, "authorize") } - if team.IncludesAllRepositories != includesAllRepositories { - team.IncludesAllRepositories = includesAllRepositories + if team.IncludesAllRepositories != opts.IncludesAllRepositories { + team.IncludesAllRepositories = opts.IncludesAllRepositories changedCols = append(changedCols, "includes_all_repositories") } - units := make([]*org_model.TeamUnit, 0, len(unitPerms)) - for tp, perm := range unitPerms { + units := make([]*org_model.TeamUnit, 0, len(opts.UnitPerms)) + for tp, perm := range opts.UnitPerms { units = append(units, &org_model.TeamUnit{ OrgID: team.OrgID, TeamID: team.ID, @@ -46,8 +55,8 @@ func UpdateTeam(ctx context.Context, team *org_model.Team, teamName, description } team.Units = units changedCols = append(changedCols, "units") - if team.CanCreateOrgRepo != canCreateOrgRepo { - team.CanCreateOrgRepo = canCreateOrgRepo + if team.CanCreateOrgRepo != opts.CanCreateOrgRepo { + team.CanCreateOrgRepo = opts.CanCreateOrgRepo changedCols = append(changedCols, "can_create_org_repo") } } else { @@ -56,9 +65,9 @@ func UpdateTeam(ctx context.Context, team *org_model.Team, teamName, description changedCols = append(changedCols, "can_create_org_repo", "includes_all_repositories") } - if team.Description != description { + if team.Description != opts.Description { changedCols = append(changedCols, "description") - team.Description = description + team.Description = opts.Description } return models.UpdateTeam(ctx, team, changedCols...)