-
-
Notifications
You must be signed in to change notification settings - Fork 104
merge dev to main (v2.11.6) #1981
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
Conversation
… policies if the corresponding fields are selected (#1979)
📝 WalkthroughWalkthroughThis pull request contains three distinct updates. The first change bumps the version number in the JetBrains IDE build configuration from 2.11.5 to 2.11.6. The second change updates the PolicyUtil class in the runtime package by modifying the signature of getFieldReadCheckSelector and refining its field-level merging logic. Finally, a new regression test is added to verify that the permission logic for accessing a user's secret field based on the publication status of associated posts is enforced correctly. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant PolicyUtil
Caller->>PolicyUtil: injectReadCheckSelect(args)
Note right of PolicyUtil: Extract fieldSelection from args.select
PolicyUtil->>PolicyUtil: Call getFieldReadCheckSelector(model, fieldSelection)
loop Process each field in fieldLevel selectors
alt Field is selected
PolicyUtil->>PolicyUtil: Merge selector for field
else Field not selected
PolicyUtil->>PolicyUtil: Skip merging for field
end
end
PolicyUtil-->>Caller: Return merged selectors
Possibly related PRs
✨ Finishing Touches
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration 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
🧹 Nitpick comments (2)
tests/regression/tests/issue-1978.test.ts (1)
32-40
: Consider adding more test cases.While the current test cases verify the basic functionality, consider adding:
- A user with an unpublished post
- A user with multiple posts (some published, some unpublished)
const user1 = await prisma.user.create({ data: { id: 1, secret: 'secret', posts: { create: { id: 1, published: true } } }, }); const user2 = await prisma.user.create({ data: { id: 2, secret: 'secret' }, }); +const user3 = await prisma.user.create({ + data: { id: 3, secret: 'secret', posts: { create: { id: 2, published: false } } }, +}); +const user4 = await prisma.user.create({ + data: { + id: 4, + secret: 'secret', + posts: { + create: [ + { id: 3, published: true }, + { id: 4, published: false } + ] + } + }, +}); const db = enhance(); await expect(db.user.findFirst({ where: { id: 1 } })).resolves.toMatchObject({ secret: 'secret' }); await expect(db.user.findFirst({ where: { id: 1 }, select: { id: true } })).resolves.toEqual({ id: 1 }); let r = await db.user.findFirst({ where: { id: 2 } }); expect(r.secret).toBeUndefined(); r = await db.user.findFirst({ where: { id: 2 }, select: { id: true } }); expect(r.secret).toBeUndefined(); +r = await db.user.findFirst({ where: { id: 3 } }); +expect(r.secret).toBeUndefined(); + +r = await db.user.findFirst({ where: { id: 4 } }); +expect(r.secret).toBeDefined();packages/runtime/src/enhancements/node/policy/policy-utils.ts (1)
1164-1196
: Consider adding error handling for invalid field selections.The
injectReadCheckSelect
method should validate thefieldSelection
parameter before passing it togetFieldReadCheckSelector
.injectReadCheckSelect(model: string, args: any) { + // Validate field selection + if (args.select && typeof args.select !== 'object') { + throw new Error('Invalid field selection: expected an object'); + } + // we need to recurse into relation fields before injecting the current level, because // injection into current level can result in relation being selected/included, which // can then cause infinite recursion when we visit relation later
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (13)
package.json
is excluded by!**/*.json
packages/ide/jetbrains/package.json
is excluded by!**/*.json
packages/language/package.json
is excluded by!**/*.json
packages/misc/redwood/package.json
is excluded by!**/*.json
packages/plugins/openapi/package.json
is excluded by!**/*.json
packages/plugins/swr/package.json
is excluded by!**/*.json
packages/plugins/tanstack-query/package.json
is excluded by!**/*.json
packages/plugins/trpc/package.json
is excluded by!**/*.json
packages/runtime/package.json
is excluded by!**/*.json
packages/schema/package.json
is excluded by!**/*.json
packages/sdk/package.json
is excluded by!**/*.json
packages/server/package.json
is excluded by!**/*.json
packages/testtools/package.json
is excluded by!**/*.json
📒 Files selected for processing (3)
packages/ide/jetbrains/build.gradle.kts
(1 hunks)packages/runtime/src/enhancements/node/policy/policy-utils.ts
(2 hunks)tests/regression/tests/issue-1978.test.ts
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- packages/ide/jetbrains/build.gradle.kts
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: OSSAR-Scan
- GitHub Check: build-test (20.x)
- GitHub Check: build-test (20.x)
- GitHub Check: dependency-review
- GitHub Check: build-test (20.x)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
tests/regression/tests/issue-1978.test.ts (2)
7-21
: LGTM! Well-structured schema definition.The schema clearly defines the relationship between
User
andPost
models, with appropriate permissions:
User.secret
is only readable when associated posts are published- Both models allow all operations by default
25-30
: LGTM! Good test data setup.Test data covers both scenarios:
- User1 with a published post
- User2 without any posts
packages/runtime/src/enhancements/node/policy/policy-utils.ts (1)
1314-1332
: LGTM! Improved field selection logic.The changes to
getFieldReadCheckSelector
optimize the field-level read checks by:
- Only merging selectors for fields that are explicitly selected
- Preventing unnecessary selector merging for unselected fields
No description provided.