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:
parent
9ec524171d
commit
4cda546880
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user