[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>
This commit is contained in:
parent
71fe018977
commit
1080c768d3
4 changed files with 55 additions and 26 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue