mirror of
https://github.com/goharbor/harbor
synced 2025-04-30 20:45:47 +00:00
Fix pagination for users and users search apis
Signed-off-by: He Weiwei <hweiwei@vmware.com>
This commit is contained in:
parent
cd33d312fb
commit
79235fffd1
@ -318,6 +318,11 @@ func TestListUsers(t *testing.T) {
|
|||||||
if users2[0].Username != username {
|
if users2[0].Username != username {
|
||||||
t.Errorf("The username in result list does not match, expected: %s, actual: %s", username, users2[0].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) {
|
func TestResetUserPassword(t *testing.T) {
|
||||||
|
@ -106,10 +106,13 @@ func GetTotalOfUsers(query *models.UserQuery) (int64, error) {
|
|||||||
|
|
||||||
// ListUsers lists all users according to different conditions.
|
// ListUsers lists all users according to different conditions.
|
||||||
func ListUsers(query *models.UserQuery) ([]models.User, error) {
|
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{}
|
users := []models.User{}
|
||||||
_, err := userQueryConditions(query).Limit(-1).
|
_, err := qs.OrderBy("username").All(&users)
|
||||||
OrderBy("username").
|
|
||||||
All(&users)
|
|
||||||
return users, err
|
return users, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user