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; return;
} }
if (
blacklist && if (blacklist && blacklist.length) {
blacklist.length && const changedWithAssociations = data.changedWithAssociations() as string[];
blacklist // 系统字段
.filter( const presetFields = ['createdBy', 'createdById', 'createdAt', 'updatedBy', 'updatedById', 'updatedAt'];
(name) => !['linkTo', 'hasOne', 'hasMany', 'belongsToMany'].includes(collection.getField(name).options.type), if (changedWithAssociations) {
) // exclude system fields
.some((name) => data.changedWithAssociations(getFieldRawName(collection, name))) 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; return;
} }
}
}
// NOTE: if no configured condition match, do not trigger // NOTE: if no configured condition match, do not trigger
if (condition && condition.$and?.length) { if (condition && condition.$and?.length) {
// TODO: change to map filter format to calculation format // TODO: change to map filter format to calculation format