Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/runtime/src/enhancements/policy/policy-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,10 @@ export class PolicyUtil extends QueryUtils {
const hoistedConditions: any[] = [];

for (const field of getModelFields(injectTarget)) {
if (injectTarget[field] === false) {
continue;
}

const fieldInfo = resolveField(this.modelMeta, model, field);
if (!fieldInfo || !fieldInfo.isDataModel) {
// only care about relation fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class ExpressionValidator implements AstValidator<Expression> {
// check was done at link time
accept(
'error',
'auth() cannot be resolved because no model marked wth "@@auth()" or named "User" is found',
'auth() cannot be resolved because no model marked with "@@auth()" or named "User" is found',
{ node: expr }
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ describe('Attribute tests', () => {
@@allow('all', auth() != null)
}
`)
).toContain(`auth() cannot be resolved because no model marked wth "@@auth()" or named "User" is found`);
).toContain(`auth() cannot be resolved because no model marked with "@@auth()" or named "User" is found`);

await loadModel(`
${prelude}
Expand Down
42 changes: 42 additions & 0 deletions tests/regression/tests/issue-1427.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { loadSchema } from '@zenstackhq/testtools';

describe('issue 1427', () => {
it('regression', async () => {
const { prisma, enhance } = await loadSchema(
`
model User {
id String @id @default(cuid())
name String
profile Profile?
@@allow('all', true)
}

model Profile {
id String @id @default(cuid())
user User @relation(fields: [userId], references: [id])
userId String @unique
@@allow('all', true)
}
`
);

await prisma.user.create({
data: {
name: 'John',
profile: {
create: {},
},
},
});

const db = enhance();
const found = await db.user.findFirst({
select: {
id: true,
name: true,
profile: false,
},
});
expect(found.profile).toBeUndefined();
});
});