Skip to content

Commit 0ea071b

Browse files
authored
fix: incorrect policy code generated when the rule only contains a single field reference (#511)
1 parent 304979f commit 0ea071b

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

packages/schema/src/plugins/access-policy/policy-guard-generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ export default class PolicyGenerator {
360360
}
361361

362362
const hasFieldAccess = [...denies, ...allows].some((rule) =>
363-
streamAllContents(rule).some(
363+
[rule, ...streamAllContents(rule)].some(
364364
(child) =>
365365
// this.???
366366
isThisExpr(child) ||

tests/integration/test-run/package-lock.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/tests/regression/issues.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,31 @@ describe('GitHub issues regression', () => {
164164
const r = await db.user.findFirst({ select: { _count: { select: { posts: true } } } });
165165
expect(r).toMatchObject({ _count: { posts: 2 } });
166166
});
167+
168+
it('issue 509', async () => {
169+
await loadSchema(
170+
`
171+
model User {
172+
id Int @id @default(autoincrement())
173+
email String @unique
174+
name String?
175+
posts Post[]
176+
}
177+
178+
model Post {
179+
id Int @id @default(autoincrement())
180+
title String
181+
content String?
182+
published Boolean @default(false)
183+
author User? @relation(fields: [authorId], references: [id])
184+
authorId Int?
185+
186+
deleted Boolean @default(false) @omit
187+
188+
@@allow('all', true)
189+
@@deny('read', deleted)
190+
}
191+
`
192+
);
193+
});
167194
});

0 commit comments

Comments
 (0)