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
)

(cherry picked from commit 6f883a4)
  • Loading branch information
all-seeing-code committed Aug 27, 2020
1 parent 9df9f92 commit 9d2a93f
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 @@ -1397,6 +1397,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 9d2a93f

Please sign in to comment.