Add field IsAllRepositories to team API
This commit is contained in:
parent
e5f6d9e766
commit
7cca1253f7
5 changed files with 59 additions and 33 deletions
|
@ -55,37 +55,44 @@ func TestAPITeam(t *testing.T) {
|
|||
|
||||
// Create team.
|
||||
teamToCreate := &api.CreateTeamOption{
|
||||
Name: "team1",
|
||||
Description: "team one",
|
||||
Permission: "write",
|
||||
Units: []string{"repo.code", "repo.issues"},
|
||||
Name: "team1",
|
||||
Description: "team one",
|
||||
IsAllRepositories: true,
|
||||
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)
|
||||
resp = session.MakeRequest(t, req, http.StatusCreated)
|
||||
DecodeJSON(t, resp, &apiTeam)
|
||||
checkTeamResponse(t, &apiTeam, teamToCreate.Name, teamToCreate.Description, teamToCreate.Permission, teamToCreate.Units)
|
||||
checkTeamBean(t, apiTeam.ID, teamToCreate.Name, teamToCreate.Description, teamToCreate.Permission, teamToCreate.Units)
|
||||
checkTeamResponse(t, &apiTeam, teamToCreate.Name, teamToCreate.Description, teamToCreate.IsAllRepositories,
|
||||
teamToCreate.Permission, teamToCreate.Units)
|
||||
checkTeamBean(t, apiTeam.ID, teamToCreate.Name, teamToCreate.Description, teamToCreate.IsAllRepositories,
|
||||
teamToCreate.Permission, teamToCreate.Units)
|
||||
teamID := apiTeam.ID
|
||||
|
||||
// Edit team.
|
||||
teamToEdit := &api.EditTeamOption{
|
||||
Name: "teamone",
|
||||
Description: "team 1",
|
||||
Permission: "admin",
|
||||
Units: []string{"repo.code", "repo.pulls", "repo.releases"},
|
||||
Name: "teamone",
|
||||
Description: "team 1",
|
||||
IsAllRepositories: false,
|
||||
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)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiTeam)
|
||||
checkTeamResponse(t, &apiTeam, teamToEdit.Name, teamToEdit.Description, teamToEdit.Permission, teamToEdit.Units)
|
||||
checkTeamBean(t, apiTeam.ID, teamToEdit.Name, teamToEdit.Description, teamToEdit.Permission, teamToEdit.Units)
|
||||
checkTeamResponse(t, &apiTeam, teamToEdit.Name, teamToEdit.Description, teamToEdit.IsAllRepositories,
|
||||
teamToEdit.Permission, teamToEdit.Units)
|
||||
checkTeamBean(t, apiTeam.ID, teamToEdit.Name, teamToEdit.Description, teamToEdit.IsAllRepositories,
|
||||
teamToEdit.Permission, teamToEdit.Units)
|
||||
|
||||
// Read team.
|
||||
teamRead := models.AssertExistsAndLoadBean(t, &models.Team{ID: teamID}).(*models.Team)
|
||||
req = NewRequestf(t, "GET", "/api/v1/teams/%d?token="+token, teamID)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
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.
|
||||
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})
|
||||
}
|
||||
|
||||
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, description, apiTeam.Description, "description")
|
||||
assert.Equal(t, isAllRepositories, apiTeam.IsAllRepositories, "isAllRepositories")
|
||||
assert.Equal(t, permission, apiTeam.Permission, "permission")
|
||||
sort.StringSlice(units).Sort()
|
||||
sort.StringSlice(apiTeam.Units).Sort()
|
||||
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)
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -219,11 +219,12 @@ func ToOrganization(org *models.User) *api.Organization {
|
|||
// ToTeam convert models.Team to api.Team
|
||||
func ToTeam(team *models.Team) *api.Team {
|
||||
return &api.Team{
|
||||
ID: team.ID,
|
||||
Name: team.Name,
|
||||
Description: team.Description,
|
||||
Permission: team.Authorize.String(),
|
||||
Units: team.GetUnitNames(),
|
||||
ID: team.ID,
|
||||
Name: team.Name,
|
||||
Description: team.Description,
|
||||
IsAllRepositories: team.IsAllRepositories,
|
||||
Permission: team.Authorize.String(),
|
||||
Units: team.GetUnitNames(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -126,10 +126,11 @@ func CreateTeam(ctx *context.APIContext, form api.CreateTeamOption) {
|
|||
// "201":
|
||||
// "$ref": "#/responses/Team"
|
||||
team := &models.Team{
|
||||
OrgID: ctx.Org.Organization.ID,
|
||||
Name: form.Name,
|
||||
Description: form.Description,
|
||||
Authorize: models.ParseAccessMode(form.Permission),
|
||||
OrgID: ctx.Org.Organization.ID,
|
||||
Name: form.Name,
|
||||
Description: form.Description,
|
||||
IsAllRepositories: form.IsAllRepositories,
|
||||
Authorize: models.ParseAccessMode(form.Permission),
|
||||
}
|
||||
|
||||
unitTypes := models.FindUnitTypes(form.Units...)
|
||||
|
@ -182,6 +183,7 @@ func EditTeam(ctx *context.APIContext, form api.EditTeamOption) {
|
|||
team := ctx.Org.Team
|
||||
team.Name = form.Name
|
||||
team.Description = form.Description
|
||||
team.IsAllRepositories = form.IsAllRepositories
|
||||
team.Authorize = models.ParseAccessMode(form.Permission)
|
||||
unitTypes := models.FindUnitTypes(form.Units...)
|
||||
|
||||
|
|
|
@ -7298,6 +7298,10 @@
|
|||
"type": "string",
|
||||
"x-go-name": "Description"
|
||||
},
|
||||
"is_all_repositories": {
|
||||
"type": "boolean",
|
||||
"x-go-name": "IsAllRepositories"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"x-go-name": "Name"
|
||||
|
@ -7733,6 +7737,10 @@
|
|||
"type": "string",
|
||||
"x-go-name": "Description"
|
||||
},
|
||||
"is_all_repositories": {
|
||||
"type": "boolean",
|
||||
"x-go-name": "IsAllRepositories"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"x-go-name": "Name"
|
||||
|
@ -9252,6 +9260,10 @@
|
|||
"format": "int64",
|
||||
"x-go-name": "ID"
|
||||
},
|
||||
"is_all_repositories": {
|
||||
"type": "boolean",
|
||||
"x-go-name": "IsAllRepositories"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"x-go-name": "Name"
|
||||
|
|
19
vendor/code.gitea.io/sdk/gitea/org_team.go
generated
vendored
19
vendor/code.gitea.io/sdk/gitea/org_team.go
generated
vendored
|
@ -7,10 +7,11 @@ package gitea
|
|||
|
||||
// Team represents a team in an organization
|
||||
type Team struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Organization *Organization `json:"organization"`
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Organization *Organization `json:"organization"`
|
||||
IsAllRepositories bool `json:"is_all_repositories"`
|
||||
// enum: none,read,write,admin,owner
|
||||
Permission string `json:"permission"`
|
||||
// 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
|
||||
type CreateTeamOption struct {
|
||||
// required: true
|
||||
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"`
|
||||
Description string `json:"description" binding:"MaxSize(255)"`
|
||||
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"`
|
||||
Description string `json:"description" binding:"MaxSize(255)"`
|
||||
IsAllRepositories bool `json:"is_all_repositories"`
|
||||
// enum: read,write,admin
|
||||
Permission string `json:"permission"`
|
||||
// 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
|
||||
type EditTeamOption struct {
|
||||
// required: true
|
||||
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"`
|
||||
Description string `json:"description" binding:"MaxSize(255)"`
|
||||
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"`
|
||||
Description string `json:"description" binding:"MaxSize(255)"`
|
||||
IsAllRepositories bool `json:"is_all_repositories"`
|
||||
// enum: read,write,admin
|
||||
Permission string `json:"permission"`
|
||||
// enum: repo.code,repo.issues,repo.ext_issues,repo.wiki,repo.pulls,repo.releases,repo.ext_wiki
|
||||
|
|
Loading…
Reference in a new issue