Skip to content

Commit 1eb735c

Browse files
committed
feat: add list rule
1 parent 2eecae5 commit 1eb735c

File tree

5 files changed

+12
-3
lines changed

5 files changed

+12
-3
lines changed

packages/runtime/src/enhancements/node/policy/policy-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ export class PolicyUtil extends QueryUtils {
277277
create: { guard: true, inputChecker: true },
278278
update: { guard: true },
279279
delete: { guard: true },
280+
list: { guard: true },
280281
postUpdate: { guard: true },
281282
},
282283
};

packages/runtime/src/enhancements/node/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export type ModelCrudDef = {
140140
create: ModelCreateDef;
141141
update: ModelUpdateDef;
142142
delete: ModelDeleteDef;
143+
list: ModelListDef;
143144
postUpdate: ModelPostUpdateDef;
144145
};
145146

@@ -207,6 +208,11 @@ type ModelUpdateDef = ModelCrudCommon;
207208
*/
208209
type ModelDeleteDef = ModelCrudCommon;
209210

211+
/**
212+
* Policy definition for listing a model
213+
*/
214+
type ModelListDef = ModelCrudCommon;
215+
210216
/**
211217
* Policy definition for post-update checking a model
212218
*/

packages/runtime/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface DbOperations {
3636
*/
3737
export type PolicyKind = 'allow' | 'deny';
3838

39-
export type PolicyCrudKind = 'read' | 'create' | 'update' | 'delete';
39+
export type PolicyCrudKind = 'read' | 'create' | 'update' | 'delete' | 'list';
4040

4141
/**
4242
* Kinds of operations controlled by access policies

packages/schema/src/res/stdlib.zmodel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ attribute @@schema(_ name: String) @@@prisma
527527
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
528528
* @param condition: a boolean expression that controls if the operation should be allowed.
529529
*/
530-
attribute @@allow(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'all'"]), _ condition: Boolean)
530+
attribute @@allow(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'list'", "'all'"]), _ condition: Boolean)
531531

532532
/**
533533
* Defines an access policy that allows the annotated field to be read or updated.
@@ -545,7 +545,7 @@ attribute @allow(_ operation: String @@@completionHint(["'create'", "'read'", "'
545545
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
546546
* @param condition: a boolean expression that controls if the operation should be denied.
547547
*/
548-
attribute @@deny(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'all'"]), _ condition: Boolean)
548+
attribute @@deny(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'list'", "'all'"]), _ condition: Boolean)
549549

550550
/**
551551
* Defines an access policy that denies the annotated field to be read or updated.

packages/sdk/src/policy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export function analyzePolicies(dataModel: DataModel) {
1212
const read = toStaticPolicy('read', allows, denies);
1313
const update = toStaticPolicy('update', allows, denies);
1414
const del = toStaticPolicy('delete', allows, denies);
15+
const list = toStaticPolicy('list', allows, denies);
1516
const hasFieldValidation = hasValidationAttributes(dataModel);
1617

1718
return {
@@ -21,6 +22,7 @@ export function analyzePolicies(dataModel: DataModel) {
2122
read,
2223
update,
2324
delete: del,
25+
list,
2426
allowAll: create === true && read === true && update === true && del === true,
2527
denyAll: create === false && read === false && update === false && del === false,
2628
hasFieldValidation,

0 commit comments

Comments
 (0)