mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-02 21:11:37 +01:00
Merge pull request #7192 from heww/fix-users-api-pagination
Fix pagination for users and users search apis
This commit is contained in:
commit
8e870de976
@ -318,6 +318,11 @@ func TestListUsers(t *testing.T) {
|
||||
if users2[0].Username != username {
|
||||
t.Errorf("The username in result list does not match, expected: %s, actual: %s", username, users2[0].Username)
|
||||
}
|
||||
|
||||
users3, err := ListUsers(&models.UserQuery{Username: username, Pagination: &models.Pagination{Page: 2, Size: 1}})
|
||||
if len(users3) != 0 {
|
||||
t.Errorf("Expect no user in list, but the acutal length is %d, the list: %+v", len(users3), users3)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResetUserPassword(t *testing.T) {
|
||||
|
@ -106,10 +106,13 @@ func GetTotalOfUsers(query *models.UserQuery) (int64, error) {
|
||||
|
||||
// ListUsers lists all users according to different conditions.
|
||||
func ListUsers(query *models.UserQuery) ([]models.User, error) {
|
||||
qs := userQueryConditions(query)
|
||||
if query != nil && query.Pagination != nil {
|
||||
offset := (query.Pagination.Page - 1) * query.Pagination.Size
|
||||
qs = qs.Offset(offset).Limit(query.Pagination.Size)
|
||||
}
|
||||
users := []models.User{}
|
||||
_, err := userQueryConditions(query).Limit(-1).
|
||||
OrderBy("username").
|
||||
All(&users)
|
||||
_, err := qs.OrderBy("username").All(&users)
|
||||
return users, err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user