Skip to content

Commit

Permalink
fix(ACL Query): Fixes queries which use variable at the top level (#6290
Browse files Browse the repository at this point in the history
)
  • Loading branch information
all-seeing-code authored Aug 27, 2020
1 parent 57fcd92 commit 6f883a4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
6 changes: 4 additions & 2 deletions edgraph/access_ee.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,8 +721,10 @@ func parsePredsFromQuery(gqls []*gql.GraphQuery) predsAndvars {
}
preds := make([]string, 0, len(predsMap))
for pred := range predsMap {
if _, found := varsMap[pred]; !found {
preds = append(preds, pred)
if len(pred) > 0 {
if _, found := varsMap[pred]; !found {
preds = append(preds, pred)
}
}
}

Expand Down
22 changes: 22 additions & 0 deletions ee/acl/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,28 @@ func TestValQueryWithACLPermissions(t *testing.T) {
`{"q1":[{"name":"RandomGuy","age":23},{"name":"RandomGuy2","age":25}],
"q2":[{"name":"RandomGuy2","val(n)":"RandomGuy2","val(a)":25},{"name":"RandomGuy","val(n)":"RandomGuy","val(a)":23}]}`,
},
{
`{
f as q1(func: has(name), orderasc: name) {
name
age
}
q2(func: uid(f), orderasc: name) {
name
age
}
}`,
"alice doesn't have access to name or age",
`{"q2":[]}`,

`alice has access to name`,
`{"q1":[{"name":"RandomGuy"},{"name":"RandomGuy2"}],
"q2":[{"name":"RandomGuy"},{"name":"RandomGuy2"}]}`,

"alice has access to name and age",
`{"q1":[{"name":"RandomGuy","age":23},{"name":"RandomGuy2","age":25}],
"q2":[{"name":"RandomGuy2","age":25},{"name":"RandomGuy","age":23}]}`,
},
}

userClient, err := testutil.DgraphClient(testutil.SockAddr)
Expand Down

0 comments on commit 6f883a4

Please sign in to comment.