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
2 changes: 1 addition & 1 deletion packages/orm/src/client/crud/operations/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export abstract class BaseOperationHandler<Schema extends SchemaDef> {

// TODO: this is not clean, needs a better solution
protected get hasPolicyEnabled() {
return this.options.plugins?.some((plugin) => plugin.constructor.name === 'PolicyPlugin');
return this.options.plugins?.some((plugin) => plugin.id === 'policy') ?? false;
}

protected requireModel(model: string) {
Expand Down
29 changes: 29 additions & 0 deletions tests/regression/test/policy-plugin-detection.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { PolicyPlugin } from '@zenstackhq/plugin-policy';
import { createTestClient } from '@zenstackhq/testtools';
import { describe, expect, it } from 'vitest';

describe('PolicyPlugin detection', () => {
it('uses plugin id when constructor names are bundled or minified', async () => {
const MinifiedPolicyPlugin = class a extends PolicyPlugin {};
const plugin = new MinifiedPolicyPlugin();

expect(plugin.id).toBe('policy');
expect(plugin.constructor.name).toBe('a');

const db = await createTestClient(
`
model User {
id String @id
name String

@@allow('all', true)
}
`,
{ plugins: [plugin] },
);

await db.user.create({ data: { id: 'u1', name: 'User 1' } });

await expect(db.user.delete({ where: { id: 'u1' } })).resolves.toEqual({ id: 'u1', name: 'User 1' });
});
});
Loading