diff --git a/packages/schema/src/plugins/access-policy/policy-guard-generator.ts b/packages/schema/src/plugins/access-policy/policy-guard-generator.ts index 6a080cd06..a25d17458 100644 --- a/packages/schema/src/plugins/access-policy/policy-guard-generator.ts +++ b/packages/schema/src/plugins/access-policy/policy-guard-generator.ts @@ -360,7 +360,7 @@ export default class PolicyGenerator { } const hasFieldAccess = [...denies, ...allows].some((rule) => - streamAllContents(rule).some( + [rule, ...streamAllContents(rule)].some( (child) => // this.??? isThisExpr(child) || diff --git a/tests/integration/test-run/package-lock.json b/tests/integration/test-run/package-lock.json index cc02e4786..cb5f183b5 100644 --- a/tests/integration/test-run/package-lock.json +++ b/tests/integration/test-run/package-lock.json @@ -182,6 +182,7 @@ "promisify": "^0.0.3", "semver": "^7.3.8", "sleep-promise": "^9.1.0", + "strip-color": "^0.1.0", "ts-morph": "^16.0.0", "upper-case-first": "^2.0.2", "uuid": "^9.0.0", @@ -203,6 +204,7 @@ "@types/node": "^14.18.32", "@types/pluralize": "^0.0.29", "@types/semver": "^7.3.13", + "@types/strip-color": "^0.1.0", "@types/tmp": "^0.2.3", "@types/upper-case-first": "^1.1.2", "@types/uuid": "^8.3.4", @@ -416,6 +418,7 @@ "@types/node": "^14.18.32", "@types/pluralize": "^0.0.29", "@types/semver": "^7.3.13", + "@types/strip-color": "^0.1.0", "@types/tmp": "^0.2.3", "@types/upper-case-first": "^1.1.2", "@types/uuid": "^8.3.4", @@ -451,6 +454,7 @@ "rimraf": "^3.0.2", "semver": "^7.3.8", "sleep-promise": "^9.1.0", + "strip-color": "^0.1.0", "tmp": "^0.2.1", "ts-jest": "^29.0.3", "ts-morph": "^16.0.0", diff --git a/tests/integration/tests/regression/issues.test.ts b/tests/integration/tests/regression/issues.test.ts index 03363583b..afc5f0324 100644 --- a/tests/integration/tests/regression/issues.test.ts +++ b/tests/integration/tests/regression/issues.test.ts @@ -164,4 +164,31 @@ describe('GitHub issues regression', () => { const r = await db.user.findFirst({ select: { _count: { select: { posts: true } } } }); expect(r).toMatchObject({ _count: { posts: 2 } }); }); + + it('issue 509', async () => { + await loadSchema( + ` + model User { + id Int @id @default(autoincrement()) + email String @unique + name String? + posts Post[] + } + + model Post { + id Int @id @default(autoincrement()) + title String + content String? + published Boolean @default(false) + author User? @relation(fields: [authorId], references: [id]) + authorId Int? + + deleted Boolean @default(false) @omit + + @@allow('all', true) + @@deny('read', deleted) + } + ` + ); + }); });