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

@ -55,37 +55,44 @@ func TestAPITeam(t *testing.T) {
// Create team. // Create team.
teamToCreate := &api.CreateTeamOption{ teamToCreate := &api.CreateTeamOption{
Name: "team1", Name: "team1",
Description: "team one", Description: "team one",
Permission: "write", IsAllRepositories: true,
Units: []string{"repo.code", "repo.issues"}, Permission: "write",
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",
Permission: "admin", IsAllRepositories: false,
Units: []string{"repo.code", "repo.pulls", "repo.releases"}, Permission: "admin",
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

@ -219,11 +219,12 @@ func ToOrganization(org *models.User) *api.Organization {
// ToTeam convert models.Team to api.Team // ToTeam convert models.Team to api.Team
func ToTeam(team *models.Team) *api.Team { func ToTeam(team *models.Team) *api.Team {
return &api.Team{ return &api.Team{
ID: team.ID, ID: team.ID,
Name: team.Name, Name: team.Name,
Description: team.Description, Description: team.Description,
Permission: team.Authorize.String(), IsAllRepositories: team.IsAllRepositories,
Units: team.GetUnitNames(), Permission: team.Authorize.String(),
Units: team.GetUnitNames(),
} }
} }

View file

@ -126,10 +126,11 @@ func CreateTeam(ctx *context.APIContext, form api.CreateTeamOption) {
// "201": // "201":
// "$ref": "#/responses/Team" // "$ref": "#/responses/Team"
team := &models.Team{ team := &models.Team{
OrgID: ctx.Org.Organization.ID, OrgID: ctx.Org.Organization.ID,
Name: form.Name, Name: form.Name,
Description: form.Description, Description: form.Description,
Authorize: models.ParseAccessMode(form.Permission), IsAllRepositories: form.IsAllRepositories,
Authorize: models.ParseAccessMode(form.Permission),
} }
unitTypes := models.FindUnitTypes(form.Units...) unitTypes := models.FindUnitTypes(form.Units...)
@ -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

@ -7,10 +7,11 @@ package gitea
// Team represents a team in an organization // Team represents a team in an organization
type Team struct { type Team struct {
ID int64 `json:"id"` ID int64 `json:"id"`
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
@ -20,8 +21,9 @@ type Team struct {
// CreateTeamOption options for creating a team // CreateTeamOption options for creating a team
type CreateTeamOption struct { 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
@ -31,8 +33,9 @@ type CreateTeamOption struct {
// EditTeamOption options for editing a team // EditTeamOption options for editing a team
type EditTeamOption struct { 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