-
-
Notifications
You must be signed in to change notification settings - Fork 144
merge dev to main (v3.4.6) #2478
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
930d996
fix(policy): support now() default value in access policy evaluation
ymc9 d3ab3a6
fix(policy): support now() default value in access policy evaluation …
ymc9 31776a8
fix(orm): use IS operator for null comparisons in filters (#2475)
ymc9 2c32dc3
[CI] Bump version 3.4.6 (#2477)
github-actions[bot] d4fbb38
fix(orm): add webpack magic comment to suppress bundler warnings for …
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
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@zenstackhq/typescript-config", | ||
| "version": "3.4.5", | ||
| "version": "3.4.6", | ||
| "private": true, | ||
| "license": "MIT" | ||
| } |
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
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
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
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
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,125 @@ | ||
| import { createPolicyTestClient } from '@zenstackhq/testtools'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| describe('now() function in policy tests', () => { | ||
| it('allows create when createdAt default now() is used in comparison', async () => { | ||
| const db = await createPolicyTestClient( | ||
| ` | ||
| model Post { | ||
| id Int @id @default(autoincrement()) | ||
| title String | ||
| createdAt DateTime? @default(now()) | ||
| @@allow('create', createdAt != null) | ||
| @@allow('read', true) | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| // createdAt should be auto-filled with now(), satisfying the <= now() check | ||
| await expect(db.post.create({ data: { title: 'hello' } })).resolves.toMatchObject({ title: 'hello' }); | ||
| const post = await db.post.findFirst(); | ||
| expect(post.createdAt).toBeInstanceOf(Date); | ||
| }); | ||
|
|
||
| it('uses now() in update policy to compare against DateTime field', async () => { | ||
| const db = await createPolicyTestClient( | ||
| ` | ||
| model Event { | ||
| id Int @id @default(autoincrement()) | ||
| name String | ||
| scheduledAt DateTime | ||
| @@allow('create,read', true) | ||
| @@allow('update', scheduledAt > now()) | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| // create an event in the future - should be updatable | ||
| const futureDate = new Date(Date.now() + 60 * 60 * 1000); | ||
| await db.event.create({ data: { name: 'future', scheduledAt: futureDate } }); | ||
| await expect(db.event.update({ where: { id: 1 }, data: { name: 'updated' } })).resolves.toMatchObject({ | ||
| name: 'updated', | ||
| }); | ||
|
|
||
| // create an event in the past - should NOT be updatable | ||
| const pastDate = new Date(Date.now() - 60 * 60 * 1000); | ||
| await db.event.create({ data: { name: 'past', scheduledAt: pastDate } }); | ||
| await expect(db.event.update({ where: { id: 2 }, data: { name: 'updated' } })).toBeRejectedNotFound(); | ||
| }); | ||
|
|
||
| it('uses now() in read policy to filter DateTime field', async () => { | ||
| const db = await createPolicyTestClient( | ||
| ` | ||
| model Article { | ||
| id Int @id @default(autoincrement()) | ||
| title String | ||
| publishedAt DateTime | ||
| @@allow('create', true) | ||
| @@allow('read', publishedAt <= now()) | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| const rawDb = db.$unuseAll(); | ||
| const pastDate = new Date(Date.now() - 60 * 60 * 1000); | ||
| const futureDate = new Date(Date.now() + 60 * 60 * 1000); | ||
|
|
||
| await rawDb.article.create({ data: { title: 'published', publishedAt: pastDate } }); | ||
| await rawDb.article.create({ data: { title: 'scheduled', publishedAt: futureDate } }); | ||
|
|
||
| // only the past article should be readable | ||
| const articles = await db.article.findMany(); | ||
| expect(articles).toHaveLength(1); | ||
| expect(articles[0].title).toBe('published'); | ||
| }); | ||
|
|
||
| it('uses now() in delete policy', async () => { | ||
| const db = await createPolicyTestClient( | ||
| ` | ||
| model Task { | ||
| id Int @id @default(autoincrement()) | ||
| name String | ||
| expiresAt DateTime | ||
| @@allow('create,read', true) | ||
| @@allow('delete', expiresAt < now()) | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| // create an expired task - should be deletable | ||
| const pastDate = new Date(Date.now() - 60 * 60 * 1000); | ||
| await db.task.create({ data: { name: 'expired', expiresAt: pastDate } }); | ||
| await expect(db.task.delete({ where: { id: 1 } })).resolves.toMatchObject({ name: 'expired' }); | ||
|
|
||
| // create a non-expired task - should NOT be deletable | ||
| const futureDate = new Date(Date.now() + 60 * 60 * 1000); | ||
| await db.task.create({ data: { name: 'active', expiresAt: futureDate } }); | ||
| await expect(db.task.delete({ where: { id: 2 } })).toBeRejectedNotFound(); | ||
| }); | ||
|
|
||
| it('combines now() default with auth in create policy', async () => { | ||
| const db = await createPolicyTestClient( | ||
| ` | ||
| type Auth { | ||
| id Int | ||
| @@auth | ||
| } | ||
|
|
||
| model Log { | ||
| id Int @id @default(autoincrement()) | ||
| message String | ||
| createdAt DateTime @default(now()) | ||
| @@allow('create', createdAt <= now() && auth() != null) | ||
| @@allow('read', true) | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| // anonymous user - rejected | ||
| await expect(db.log.create({ data: { message: 'test' } })).toBeRejectedByPolicy(); | ||
| // authenticated user with auto-filled createdAt - allowed | ||
| await expect(db.$setAuth({ id: 1 }).log.create({ data: { message: 'test' } })).resolves.toMatchObject({ | ||
| message: 'test', | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.