From 054bc55a1c6f8396c032a85354eb023742cb9f97 Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Sun, 27 Feb 2022 13:18:23 +0100 Subject: [PATCH] Fix page and missing return on unadopted repos API (#18848) (#18927) * Fix page and missing return on unadopted repos API Page must be 1 if it's not specified and it should return after sending an internal server error. * Allow ignore pages --- integrations/api_repo_test.go | 1 - models/migrations/migrations.go | 1 - models/migrations/v210.go | 2 +- models/migrations/v210_test.go | 1 + routers/api/v1/admin/adopt.go | 4 ++++ 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/integrations/api_repo_test.go b/integrations/api_repo_test.go index c909e96f06..1ec9dbad10 100644 --- a/integrations/api_repo_test.go +++ b/integrations/api_repo_test.go @@ -445,7 +445,6 @@ func TestAPIRepoTransfer(t *testing.T) { expectedStatus int }{ // Disclaimer for test story: "user1" is an admin, "user2" is normal user and part of in owner team of org "user3" - // Transfer to a user with teams in another org should fail {ctxUserID: 1, newOwner: "user3", teams: &[]int64{5}, expectedStatus: http.StatusForbidden}, // Transfer to a user with non-existent team IDs should fail diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 63d1c32259..31b172a68d 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -61,7 +61,6 @@ type Version struct { // update minDBVersion accordingly var migrations = []Migration{ // Gitea 1.5.0 ends at v69 - // v70 -> v71 NewMigration("add issue_dependencies", addIssueDependencies), // v71 -> v72 diff --git a/models/migrations/v210.go b/models/migrations/v210.go index 53461c03e9..dafe355fe2 100644 --- a/models/migrations/v210.go +++ b/models/migrations/v210.go @@ -11,8 +11,8 @@ import ( "strings" "code.gitea.io/gitea/modules/timeutil" - "github.com/tstranex/u2f" + "github.com/tstranex/u2f" "xorm.io/xorm" "xorm.io/xorm/schemas" ) diff --git a/models/migrations/v210_test.go b/models/migrations/v210_test.go index 3e10b3ce80..70dbe61b06 100644 --- a/models/migrations/v210_test.go +++ b/models/migrations/v210_test.go @@ -8,6 +8,7 @@ import ( "testing" "code.gitea.io/gitea/modules/timeutil" + "github.com/stretchr/testify/assert" "xorm.io/xorm/schemas" ) diff --git a/routers/api/v1/admin/adopt.go b/routers/api/v1/admin/adopt.go index 1c0e237cdb..db1754c8d0 100644 --- a/routers/api/v1/admin/adopt.go +++ b/routers/api/v1/admin/adopt.go @@ -43,9 +43,13 @@ func ListUnadoptedRepositories(ctx *context.APIContext) { // "$ref": "#/responses/forbidden" listOptions := utils.GetListOptions(ctx) + if listOptions.Page == 0 { + listOptions.Page = 1 + } repoNames, count, err := repo_service.ListUnadoptedRepositories(ctx.FormString("query"), &listOptions) if err != nil { ctx.InternalServerError(err) + return } ctx.SetTotalCountHeader(int64(count))