Add field IsAllRepositories to team API

This commit is contained in:
Nicolas Gourdon 2019-04-28 19:33:32 +02:00
parent e5f6d9e766
commit 7cca1253f7
5 changed files with 59 additions and 33 deletions

View file

@ -57,35 +57,42 @@ func TestAPITeam(t *testing.T) {
teamToCreate := &api.CreateTeamOption{ teamToCreate := &api.CreateTeamOption{
Name: "team1", Name: "team1",
Description: "team one", Description: "team one",
IsAllRepositories: true,
Permission: "write", Permission: "write",
Units: []string{"repo.code", "repo.issues"}, Units: []string{"repo.code", "repo.issues"},
} }
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/orgs/%s/teams?token=%s", org.Name, token), teamToCreate) req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/orgs/%s/teams?token=%s", org.Name, token), teamToCreate)
resp = session.MakeRequest(t, req, http.StatusCreated) resp = session.MakeRequest(t, req, http.StatusCreated)
DecodeJSON(t, resp, &apiTeam) DecodeJSON(t, resp, &apiTeam)
checkTeamResponse(t, &apiTeam, teamToCreate.Name, teamToCreate.Description, teamToCreate.Permission, teamToCreate.Units) checkTeamResponse(t, &apiTeam, teamToCreate.Name, teamToCreate.Description, teamToCreate.IsAllRepositories,
checkTeamBean(t, apiTeam.ID, teamToCreate.Name, teamToCreate.Description, teamToCreate.Permission, teamToCreate.Units) teamToCreate.Permission, teamToCreate.Units)
checkTeamBean(t, apiTeam.ID, teamToCreate.Name, teamToCreate.Description, teamToCreate.IsAllRepositories,
teamToCreate.Permission, teamToCreate.Units)
teamID := apiTeam.ID teamID := apiTeam.ID
// Edit team. // Edit team.
teamToEdit := &api.EditTeamOption{ teamToEdit := &api.EditTeamOption{
Name: "teamone", Name: "teamone",
Description: "team 1", Description: "team 1",
IsAllRepositories: false,
Permission: "admin", Permission: "admin",
Units: []string{"repo.code", "repo.pulls", "repo.releases"}, Units: []string{"repo.code", "repo.pulls", "repo.releases"},
} }
req = NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/teams/%d?token=%s", teamID, token), teamToEdit) req = NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/teams/%d?token=%s", teamID, token), teamToEdit)
resp = session.MakeRequest(t, req, http.StatusOK) resp = session.MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiTeam) DecodeJSON(t, resp, &apiTeam)
checkTeamResponse(t, &apiTeam, teamToEdit.Name, teamToEdit.Description, teamToEdit.Permission, teamToEdit.Units) checkTeamResponse(t, &apiTeam, teamToEdit.Name, teamToEdit.Description, teamToEdit.IsAllRepositories,
checkTeamBean(t, apiTeam.ID, teamToEdit.Name, teamToEdit.Description, teamToEdit.Permission, teamToEdit.Units) teamToEdit.Permission, teamToEdit.Units)
checkTeamBean(t, apiTeam.ID, teamToEdit.Name, teamToEdit.Description, teamToEdit.IsAllRepositories,
teamToEdit.Permission, teamToEdit.Units)
// Read team. // Read team.
teamRead := models.AssertExistsAndLoadBean(t, &models.Team{ID: teamID}).(*models.Team) teamRead := models.AssertExistsAndLoadBean(t, &models.Team{ID: teamID}).(*models.Team)
req = NewRequestf(t, "GET", "/api/v1/teams/%d?token="+token, teamID) req = NewRequestf(t, "GET", "/api/v1/teams/%d?token="+token, teamID)
resp = session.MakeRequest(t, req, http.StatusOK) resp = session.MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiTeam) DecodeJSON(t, resp, &apiTeam)
checkTeamResponse(t, &apiTeam, teamRead.Name, teamRead.Description, teamRead.Authorize.String(), teamRead.GetUnitNames()) checkTeamResponse(t, &apiTeam, teamRead.Name, teamRead.Description, teamRead.IsAllRepositories,
teamRead.Authorize.String(), teamRead.GetUnitNames())
// Delete team. // Delete team.
req = NewRequestf(t, "DELETE", "/api/v1/teams/%d?token="+token, teamID) req = NewRequestf(t, "DELETE", "/api/v1/teams/%d?token="+token, teamID)
@ -93,17 +100,18 @@ func TestAPITeam(t *testing.T) {
models.AssertNotExistsBean(t, &models.Team{ID: teamID}) models.AssertNotExistsBean(t, &models.Team{ID: teamID})
} }
func checkTeamResponse(t *testing.T, apiTeam *api.Team, name, description string, permission string, units []string) { func checkTeamResponse(t *testing.T, apiTeam *api.Team, name, description string, isAllRepositories bool, permission string, units []string) {
assert.Equal(t, name, apiTeam.Name, "name") assert.Equal(t, name, apiTeam.Name, "name")
assert.Equal(t, description, apiTeam.Description, "description") assert.Equal(t, description, apiTeam.Description, "description")
assert.Equal(t, isAllRepositories, apiTeam.IsAllRepositories, "isAllRepositories")
assert.Equal(t, permission, apiTeam.Permission, "permission") assert.Equal(t, permission, apiTeam.Permission, "permission")
sort.StringSlice(units).Sort() sort.StringSlice(units).Sort()
sort.StringSlice(apiTeam.Units).Sort() sort.StringSlice(apiTeam.Units).Sort()
assert.EqualValues(t, units, apiTeam.Units, "units") assert.EqualValues(t, units, apiTeam.Units, "units")
} }
func checkTeamBean(t *testing.T, id int64, name, description string, permission string, units []string) { func checkTeamBean(t *testing.T, id int64, name, description string, isAllRepositories bool, permission string, units []string) {
team := models.AssertExistsAndLoadBean(t, &models.Team{ID: id}).(*models.Team) team := models.AssertExistsAndLoadBean(t, &models.Team{ID: id}).(*models.Team)
assert.NoError(t, team.GetUnits(), "GetUnits") assert.NoError(t, team.GetUnits(), "GetUnits")
checkTeamResponse(t, convert.ToTeam(team), name, description, permission, units) checkTeamResponse(t, convert.ToTeam(team), name, description, isAllRepositories, permission, units)
} }

View file

@ -222,6 +222,7 @@ func ToTeam(team *models.Team) *api.Team {
ID: team.ID, ID: team.ID,
Name: team.Name, Name: team.Name,
Description: team.Description, Description: team.Description,
IsAllRepositories: team.IsAllRepositories,
Permission: team.Authorize.String(), Permission: team.Authorize.String(),
Units: team.GetUnitNames(), Units: team.GetUnitNames(),
} }

View file

@ -129,6 +129,7 @@ func CreateTeam(ctx *context.APIContext, form api.CreateTeamOption) {
OrgID: ctx.Org.Organization.ID, OrgID: ctx.Org.Organization.ID,
Name: form.Name, Name: form.Name,
Description: form.Description, Description: form.Description,
IsAllRepositories: form.IsAllRepositories,
Authorize: models.ParseAccessMode(form.Permission), Authorize: models.ParseAccessMode(form.Permission),
} }
@ -182,6 +183,7 @@ func EditTeam(ctx *context.APIContext, form api.EditTeamOption) {
team := ctx.Org.Team team := ctx.Org.Team
team.Name = form.Name team.Name = form.Name
team.Description = form.Description team.Description = form.Description
team.IsAllRepositories = form.IsAllRepositories
team.Authorize = models.ParseAccessMode(form.Permission) team.Authorize = models.ParseAccessMode(form.Permission)
unitTypes := models.FindUnitTypes(form.Units...) unitTypes := models.FindUnitTypes(form.Units...)

View file

@ -7298,6 +7298,10 @@
"type": "string", "type": "string",
"x-go-name": "Description" "x-go-name": "Description"
}, },
"is_all_repositories": {
"type": "boolean",
"x-go-name": "IsAllRepositories"
},
"name": { "name": {
"type": "string", "type": "string",
"x-go-name": "Name" "x-go-name": "Name"
@ -7733,6 +7737,10 @@
"type": "string", "type": "string",
"x-go-name": "Description" "x-go-name": "Description"
}, },
"is_all_repositories": {
"type": "boolean",
"x-go-name": "IsAllRepositories"
},
"name": { "name": {
"type": "string", "type": "string",
"x-go-name": "Name" "x-go-name": "Name"
@ -9252,6 +9260,10 @@
"format": "int64", "format": "int64",
"x-go-name": "ID" "x-go-name": "ID"
}, },
"is_all_repositories": {
"type": "boolean",
"x-go-name": "IsAllRepositories"
},
"name": { "name": {
"type": "string", "type": "string",
"x-go-name": "Name" "x-go-name": "Name"

View file

@ -11,6 +11,7 @@ type Team struct {
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description"` Description string `json:"description"`
Organization *Organization `json:"organization"` Organization *Organization `json:"organization"`
IsAllRepositories bool `json:"is_all_repositories"`
// enum: none,read,write,admin,owner // enum: none,read,write,admin,owner
Permission string `json:"permission"` Permission string `json:"permission"`
// enum: repo.code,repo.issues,repo.ext_issues,repo.wiki,repo.pulls,repo.releases,repo.ext_wiki // enum: repo.code,repo.issues,repo.ext_issues,repo.wiki,repo.pulls,repo.releases,repo.ext_wiki
@ -22,6 +23,7 @@ type CreateTeamOption struct {
// required: true // required: true
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"` Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"`
Description string `json:"description" binding:"MaxSize(255)"` Description string `json:"description" binding:"MaxSize(255)"`
IsAllRepositories bool `json:"is_all_repositories"`
// enum: read,write,admin // enum: read,write,admin
Permission string `json:"permission"` Permission string `json:"permission"`
// enum: repo.code,repo.issues,repo.ext_issues,repo.wiki,repo.pulls,repo.releases,repo.ext_wiki // enum: repo.code,repo.issues,repo.ext_issues,repo.wiki,repo.pulls,repo.releases,repo.ext_wiki
@ -33,6 +35,7 @@ type EditTeamOption struct {
// required: true // required: true
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"` Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"`
Description string `json:"description" binding:"MaxSize(255)"` Description string `json:"description" binding:"MaxSize(255)"`
IsAllRepositories bool `json:"is_all_repositories"`
// enum: read,write,admin // enum: read,write,admin
Permission string `json:"permission"` Permission string `json:"permission"`
// enum: repo.code,repo.issues,repo.ext_issues,repo.wiki,repo.pulls,repo.releases,repo.ext_wiki // enum: repo.code,repo.issues,repo.ext_issues,repo.wiki,repo.pulls,repo.releases,repo.ext_wiki