From cfeb1c32264e4a12eab6907afd53d4004e53a5a7 Mon Sep 17 00:00:00 2001 From: David Svantesson Date: Sat, 5 Oct 2019 12:54:37 +0000 Subject: [PATCH] Change code in API EditTeam similar to EditTeamPost web interface Signed-off-by: David Svantesson --- routers/api/v1/org/team.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index 44732cdec6..a22b60a2c6 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -183,12 +183,27 @@ func EditTeam(ctx *context.APIContext, form api.EditTeamOption) { // "200": // "$ref": "#/responses/Team" team := ctx.Org.Team - team.Name = form.Name team.Description = form.Description - team.IncludesAllRepositories = form.IncludesAllRepositories - team.Authorize = models.ParseAccessMode(form.Permission) unitTypes := models.FindUnitTypes(form.Units...) + isAuthChanged := false + isIncludeAllChanged := false + if !team.IsOwnerTeam() { + // Validate permission level. + auth := models.ParseAccessMode(form.Permission) + + team.Name = form.Name + if team.Authorize != auth { + isAuthChanged = true + team.Authorize = auth + } + + if team.IncludesAllRepositories != form.IncludesAllRepositories { + isIncludeAllChanged = true + team.IncludesAllRepositories = form.IncludesAllRepositories + } + } + if team.Authorize < models.AccessModeOwner { var units = make([]*models.TeamUnit, 0, len(form.Units)) for _, tp := range unitTypes { @@ -200,7 +215,7 @@ func EditTeam(ctx *context.APIContext, form api.EditTeamOption) { team.Units = units } - if err := models.UpdateTeam(team, true, true); err != nil { + if err := models.UpdateTeam(team, isAuthChanged, isIncludeAllChanged); err != nil { ctx.Error(500, "EditTeam", err) return }