Skip to content

Commit c948e75

Browse files
committed
feat: add list rule
1 parent 05bcc93 commit c948e75

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
@@ -35,7 +35,7 @@ export interface DbOperations {
3535
*/
3636
export type PolicyKind = 'allow' | 'deny';
3737

38-
export type PolicyCrudKind = 'read' | 'create' | 'update' | 'delete';
38+
export type PolicyCrudKind = 'read' | 'create' | 'update' | 'delete' | 'list';
3939

4040
/**
4141
* 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
@@ -504,7 +504,7 @@ attribute @@schema(_ name: String) @@@prisma
504504
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
505505
* @param condition: a boolean expression that controls if the operation should be allowed.
506506
*/
507-
attribute @@allow(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'all'"]), _ condition: Boolean)
507+
attribute @@allow(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'list'", "'all'"]), _ condition: Boolean)
508508

509509
/**
510510
* Defines an access policy that allows the annotated field to be read or updated.
@@ -522,7 +522,7 @@ attribute @allow(_ operation: String @@@completionHint(["'create'", "'read'", "'
522522
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
523523
* @param condition: a boolean expression that controls if the operation should be denied.
524524
*/
525-
attribute @@deny(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'all'"]), _ condition: Boolean)
525+
attribute @@deny(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'list'", "'all'"]), _ condition: Boolean)
526526

527527
/**
528528
* 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)