Skip to content
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

chore(perm-checker): rename filter clause to where #1413

Merged
merged 2 commits into from
May 7, 2024
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
6 changes: 3 additions & 3 deletions packages/runtime/src/enhancements/policy/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type FindOperations = 'findUnique' | 'findUniqueOrThrow' | 'findFirst' | 'findFi
// input arg type for `check` API
type PermissionCheckArgs = {
operation: PolicyCrudKind;
filter?: Record<string, number | string | boolean>;
where?: Record<string, number | string | boolean>;
};

/**
Expand Down Expand Up @@ -1466,11 +1466,11 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
return constraint;
}

if (args.filter) {
if (args.where) {
// combine runtime filters with generated constraints

const extraConstraints: CheckerConstraint[] = [];
for (const [field, value] of Object.entries(args.filter)) {
for (const [field, value] of Object.entries(args.where)) {
if (value === undefined) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface ModelCheckers {

function generateDataModelChecker(dataModel: DataModel) {
return `{
check(args: { operation: PolicyCrudKind, filter?: ${generateDataModelArgs(dataModel)} }): Promise<boolean>
check(args: { operation: PolicyCrudKind, where?: ${generateDataModelArgs(dataModel)} }): Promise<boolean>
}`;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/server/tests/api/rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('RPC API Handler Tests', () => {
r = await handleRequest({
method: 'get',
path: '/post/check',
query: { q: JSON.stringify({ operation: 'read', filter: { published: false } }) },
query: { q: JSON.stringify({ operation: 'read', where: { published: false } }) },
prisma: enhance(),
});
expect(r.status).toBe(200);
Expand All @@ -155,7 +155,7 @@ describe('RPC API Handler Tests', () => {
r = await handleRequest({
method: 'get',
path: '/post/check',
query: { q: JSON.stringify({ operation: 'read', filter: { authorId: '1', published: false } }) },
query: { q: JSON.stringify({ operation: 'read', where: { authorId: '1', published: false } }) },
prisma: enhance({ id: '1' }),
});
expect(r.status).toBe(200);
Expand Down
Loading
Loading