Skip to content

fix(policy): currentModel and currentOperation inside of collection predicates#2537

Merged
ymc9 merged 2 commits intozenstackhq:devfrom
wolflu05:issue/2536
Apr 1, 2026
Merged

fix(policy): currentModel and currentOperation inside of collection predicates#2537
ymc9 merged 2 commits intozenstackhq:devfrom
wolflu05:issue/2536

Conversation

@wolflu05
Copy link
Copy Markdown
Contributor

@wolflu05 wolflu05 commented Mar 31, 2026

This fixes currentModel() and currentOperation() inside of collection predicates

fixes #2536

Summary by CodeRabbit

  • New Features

    • Policy expressions can now access the current model type and CRUD operation via built-ins, and nested expressions evaluate with that context.
  • Tests

    • Added a regression test validating context-aware policy evaluation using the new model/operation built-ins in nested rules.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 31, 2026

📝 Walkthrough

Walkthrough

Added required model type and CRUD operation fields to the expression evaluator context and propagated them through the expression transformer; implemented currentModel() and currentOperation() evaluation inside collection predicates; added a regression test covering nested predicate usage.

Changes

Cohort / File(s) Summary
Expression Evaluator
packages/plugins/policy/src/expression-evaluator.ts
Added required operation: CRUD_EXT and thisType: string to ExpressionEvaluatorContext; extended evaluateCall() to return context.thisType for currentModel() and context.operation for currentOperation() (keeps existing auth handling).
Expression Transformer
packages/plugins/policy/src/expression-transformer.ts
Passed operation and thisType through when invoking the evaluator for LHS of collection predicates and when optimizing RHS of value-tree-only collection predicates.
Tests
tests/regression/test/issue-2536.test.ts
Added regression test that exercises currentModel() and currentOperation() inside nested collection predicates using auth groups to validate allow/reject behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through code and peered inside,
Found model names and ops that used to hide,
I stitched the context, made them play,
In nested lists they now display,
A tiny patch — a joyful stride.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR fully addresses issue #2536 by implementing support for currentModel() and currentOperation() in collection predicates through context propagation in the expression evaluator and transformer.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the reported issue: context field additions, expression evaluator/transformer modifications, and regression test are all necessary for the fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately describes the main fix: enabling currentModel and currentOperation functions to work within collection predicates, which directly addresses the bug reported in issue #2536.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Member

@ymc9 ymc9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @wolflu05 , thanks for making the fix! It'll solve the immediate issue.

The expression evaluator's function call handling needs some overall refactoring. I'll make a follow-up PR a bit later.

@ymc9 ymc9 changed the title fix currentModel and currentOperation inside of collection predicates fix(policy): currentModel and currentOperation inside of collection predicates Apr 1, 2026
@ymc9 ymc9 merged commit 28ae08d into zenstackhq:dev Apr 1, 2026
9 checks passed
@wolflu05
Copy link
Copy Markdown
Contributor Author

wolflu05 commented Apr 1, 2026

Thanks for you so quick response. I really start to enjoy using zenstack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

currentModel() / currentOperation() does not work inside of collection predicates

2 participants