@zenstackhq/plugin-policy 3.6.2 → 3.6.3-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -787,7 +787,11 @@ var PolicyHandler = class extends OperationNodeTransformer {
787
787
  if (isTrueNode(fieldLevelFilter)) return;
788
788
  const modelLevelFilter = this.buildPolicyFilter(mutationModel, void 0, "update");
789
789
  const updateFilter = conjunction(this.dialect, [modelLevelFilter, node.where?.where ?? trueNode(this.dialect)]);
790
- if ((await proceed(this.eb.selectFrom(mutationModel).select((eb) => eb.fn.coalesce(eb.fn.sum(this.dialect.castInt(new ExpressionWrapper(logicalNot(this.dialect, fieldLevelFilter)))), eb.lit(0)).as("$filteredCount")).where(() => new ExpressionWrapper(updateFilter)).toOperationNode())).rows[0].$filteredCount > 0) throw createRejectedByPolicyError(mutationModel, RejectedByPolicyReason.NO_ACCESS, "some rows cannot be updated due to field policies");
790
+ const violatingRowsQuery = this.eb.selectFrom(mutationModel).select(this.eb.lit(1).as("_")).where(() => new ExpressionWrapper(conjunction(this.dialect, [updateFilter, logicalNot(this.dialect, fieldLevelFilter)])));
791
+ if ((await proceed({
792
+ kind: "SelectQueryNode",
793
+ selections: [SelectionNode.create(AliasNode.create(this.eb.exists(violatingRowsQuery).toOperationNode(), IdentifierNode.create("$condition")))]
794
+ })).rows[0].$condition) throw createRejectedByPolicyError(mutationModel, RejectedByPolicyReason.NO_ACCESS, "some rows cannot be updated due to field policies");
791
795
  }
792
796
  async postUpdateCheck(model, beforeUpdateInfo, updateResult, proceed) {
793
797
  let postUpdateRows;
@@ -1106,7 +1110,11 @@ var PolicyHandler = class extends OperationNodeTransformer {
1106
1110
  }
1107
1111
  const valuesTable = this.dialect.buildValuesTableSelect(allFields, [allValues]);
1108
1112
  const filter = this.buildPolicyFilter(model, void 0, "create");
1109
- if (!(await proceed(this.eb.selectFrom(valuesTable.as(model)).select(this.eb(this.eb.fn.count(this.eb.lit(1)), ">", 0).as("$condition")).where(() => new ExpressionWrapper(filter)).toOperationNode())).rows[0]?.$condition) throw createRejectedByPolicyError(model, RejectedByPolicyReason.NO_ACCESS);
1113
+ const preCreateInner = this.eb.selectFrom(valuesTable.as(model)).select(this.eb.lit(1).as("_")).where(() => new ExpressionWrapper(filter));
1114
+ if (!(await proceed({
1115
+ kind: "SelectQueryNode",
1116
+ selections: [SelectionNode.create(AliasNode.create(this.eb.exists(preCreateInner).toOperationNode(), IdentifierNode.create("$condition")))]
1117
+ })).rows[0]?.$condition) throw createRejectedByPolicyError(model, RejectedByPolicyReason.NO_ACCESS);
1110
1118
  }
1111
1119
  unwrapCreateValueRows(node, model, fields, isManyToManyJoinTable) {
1112
1120
  if (ValuesNode.is(node)) return node.values.map((v) => this.unwrapCreateValueRow(v.values, model, fields, isManyToManyJoinTable));