From 6e8cd9e3ec95325b6924a10b6b9434c095a6865e Mon Sep 17 00:00:00 2001 From: "Xc@centOs" Date: Mon, 24 Jul 2023 15:23:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E5=88=86=E8=A7=A3cascade=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=97=B6,=E5=AF=B9create=E7=9A=84=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E7=B2=BE=E7=BB=86=E5=8C=96=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/store/RelationAuth.js | 22 +++++++++++++++++++++- src/store/RelationAuth.ts | 25 +++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/lib/store/RelationAuth.js b/lib/store/RelationAuth.js index 86e533b..66d80cb 100644 --- a/lib/store/RelationAuth.js +++ b/lib/store/RelationAuth.js @@ -1467,8 +1467,28 @@ var RelationAuth = /** @class */ (function () { */ RelationAuth.prototype.destructOperation = function (entity2, operation2, userId) { var _this = this; + /** + * 对create动作,把data中的cascade部分剔除后作为filter参与后续的检验 + * @param operation + * @returns + */ + var makeCreateFilter = function (operation) { + var data = operation.data, filter = operation.filter; + (0, assert_1.default)(!(data instanceof Array)); + if (data) { + var data2 = {}; + for (var attr in data) { + var rel = (0, relation_1.judgeRelation)(_this.schema, entity2, attr); + if (rel === 1) { + data2[attr] = data[attr]; + } + } + return data2; + } + return filter; + }; var action = operation2.action, data = operation2.data, filter = operation2.filter; - var filter2 = action === 'create' ? data || filter : filter; + var filter2 = action === 'create' ? makeCreateFilter(operation2) : filter; (0, assert_1.default)(filter2); var addChild = function (node, path, child) { var _a; diff --git a/src/store/RelationAuth.ts b/src/store/RelationAuth.ts index c5bd0cd..8912f29 100644 --- a/src/store/RelationAuth.ts +++ b/src/store/RelationAuth.ts @@ -1714,9 +1714,30 @@ export class RelationAuth{ * @param entity * @param selection */ - private destructOperation(entity2: T, operation2: Omit, userId: string) { + private destructOperation(entity2: T, operation2: Omit, userId: string) { + /** + * 对create动作,把data中的cascade部分剔除后作为filter参与后续的检验 + * @param operation + * @returns + */ + const makeCreateFilter = (operation: Omit) => { + const { data, filter } = operation; + assert(!(data instanceof Array)); + if (data) { + const data2: ED[T]['Selection']['filter'] = {}; + for (const attr in data) { + const rel = judgeRelation(this.schema, entity2, attr); + if (rel === 1) { + data2[attr] = data[attr]; + } + } + return data2; + } + return filter; + }; + const { action, data, filter } = operation2; - const filter2 = action === 'create' ? data || filter : filter; + const filter2 = action === 'create' ? makeCreateFilter(operation2 as Omit) : filter; assert(filter2); const addChild = (node: OperationTree, path: string, child: OperationTree) => {