fix(workflow): 数据表触发时机为更新数据的黑白名单机制修改 (#1585)

数据库触发器仅在变化字段都在黑名单才失效

Reviewed-on: daoyoucloud/tachybase#1585
Co-authored-by: Toby <2287769986@qq.com>
Co-committed-by: Toby <2287769986@qq.com>
This commit is contained in:
Toby 2024-10-09 15:55:59 +08:00 committed by bai.zixv
parent 9ec524171d
commit 4cda546880

View File

@ -57,17 +57,25 @@ 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)))
) {
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) {
// TODO: change to map filter format to calculation format