Merge pull request #139 from RafayLabs/user-listing-fix

Fix user listing
This commit is contained in:
Nirav Parikh
2022-05-20 10:15:33 +05:30
committed by GitHub
3 changed files with 13 additions and 6 deletions
+3 -1
View File
@@ -248,8 +248,10 @@ func ListFiltered(ctx context.Context, db bun.IDB,
if orderBy != "" && order != "" {
sq.Order(orderBy + " " + order)
}
if limit != 0 || offset != 0 {
if limit > 0 {
sq.Limit(limit)
}
if offset > 0 {
sq.Offset(offset)
}
err := sq.Scan(ctx)
+9 -4
View File
@@ -100,7 +100,10 @@ func GetQueryFilteredUsers(ctx context.Context, db bun.IDB, partner, org, group,
if len(projects) != 0 {
q.Where("project_id IN (?)", bun.In(projects))
}
q.Scan(ctx)
err := q.Scan(ctx)
if err != nil {
return nil, err
}
acc := []uuid.UUID{}
for _, a := range p {
@@ -122,18 +125,20 @@ func ListFilteredUsers(ctx context.Context, db bun.IDB, users *[]models.KratosId
if len(fusers) > 0 {
// filter with precomputed users if we have any
q.Where("id IN (?)", bun.In(fusers))
q.Where("identities.id IN (?)", bun.In(fusers))
}
if query != "" {
q.Where("traits ->> 'email' ILIKE ?", "%"+query+"%") // XXX: ILIKE is not-standard
q.Where("traits ->> 'email' ILIKE ?", "%"+query+"%") // XXX: ILIKE is not-standard sql
q.WhereOr("traits ->> 'first_name' ILIKE ?", "%"+query+"%")
q.WhereOr("traits ->> 'last_name' ILIKE ?", "%"+query+"%")
}
if orderBy != "" && order != "" {
q.Order("traits ->> '" + orderBy + "' " + order)
}
if limit != 0 || offset != 0 {
if limit > 0 {
q.Limit(limit)
}
if offset > 0 {
q.Offset(offset)
}
err := q.Scan(ctx)
+1 -1
View File
@@ -507,7 +507,7 @@ func TestUserList(t *testing.T) {
}
if tc.role != "" || tc.group != "" || len(tc.projects) != 0 {
addSentryLookupExpectation(mock, []string{uuuid1, uuuid2}, puuid, ouuid)
mock.ExpectQuery(`SELECT "identities"."id", .*WHERE .id IN .'` + uuuid1 + `', '` + uuuid2 + `'.. ` + q + order + `LIMIT ` + fmt.Sprint(tc.limit) + ` OFFSET ` + fmt.Sprint(tc.offset)).
mock.ExpectQuery(`SELECT "identities"."id", .*WHERE .identities.id IN .'` + uuuid1 + `', '` + uuuid2 + `'.. ` + q + order + `LIMIT ` + fmt.Sprint(tc.limit) + ` OFFSET ` + fmt.Sprint(tc.offset)).
WithArgs().WillReturnRows(sqlmock.NewRows([]string{"id", "traits"}).
AddRow(uuuid1, []byte(`{"email":"johndoe@provider.com", "first_name": "John", "last_name": "Doe", "organization_id": "`+ouuid+`", "partner_id": "`+puuid+`", "description": "My awesome user"}`)).
AddRow(uuuid2, []byte(`{"email":"johndoe@provider.com", "first_name": "John", "last_name": "Doe", "organization_id": "`+ouuid+`", "partner_id": "`+puuid+`", "description": "My awesome user"}`)))