Fix user listing
Problem with nil check in whereMasked (user repo)
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/titpetric/factory"
|
||||
"gopkg.in/Masterminds/squirrel.v1"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/permissions"
|
||||
"github.com/cortezaproject/corteza-server/pkg/rh"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
)
|
||||
@@ -115,7 +116,7 @@ func (r user) Find(filter types.UserFilter) (set types.UserSet, f types.UserFilt
|
||||
q := r.queryNoFilter()
|
||||
|
||||
// Returns user filter (flt) wrapped in IF() function with cnd as condition (when cnd != nil)
|
||||
whereMasked := func(cnd squirrel.Sqlizer, flt squirrel.Sqlizer) squirrel.Sqlizer {
|
||||
whereMasked := func(cnd *permissions.ResourceFilter, flt squirrel.Sqlizer) squirrel.Sqlizer {
|
||||
if cnd != nil {
|
||||
return rh.SquirrelFunction("IF", cnd, flt, squirrel.Expr("false"))
|
||||
} else {
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestUserRead(t *testing.T) {
|
||||
End()
|
||||
}
|
||||
|
||||
func TestUserList(t *testing.T) {
|
||||
func TestUserListAll(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
|
||||
h.secCtx()
|
||||
@@ -58,9 +58,7 @@ func TestUserList(t *testing.T) {
|
||||
h.allow(types.UserPermissionResource.AppendWildcard(), "read")
|
||||
|
||||
aux := struct {
|
||||
Response *struct {
|
||||
Filter *types.UserFilter
|
||||
}
|
||||
Response *struct{ Filter *types.UserFilter }
|
||||
}{}
|
||||
|
||||
h.apiInit().
|
||||
@@ -78,6 +76,36 @@ func TestUserList(t *testing.T) {
|
||||
h.a.GreaterOrEqual(int(aux.Response.Filter.Count), seedCount)
|
||||
}
|
||||
|
||||
func TestUserListQuery(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
|
||||
h.secCtx()
|
||||
|
||||
h.allow(types.UserPermissionResource.AppendWildcard(), "read")
|
||||
|
||||
aux := struct {
|
||||
Response *struct{ Filter *types.UserFilter }
|
||||
}{}
|
||||
|
||||
h.apiInit().
|
||||
Debug().
|
||||
Get("/users/").
|
||||
Query("query", h.randEmail()).
|
||||
Query("email", h.randEmail()).
|
||||
Query("name", "John Doe").
|
||||
Query("handle", "jdoe").
|
||||
Query("username", "jdoe").
|
||||
Expect(t).
|
||||
Status(http.StatusOK).
|
||||
Assert(helpers.AssertNoErrors).
|
||||
End().
|
||||
JSON(&aux)
|
||||
|
||||
h.a.NotNil(aux.Response)
|
||||
h.a.NotNil(aux.Response.Filter)
|
||||
h.a.GreaterOrEqual(int(aux.Response.Filter.Count), 0)
|
||||
}
|
||||
|
||||
func TestUserListWithOneAllowed(t *testing.T) {
|
||||
h := newHelper(t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user