From 4cda546880340a809d975bbddc3d5929fa3263e9 Mon Sep 17 00:00:00 2001 From: Toby <2287769986@qq.com> Date: Wed, 9 Oct 2024 15:55:59 +0800 Subject: [PATCH] =?UTF-8?q?fix(workflow):=20=E6=95=B0=E6=8D=AE=E8=A1=A8?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E6=97=B6=E6=9C=BA=E4=B8=BA=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=9A=84=E9=BB=91=E7=99=BD=E5=90=8D=E5=8D=95?= =?UTF-8?q?=E6=9C=BA=E5=88=B6=E4=BF=AE=E6=94=B9=20(#1585)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 数据库触发器仅在变化字段都在黑名单才失效 Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1585 Co-authored-by: Toby <2287769986@qq.com> Co-committed-by: Toby <2287769986@qq.com> --- .../src/server/triggers/CollectionTrigger.ts | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/triggers/CollectionTrigger.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/triggers/CollectionTrigger.ts index 993ac2aff..9d83b8fa1 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/triggers/CollectionTrigger.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/triggers/CollectionTrigger.ts @@ -57,16 +57,24 @@ async function handler(this: CollectionTrigger, workflow: WorkflowModel, data: M ) { return; } - if ( - blacklist && - blacklist.length && - blacklist - .filter( - (name) => !['linkTo', 'hasOne', 'hasMany', 'belongsToMany'].includes(collection.getField(name).options.type), - ) - .some((name) => data.changedWithAssociations(getFieldRawName(collection, name))) - ) { - return; + + if (blacklist && blacklist.length) { + const changedWithAssociations = data.changedWithAssociations() as string[]; + // 系统字段 + const presetFields = ['createdBy', 'createdById', 'createdAt', 'updatedBy', 'updatedById', 'updatedAt']; + if (changedWithAssociations) { + // exclude system fields + const userFields = changedWithAssociations.filter( + (field) => + !presetFields.includes(field) && + collection.getField(field) && + !['linkTo', 'hasOne', 'hasMany', 'belongsToMany'].includes(collection.getField(field).options.type), + ); + const allInBlacklist = userFields.every((name) => blacklist.includes(name)); + if (allInBlacklist) { + return; + } + } } // NOTE: if no configured condition match, do not trigger if (condition && condition.$and?.length) {