Merge pull request 'Fix user search paging' (#3379) from algernon/forgejo:paging-all-users-exclamationmark into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3379 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
commit
c22110cf21
2 changed files with 22 additions and 1 deletions
|
@ -140,7 +140,7 @@ func SearchUsers(ctx context.Context, opts *SearchUserOptions) (users []*User, _
|
||||||
|
|
||||||
sessQuery := opts.toSearchQueryBase(ctx).OrderBy(opts.OrderBy.String())
|
sessQuery := opts.toSearchQueryBase(ctx).OrderBy(opts.OrderBy.String())
|
||||||
defer sessQuery.Close()
|
defer sessQuery.Close()
|
||||||
if opts.Page != 0 {
|
if opts.PageSize > 0 {
|
||||||
sessQuery = db.SetSessionPagination(sessQuery, opts)
|
sessQuery = db.SetSessionPagination(sessQuery, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,9 @@ import (
|
||||||
auth_model "code.gitea.io/gitea/models/auth"
|
auth_model "code.gitea.io/gitea/models/auth"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
|
"code.gitea.io/gitea/modules/test"
|
||||||
"code.gitea.io/gitea/tests"
|
"code.gitea.io/gitea/tests"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -57,6 +59,25 @@ func TestAPIUserSearchNotLoggedIn(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAPIUserSearchPaged(t *testing.T) {
|
||||||
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
defer test.MockVariableValue(&setting.API.DefaultPagingNum, 5)()
|
||||||
|
|
||||||
|
req := NewRequest(t, "GET", "/api/v1/users/search?limit=1")
|
||||||
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
|
var limitedResults SearchResults
|
||||||
|
DecodeJSON(t, resp, &limitedResults)
|
||||||
|
assert.Len(t, limitedResults.Data, 1)
|
||||||
|
|
||||||
|
req = NewRequest(t, "GET", "/api/v1/users/search")
|
||||||
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
|
var results SearchResults
|
||||||
|
DecodeJSON(t, resp, &results)
|
||||||
|
assert.Len(t, results.Data, 5)
|
||||||
|
}
|
||||||
|
|
||||||
func TestAPIUserSearchSystemUsers(t *testing.T) {
|
func TestAPIUserSearchSystemUsers(t *testing.T) {
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
for _, systemUser := range []*user_model.User{
|
for _, systemUser := range []*user_model.User{
|
||||||
|
|
Loading…
Reference in a new issue