Skip to content

Commit b49e4a8

Browse files
committed
API: orgEditTeam make Fields optional
1 parent c620eb5 commit b49e4a8

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

modules/structs/org_team.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ type CreateTeamOption struct {
3535
// EditTeamOption options for editing a team
3636
type EditTeamOption struct {
3737
// required: true
38-
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"`
38+
Name string `json:"name" binding:"AlphaDashDot;MaxSize(30)"`
3939
Description string `json:"description" binding:"MaxSize(255)"`
4040
IncludesAllRepositories bool `json:"includes_all_repositories"`
4141
// enum: read,write,admin
4242
Permission string `json:"permission"`
4343
// example: ["repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.pulls","repo.releases","repo.ext_wiki"]
4444
Units []string `json:"units"`
45-
CanCreateOrgRepo bool `json:"can_create_org_repo"`
45+
CanCreateOrgRepo *bool `json:"can_create_org_repo"`
4646
}

routers/api/v1/org/team.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,28 @@ func EditTeam(ctx *context.APIContext, form api.EditTeamOption) {
192192
// "$ref": "#/responses/Team"
193193

194194
team := ctx.Org.Team
195-
team.Description = form.Description
196-
unitTypes := models.FindUnitTypes(form.Units...)
197-
team.CanCreateOrgRepo = form.CanCreateOrgRepo
195+
if err := team.GetUnits(); err != nil {
196+
ctx.InternalServerError(err)
197+
}
198+
199+
if form.CanCreateOrgRepo != nil {
200+
team.CanCreateOrgRepo = *form.CanCreateOrgRepo
201+
}
202+
203+
if form.Name != "" {
204+
team.Name = form.Name
205+
}
206+
207+
if form.Description != "" {
208+
team.Description = form.Description
209+
}
198210

199211
isAuthChanged := false
200212
isIncludeAllChanged := false
201-
if !team.IsOwnerTeam() {
213+
if !team.IsOwnerTeam() && form.Permission != "" {
202214
// Validate permission level.
203215
auth := models.ParseAccessMode(form.Permission)
204216

205-
team.Name = form.Name
206217
if team.Authorize != auth {
207218
isAuthChanged = true
208219
team.Authorize = auth
@@ -215,14 +226,17 @@ func EditTeam(ctx *context.APIContext, form api.EditTeamOption) {
215226
}
216227

217228
if team.Authorize < models.AccessModeOwner {
218-
var units = make([]*models.TeamUnit, 0, len(form.Units))
219-
for _, tp := range unitTypes {
220-
units = append(units, &models.TeamUnit{
221-
OrgID: ctx.Org.Team.OrgID,
222-
Type: tp,
223-
})
229+
if len(form.Units) > 0 {
230+
var units = make([]*models.TeamUnit, 0, len(form.Units))
231+
unitTypes := models.FindUnitTypes(form.Units...)
232+
for _, tp := range unitTypes {
233+
units = append(units, &models.TeamUnit{
234+
OrgID: ctx.Org.Team.OrgID,
235+
Type: tp,
236+
})
237+
}
238+
team.Units = units
224239
}
225-
team.Units = units
226240
}
227241

228242
if err := models.UpdateTeam(team, isAuthChanged, isIncludeAllChanged); err != nil {

0 commit comments

Comments
 (0)