-
-
Notifications
You must be signed in to change notification settings - Fork 144
fix(orm): fix PostgreSQL type mismatch when @db.Uuid fields used in policy expressions #2532
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cb7e60d
fix(orm): fix PostgreSQL type mismatch when @db.Uuid fields used in p…
ymc9 455e6f2
refactor(orm): resolve actual SQL types before casting in buildCompar…
ymc9 f70e984
test(regression): add auth() vs @db.Uuid regression test for issue #2394
ymc9 10ac9f8
fix test
ymc9 1094d85
fix(policy): resolve FieldDef through relation chains for native-type…
ymc9 f7a30cb
refactor(policy): pass context to getFieldDefFromFieldRef instead of …
ymc9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { createPolicyTestClient } from '@zenstackhq/testtools'; | ||
| import { randomUUID } from 'node:crypto'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| describe('Regression for issue #2394', () => { | ||
| it('should work with post-update rules when uuid fields are used', async () => { | ||
| const db = await createPolicyTestClient( | ||
| ` | ||
| model Item { | ||
| id String @id @default(uuid()) @db.Uuid | ||
| status String | ||
|
|
||
| @@allow('create,read,update', true) | ||
| @@deny('post-update', before().status == status) | ||
| } | ||
| `, | ||
| { provider: 'postgresql', usePrismaPush: true }, | ||
| ); | ||
|
|
||
| const item = await db.item.create({ data: { status: 'draft' } }); | ||
|
|
||
| // updating with a different status should succeed (post-update policy: deny if status didn't change) | ||
| const updated = await db.item.update({ where: { id: item.id }, data: { status: 'published' } }); | ||
| expect(updated.status).toBe('published'); | ||
|
|
||
| // // updating with the same status should be denied | ||
| // await expect(db.item.update({ where: { id: updated.id }, data: { status: 'published' } })).rejects.toThrow(); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| }); | ||
|
|
||
| it('should work with policies comparing string field with uuid field', async () => { | ||
| const db = await createPolicyTestClient( | ||
| ` | ||
| model Foo { | ||
| id String @id @default(uuid()) @db.Uuid | ||
| id1 String | ||
| value Int | ||
| @@allow('all', id == id1) | ||
| } | ||
| `, | ||
| { provider: 'postgresql', usePrismaPush: true }, | ||
| ); | ||
|
|
||
| const newId = randomUUID(); | ||
|
|
||
| await expect(db.foo.create({ data: { id: newId, id1: newId, value: 0 } })).toResolveTruthy(); | ||
| await expect(db.foo.update({ where: { id: newId }, data: { value: 1 } })).toResolveTruthy(); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.