From 7cca1253f7c7bf90582a71c26582d0369b8109ce Mon Sep 17 00:00:00 2001 From: Nicolas Gourdon Date: Sun, 28 Apr 2019 19:33:32 +0200 Subject: [PATCH] Add field IsAllRepositories to team API --- integrations/api_team_test.go | 40 +++++++++++++--------- routers/api/v1/convert/convert.go | 11 +++--- routers/api/v1/org/team.go | 10 +++--- templates/swagger/v1_json.tmpl | 12 +++++++ vendor/code.gitea.io/sdk/gitea/org_team.go | 19 +++++----- 5 files changed, 59 insertions(+), 33 deletions(-) diff --git a/integrations/api_team_test.go b/integrations/api_team_test.go index 7bb0e5b1bc..8eb18f4e90 100644 --- a/integrations/api_team_test.go +++ b/integrations/api_team_test.go @@ -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) } diff --git a/routers/api/v1/convert/convert.go b/routers/api/v1/convert/convert.go index f132dedb55..7d813b5c76 100644 --- a/routers/api/v1/convert/convert.go +++ b/routers/api/v1/convert/convert.go @@ -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(), } } diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index 340dd96c7e..0b5022f8c1 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -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...) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index b6160fc84d..e7438f7280 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -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" diff --git a/vendor/code.gitea.io/sdk/gitea/org_team.go b/vendor/code.gitea.io/sdk/gitea/org_team.go index 9de0a8d000..f82401cd47 100644 --- a/vendor/code.gitea.io/sdk/gitea/org_team.go +++ b/vendor/code.gitea.io/sdk/gitea/org_team.go @@ -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