From c2a5e1bda11e468d32e19f35aecdd86bad5eab3b Mon Sep 17 00:00:00 2001 From: Xc Date: Sun, 4 May 2025 16:19:29 +0800 Subject: [PATCH] =?UTF-8?q?relationAuth=E4=B8=AD=E6=8A=8AupdateFree?= =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD=E4=B8=8B=E9=99=8D=E5=88=B0=E6=AF=8F?= =?UTF-8?q?=E4=B8=80=E5=B1=82=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/store/IntrinsicCheckers.js | 8 ++++---- lib/store/RelationAuth.js | 8 +++++--- lib/utils/assert.d.ts | 1 + lib/utils/relationPath.js | 2 +- src/store/RelationAuth.ts | 10 ++++++---- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/store/IntrinsicCheckers.js b/lib/store/IntrinsicCheckers.js index 0d3f08d..a972231 100644 --- a/lib/store/IntrinsicCheckers.js +++ b/lib/store/IntrinsicCheckers.js @@ -79,7 +79,7 @@ function createUniqueCheckers(schema) { entity, action: 'create', type: 'logicalData', - priority: types_1.CHECKER_MAX_PRIORITY, + priority: types_1.CHECKER_MAX_PRIORITY, // 优先级要放在最低,所有前置的checker/trigger将数据完整之后再在这里检测 checker: (operation, context) => { const { data } = operation; if (data instanceof Array) { @@ -95,9 +95,9 @@ function createUniqueCheckers(schema) { } }, { entity, - action: 'update', + action: 'update', // 只检查update,其它状态转换的action应该不会涉及unique约束的属性 type: 'logicalData', - priority: types_1.CHECKER_MAX_PRIORITY, + priority: types_1.CHECKER_MAX_PRIORITY, // 优先级要放在最低,所有前置的checker/trigger将数据完整之后再在这里检测 checker: (operation, context) => { const { data, filter: operationFilter } = operation; if (data) { @@ -227,7 +227,7 @@ function createActionTransformerCheckers(actionDefDict) { action: 'create', type: 'logical', entity, - priority: 10, + priority: 10, // 优先级要高,先于真正的data检查进行 checker: (operation) => { const { data } = operation; if (data instanceof Array) { diff --git a/lib/store/RelationAuth.js b/lib/store/RelationAuth.js index ec15afe..d5b1f90 100644 --- a/lib/store/RelationAuth.js +++ b/lib/store/RelationAuth.js @@ -1045,6 +1045,11 @@ class RelationAuth { if (actionAuths && actionAuths.length > 0) { return checkChildren(actionAuths); } + // 如果这个entity是updateFree,直接过掉到子结点判定 + const { action, entity } = node; + if (this.updateFreeDict[entity] && this.updateFreeDict[entity].includes(action)) { + return checkChildren([]); + } // 没有能根据父亲传下来的actionAuth判定,只能自己找 const result = this.findActionAuthsOnNode(node, context); const checkResult = (result2) => { @@ -1083,9 +1088,6 @@ class RelationAuth { } checkOperation(entity, operation, context) { const { action, filter, data } = operation; - if (this.updateFreeDict[entity] && this.updateFreeDict[entity].includes(action)) { - return true; - } const userId = context.getCurrentUserId(); if (!userId) { throw new types_1.OakUnloggedInException(); diff --git a/lib/utils/assert.d.ts b/lib/utils/assert.d.ts index c502695..932ffd1 100644 --- a/lib/utils/assert.d.ts +++ b/lib/utils/assert.d.ts @@ -1,3 +1,4 @@ +/// /** * 防止assert打包体积过大,从这里引用 */ diff --git a/lib/utils/relationPath.js b/lib/utils/relationPath.js index 00c7c5e..8ca798a 100644 --- a/lib/utils/relationPath.js +++ b/lib/utils/relationPath.js @@ -60,7 +60,7 @@ function destructRelationPath(schema, entity, path, relationFilter, recursive) { }, filter: relationFilter, } // as ED['userRelation']['Selection'] - }, + }, // as ED[keyof ED]['Projection'], getData: (d) => { return d.userRelation$entity; }, diff --git a/src/store/RelationAuth.ts b/src/store/RelationAuth.ts index 379c074..c36817d 100644 --- a/src/store/RelationAuth.ts +++ b/src/store/RelationAuth.ts @@ -1358,9 +1358,14 @@ export class RelationAuth { return checkChildren(actionAuths); } + // 如果这个entity是updateFree,直接过掉到子结点判定 + const { action, entity } = node; + if (this.updateFreeDict[entity] && this.updateFreeDict[entity]!.includes(action)) { + return checkChildren([]); + } + // 没有能根据父亲传下来的actionAuth判定,只能自己找 const result = this.findActionAuthsOnNode(node, context); - const checkResult = (result2: false | ED['actionAuth']['Schema'][]) => { if (result2 === false) { return false; @@ -1407,9 +1412,6 @@ export class RelationAuth { context: Cxt, ) { const { action, filter, data } = operation; - if (this.updateFreeDict[entity] && this.updateFreeDict[entity]!.includes(action)) { - return true; - } const userId = context.getCurrentUserId(); if (!userId) { throw new OakUnloggedInException();