mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 21:49:25 +08:00
refactor(plugin-workflow): add option to skip triggering in collection event (#6379)
This commit is contained in:
parent
8b1a718091
commit
f6ec9f82b4
@ -161,6 +161,23 @@ describe('workflow > triggers > collection', () => {
|
|||||||
expect(executions.length).toBe(1);
|
expect(executions.length).toBe(1);
|
||||||
expect(executions[0].context.data.title).toBe('c1');
|
expect(executions[0].context.data.title).toBe('c1');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('skipWorkflow', async () => {
|
||||||
|
const workflow = await WorkflowModel.create({
|
||||||
|
enabled: true,
|
||||||
|
sync: true,
|
||||||
|
type: 'collection',
|
||||||
|
config: {
|
||||||
|
mode: 1,
|
||||||
|
collection: 'posts',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const post = await PostRepo.create({ values: { title: 't1' }, context: { skipWorkflow: true } });
|
||||||
|
|
||||||
|
const executions = await workflow.getExecutions();
|
||||||
|
expect(executions.length).toBe(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('config.mode', () => {
|
describe('config.mode', () => {
|
||||||
|
@ -53,13 +53,17 @@ export default class CollectionTrigger extends Trigger {
|
|||||||
|
|
||||||
// async function, should return promise
|
// async function, should return promise
|
||||||
private static async handler(this: CollectionTrigger, workflow: WorkflowModel, data: Model, options) {
|
private static async handler(this: CollectionTrigger, workflow: WorkflowModel, data: Model, options) {
|
||||||
|
const { skipWorkflow = false, stack } = options.context ?? {};
|
||||||
|
if (skipWorkflow) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const [dataSourceName] = parseCollectionName(workflow.config.collection);
|
const [dataSourceName] = parseCollectionName(workflow.config.collection);
|
||||||
const transaction = this.workflow.useDataSourceTransaction(dataSourceName, options.transaction);
|
const transaction = this.workflow.useDataSourceTransaction(dataSourceName, options.transaction);
|
||||||
const ctx = await this.prepare(workflow, data, { ...options, transaction });
|
const ctx = await this.prepare(workflow, data, { ...options, transaction });
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { stack } = options.context ?? {};
|
|
||||||
if (workflow.sync) {
|
if (workflow.sync) {
|
||||||
await this.workflow.trigger(workflow, ctx, {
|
await this.workflow.trigger(workflow, ctx, {
|
||||||
transaction,
|
transaction,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user