diff options
author | 6543 <6543@obermui.de> | 2020-01-09 14:15:14 +0100 |
---|---|---|
committer | zeripath <art27@cantab.net> | 2020-01-09 13:15:14 +0000 |
commit | 1080c768d33a2c4846467d2e2913df87237b8b23 (patch) | |
tree | 0c9fd7f0da7e53bb6eeffa65aec793823bd8eb89 /routers | |
parent | 71fe01897743915b8fc8bb8d07f44ee6214d1e50 (diff) | |
download | gitea-1080c768d33a2c4846467d2e2913df87237b8b23.tar.gz gitea-1080c768d33a2c4846467d2e2913df87237b8b23.zip |
[API] orgEditTeam make Fields optional (#9556)
* API: orgEditTeam make Fields optional
* add TestCase
* Update integrations/api_team_test.go
* suggestions from lafriks
use len() to check if string is empty
Co-Authored-By: Lauris BH <lauris@nix.lv>
* change ...
* use Where not ID to get mssql
* add return and code format
* fix test
* fix test ... null pointer exept
* update specific colums
* only specific colums too
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/org/team.go | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index 73714e6a66..446287a343 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -192,37 +192,52 @@ func EditTeam(ctx *context.APIContext, form api.EditTeamOption) { // "$ref": "#/responses/Team" team := ctx.Org.Team - team.Description = form.Description - unitTypes := models.FindUnitTypes(form.Units...) - team.CanCreateOrgRepo = form.CanCreateOrgRepo + if err := team.GetUnits(); err != nil { + ctx.InternalServerError(err) + return + } + + if form.CanCreateOrgRepo != nil { + team.CanCreateOrgRepo = *form.CanCreateOrgRepo + } + + if len(form.Name) > 0 { + team.Name = form.Name + } + + if form.Description != nil { + team.Description = *form.Description + } isAuthChanged := false isIncludeAllChanged := false - if !team.IsOwnerTeam() { + if !team.IsOwnerTeam() && len(form.Permission) != 0 { // 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 { + if form.IncludesAllRepositories != nil { isIncludeAllChanged = true - team.IncludesAllRepositories = form.IncludesAllRepositories + team.IncludesAllRepositories = *form.IncludesAllRepositories } } if team.Authorize < models.AccessModeOwner { - var units = make([]*models.TeamUnit, 0, len(form.Units)) - for _, tp := range unitTypes { - units = append(units, &models.TeamUnit{ - OrgID: ctx.Org.Team.OrgID, - Type: tp, - }) + if len(form.Units) > 0 { + var units = make([]*models.TeamUnit, 0, len(form.Units)) + unitTypes := models.FindUnitTypes(form.Units...) + for _, tp := range unitTypes { + units = append(units, &models.TeamUnit{ + OrgID: ctx.Org.Team.OrgID, + Type: tp, + }) + } + team.Units = units } - team.Units = units } if err := models.UpdateTeam(team, isAuthChanged, isIncludeAllChanged); err != nil { |