From 30a3fd48b2af3af95bc4cf8c207899ce91fe3e61 Mon Sep 17 00:00:00 2001 From: dennemark Date: Fri, 26 Jul 2024 17:19:48 +0200 Subject: [PATCH] Release 0.1.4 --- CHANGELOG.md | 7 +++++++ dist/index.js | 9 +++++++-- dist/index.mjs | 9 +++++++-- package.json | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1eaa6f4..c2383fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ +## [0.1.4](https://github.com/dennemark/prisma-extension-casl/compare/0.1.3...0.1.4) (2024-07-26) + + +### Bug Fixes + +* :bug: consider rules without fields in select queries ([2a222ae](https://github.com/dennemark/prisma-extension-casl/commit/2a222aec8b546f416bbed9ea19f79acd77a7b877)) + ## [0.1.3](https://github.com/dennemark/prisma-extension-casl/compare/0.1.2...0.1.3) (2024-07-26) diff --git a/dist/index.js b/dist/index.js index aee92b7..bfe6f57 100644 --- a/dist/index.js +++ b/dist/index.js @@ -857,9 +857,13 @@ var propertyFieldsByModel = Object.fromEntries(import_client.Prisma.dmmf.datamod })); function getPermittedFields(abilities, args, action, model) { let hasPermittedFields = false; + let hasNoRuleWithoutFields = void 0; const omittedFieldsSet = /* @__PURE__ */ new Set(); const permittedFields = c4(abilities, action, model, { fieldsFrom: (rule) => { + if (hasNoRuleWithoutFields === void 0) { + hasNoRuleWithoutFields = true; + } if (rule.fields) { if (rule.inverted) { rule.fields.forEach((field) => omittedFieldsSet.add(field)); @@ -869,11 +873,12 @@ function getPermittedFields(abilities, args, action, model) { if (rule.conditions) { if (isSubset(rule.conditions, args.where)) { return rule.fields; - } else { } } else { return rule.fields; } + } else { + hasNoRuleWithoutFields = false; } return []; } @@ -882,7 +887,7 @@ function getPermittedFields(abilities, args, action, model) { permittedFields.push(...Object.keys(propertyFieldsByModel[model]).filter((field) => !omittedFieldsSet.has(field))); hasPermittedFields = true; } - return hasPermittedFields ? permittedFields : void 0; + return hasPermittedFields && permittedFields.length > 0 ? permittedFields : hasNoRuleWithoutFields ? [] : void 0; } function isSubset(obj1, obj2) { if (obj1 === obj2) return true; diff --git a/dist/index.mjs b/dist/index.mjs index 53148ff..49ba128 100644 --- a/dist/index.mjs +++ b/dist/index.mjs @@ -832,9 +832,13 @@ var propertyFieldsByModel = Object.fromEntries(Prisma.dmmf.datamodel.models.map( })); function getPermittedFields(abilities, args, action, model) { let hasPermittedFields = false; + let hasNoRuleWithoutFields = void 0; const omittedFieldsSet = /* @__PURE__ */ new Set(); const permittedFields = c4(abilities, action, model, { fieldsFrom: (rule) => { + if (hasNoRuleWithoutFields === void 0) { + hasNoRuleWithoutFields = true; + } if (rule.fields) { if (rule.inverted) { rule.fields.forEach((field) => omittedFieldsSet.add(field)); @@ -844,11 +848,12 @@ function getPermittedFields(abilities, args, action, model) { if (rule.conditions) { if (isSubset(rule.conditions, args.where)) { return rule.fields; - } else { } } else { return rule.fields; } + } else { + hasNoRuleWithoutFields = false; } return []; } @@ -857,7 +862,7 @@ function getPermittedFields(abilities, args, action, model) { permittedFields.push(...Object.keys(propertyFieldsByModel[model]).filter((field) => !omittedFieldsSet.has(field))); hasPermittedFields = true; } - return hasPermittedFields ? permittedFields : void 0; + return hasPermittedFields && permittedFields.length > 0 ? permittedFields : hasNoRuleWithoutFields ? [] : void 0; } function isSubset(obj1, obj2) { if (obj1 === obj2) return true; diff --git a/package.json b/package.json index 69e79b2..34d9e2e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prisma-extension-casl", - "version": "0.1.3", + "version": "0.1.4", "description": "Enforce casl abilities on prisma client ", "main": "dist/index.js", "types": "dist/index.d.ts",