Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(planner): Lambda body can be a field selection #1720

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion internal/engine/planner/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,9 @@
return err
}
if _, ok := lambda.Node.(*ExprOpExpr); !ok {
return fmt.Errorf("expected expression, got %T", lambda.Node)
if _, ok := lambda.Node.(*ExprOpVar); !ok {
return fmt.Errorf("expected expression or variable, got %T", lambda.Node)
}

Check warning on line 482 in internal/engine/planner/ast.go

View check run for this annotation

Codecov / codecov/patch

internal/engine/planner/ast.go#L480-L482

Added lines #L480 - L482 were not covered by tests
}
op := new(ExprOp)
err = buildExprImpl(iterRange, op, cur)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,9 @@ resourcePolicy:
condition:
match:
expr: P.attr.teams.all(t, t.startsWith(R.attr.teamId))
- actions: ["just-index"]
roles: ["user"]
effect: EFFECT_ALLOW
condition:
match:
expr: P.attr.account_id in (R.attr.accounts_people.map(ap, ap.account_id))
21 changes: 21 additions & 0 deletions internal/test/testdata/query_planner/suite/harry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ principal:
teams:
team1: employee
team2: user
account_id: abc123
tests:
- action: view
resource:
Expand Down Expand Up @@ -131,3 +132,23 @@ tests:
- variable: t
- variable: request.resource.attr.teamId
- variable: t
- action: just-index
resource:
kind: leave_request
policyVersion: default
want:
kind: KIND_CONDITIONAL
condition:
expression:
operator: in
operands:
- value: abc123
- expression:
operator: map
operands:
- variable: request.resource.attr.accounts_people
- expression:
operator: lambda
operands:
- variable: ap.account_id
- variable: ap
dbuduev marked this conversation as resolved.
Show resolved Hide resolved