From f832e8eeea68d632cb8b000c25e6e3ed78af0a11 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 18 Jun 2021 13:47:34 +0200 Subject: [PATCH] Fix some API bugs (#16184) (#16190) * Fix some API bugs (#16184) * Repository object only count releases as releases (fix #16144) * EditOrg respect RepoAdminChangeTeamAccess option (fix #16013) * adjut to v1.14 --- integrations/api_repo_test.go | 2 +- modules/convert/repository.go | 2 +- modules/structs/org.go | 4 +++- routers/api/v1/org/org.go | 8 +++++++- routers/api/v1/utils/utils.go | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/integrations/api_repo_test.go b/integrations/api_repo_test.go index cfd3b58d649..d600d20e482 100644 --- a/integrations/api_repo_test.go +++ b/integrations/api_repo_test.go @@ -223,7 +223,7 @@ func TestAPIViewRepo(t *testing.T) { DecodeJSON(t, resp, &repo) assert.EqualValues(t, 1, repo.ID) assert.EqualValues(t, "repo1", repo.Name) - assert.EqualValues(t, 2, repo.Releases) + assert.EqualValues(t, 1, repo.Releases) assert.EqualValues(t, 1, repo.OpenIssues) assert.EqualValues(t, 3, repo.OpenPulls) diff --git a/modules/convert/repository.go b/modules/convert/repository.go index 813201ca684..be765383063 100644 --- a/modules/convert/repository.go +++ b/modules/convert/repository.go @@ -89,7 +89,7 @@ func innerToRepo(repo *models.Repository, mode models.AccessMode, isParent bool) return nil } - numReleases, _ := models.GetReleaseCountByRepoID(repo.ID, models.FindReleasesOptions{IncludeDrafts: false, IncludeTags: true}) + numReleases, _ := models.GetReleaseCountByRepoID(repo.ID, models.FindReleasesOptions{IncludeDrafts: false, IncludeTags: false}) mirrorInterval := "" if repo.IsMirror { diff --git a/modules/structs/org.go b/modules/structs/org.go index 4b79a4e70a0..ba97479b633 100644 --- a/modules/structs/org.go +++ b/modules/structs/org.go @@ -31,6 +31,8 @@ type CreateOrgOption struct { RepoAdminChangeTeamAccess bool `json:"repo_admin_change_team_access"` } +// TODO: make EditOrgOption fields optional after https://gitea.com/go-chi/binding/pulls/5 got merged + // EditOrgOption options for editing an organization type EditOrgOption struct { FullName string `json:"full_name"` @@ -40,5 +42,5 @@ type EditOrgOption struct { // possible values are `public`, `limited` or `private` // enum: public,limited,private Visibility string `json:"visibility" binding:"In(,public,limited,private)"` - RepoAdminChangeTeamAccess bool `json:"repo_admin_change_team_access"` + RepoAdminChangeTeamAccess *bool `json:"repo_admin_change_team_access"` } diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go index e0f36aa1e65..f4a634f4d56 100644 --- a/routers/api/v1/org/org.go +++ b/routers/api/v1/org/org.go @@ -264,7 +264,13 @@ func Edit(ctx *context.APIContext) { if form.Visibility != "" { org.Visibility = api.VisibilityModes[form.Visibility] } - if err := models.UpdateUserCols(org, "full_name", "description", "website", "location", "visibility"); err != nil { + if form.RepoAdminChangeTeamAccess != nil { + org.RepoAdminChangeTeamAccess = *form.RepoAdminChangeTeamAccess + } + if err := models.UpdateUserCols(org, + "full_name", "description", "website", "location", + "visibility", "repo_admin_change_team_access", + ); err != nil { ctx.Error(http.StatusInternalServerError, "EditOrganization", err) return } diff --git a/routers/api/v1/utils/utils.go b/routers/api/v1/utils/utils.go index ad1a136db46..10ab3ebd0cf 100644 --- a/routers/api/v1/utils/utils.go +++ b/routers/api/v1/utils/utils.go @@ -55,7 +55,7 @@ func parseTime(value string) (int64, error) { // prepareQueryArg unescape and trim a query arg func prepareQueryArg(ctx *context.APIContext, name string) (value string, err error) { value, err = url.PathUnescape(ctx.Query(name)) - value = strings.Trim(value, " ") + value = strings.TrimSpace(value) return }