-
-
Notifications
You must be signed in to change notification settings - Fork 90
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(policy): field-level override rules don't work properly with non-optional to-one relations #1592
Conversation
…optional to-one relations
WalkthroughWalkthroughThe recent changes introduce an enhancement to the Changes
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- packages/runtime/src/enhancements/policy/policy-utils.ts (1 hunks)
- tests/regression/tests/issue-1574.test.ts (1 hunks)
Additional comments not posted (20)
tests/regression/tests/issue-1574.test.ts (18)
1-2
: Import statement is correct.The
loadSchema
function is correctly imported from@zenstackhq/testtools
.
3-3
: Test suite description is clear.The test suite is correctly named to indicate it addresses issue 1574.
4-4
: Test case description is clear.The test case is correctly named as a regression test.
5-52
: Schema is correctly defined.The schema definition matches the described access policies:
User
has a one-to-many relation withModelA
.ModelA
has a model-level access policy and a property-level read override forname
.ModelB
andModelC
have allow-all policies, withModelB
having an optional relation toModelA
andModelC
having a non-optional relation toModelA
.
54-57
: User creation is correct.Two users are correctly created for the tests.
58-60
: Database instances are correctly enhanced for users.Two database instances are correctly enhanced for the two users.
62-63
: ModelA creation is correct.A
ModelA
instance owned byuser1
is correctly created.
65-67
: ModelB and ModelC creation is correct.A
ModelB
instance with a reference toModelA
and aModelC
instance with a reference toModelA
are correctly created.
69-71
: Test case for user1 reading ModelB and referenced ModelA is correct.The test correctly verifies that
user1
can readModelB
and the entire referencedModelA
.
73-75
: Test case for user1 reading ModelB and referenced ModelA's name is correct.The test correctly verifies that
user1
can readModelB
and thename
of the referencedModelA
.
77-79
: Test case for user2 reading ModelB and referenced ModelA's name is correct.The test correctly verifies that
user2
can readModelB
and thename
of the referencedModelA
.
81-83
: Test case for user2 reading ModelB and entire referenced ModelA is correct.The test correctly verifies that
user2
cannot readModelB
with the entire referencedModelA
.
85-87
: Comment for ModelC tests is clear.The comment correctly indicates that the following tests are similar to the previous ones but with
ModelC
.
89-91
: Test case for user1 reading ModelC and referenced ModelA is correct.The test correctly verifies that
user1
can readModelC
and the entire referencedModelA
.
93-95
: Test case for user1 reading ModelC and referenced ModelA's name is correct.The test correctly verifies that
user1
can readModelC
and thename
of the referencedModelA
.
97-99
: Test case for user2 reading ModelC and referenced ModelA is correct.The test correctly verifies that
user2
cannot readModelC
with the referencedModelA
.
101-103
: Test case for user2 querying ModelC and accessing ModelA's name directly is correct.The test correctly verifies that
user2
can queryModelC
, get therefId
toModelA
, and accessModelA
'sname
directly.
105-106
: Test case for user2 querying ModelC and referenced ModelA's name directly is correct.The test correctly verifies that
user2
should be able to queryModelC
along with thename
of the referencedModelA
directly, but this is expected to fail.packages/runtime/src/enhancements/policy/policy-utils.ts (2)
723-729
: Ensure proper authorization checks in hoistNonNullableToOneFilters.The addition of
injectAuthGuardAsWhere
ensures that authorization checks are applied before hoisting non-nullable to-one filters. This change appears correct and aligns with the PR objectives.
728-728
: New method injectAuthGuardAsWhere is correctly implemented.The method
injectAuthGuardAsWhere
correctly injects anAuthGuard
as awhere
condition, ensuring proper authorization checks are applied. This change aligns with the PR objectives and resolves the issue described.
Fixes #1574