mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 05:18:03 +00:00
feat(plugin-workflow-action-trigger): support association actions to trigger (#4007)
This commit is contained in:
parent
699fd52b8e
commit
de935d54b6
@ -54,7 +54,10 @@ export default class extends Trigger {
|
||||
params: { triggerWorkflows = '', values },
|
||||
} = context.action;
|
||||
const dataSourceHeader = context.get('x-data-source') || 'main';
|
||||
const fullCollectionName = joinCollectionName(dataSourceHeader, resourceName);
|
||||
const collection = context.app.dataSourceManager.dataSources
|
||||
.get(dataSourceHeader)
|
||||
.collectionManager.getCollection(resourceName);
|
||||
const fullCollectionName = joinCollectionName(dataSourceHeader, collection.name);
|
||||
const { currentUser, currentRole } = context.state;
|
||||
const { model: UserModel } = this.workflow.db.getCollection('users');
|
||||
const userInfo = {
|
||||
@ -95,8 +98,8 @@ export default class extends Trigger {
|
||||
const syncGroup = [];
|
||||
const asyncGroup = [];
|
||||
for (const workflow of triggeringLocalWorkflows.concat(...globalWorkflows.values())) {
|
||||
const { collection, appends = [] } = workflow.config;
|
||||
const [dataSourceName, collectionName] = parseCollectionName(collection);
|
||||
const { appends = [] } = workflow.config;
|
||||
const [dataSourceName, collectionName] = parseCollectionName(workflow.config.collection);
|
||||
const dataPath = triggersKeysMap.get(workflow.key);
|
||||
const event = [workflow];
|
||||
if (context.action.resourceName !== 'workflows') {
|
||||
|
@ -10,7 +10,7 @@ describe('workflow > action-trigger', () => {
|
||||
let db: Database;
|
||||
let agent;
|
||||
let PostRepo;
|
||||
let CommentRepo;
|
||||
let CategoryRepo;
|
||||
let WorkflowModel;
|
||||
let UserRepo;
|
||||
let users;
|
||||
@ -25,7 +25,7 @@ describe('workflow > action-trigger', () => {
|
||||
db = app.db;
|
||||
WorkflowModel = db.getCollection('workflows').model;
|
||||
PostRepo = db.getCollection('posts').repository;
|
||||
CommentRepo = db.getCollection('comments').repository;
|
||||
CategoryRepo = db.getCollection('categories').repository;
|
||||
UserRepo = db.getCollection('users').repository;
|
||||
|
||||
users = await UserRepo.create({
|
||||
@ -461,6 +461,33 @@ describe('workflow > action-trigger', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('associations actions', () => {
|
||||
it('trigger on associated data', async () => {
|
||||
const workflow = await WorkflowModel.create({
|
||||
enabled: true,
|
||||
type: 'action',
|
||||
config: {
|
||||
collection: 'posts',
|
||||
},
|
||||
});
|
||||
|
||||
const c1 = await CategoryRepo.create({ values: { title: 'c1' } });
|
||||
|
||||
const res1 = await userAgents[0].resource('categories.posts', c1.id).create({
|
||||
values: { title: 'p1' },
|
||||
triggerWorkflows: `${workflow.key}`,
|
||||
});
|
||||
expect(res1.status).toBe(200);
|
||||
|
||||
await sleep(500);
|
||||
|
||||
const e1s = await workflow.getExecutions();
|
||||
expect(e1s.length).toBe(1);
|
||||
expect(e1s[0].status).toBe(EXECUTION_STATUS.RESOLVED);
|
||||
expect(e1s[0].context.data).toMatchObject({ title: 'p1', categoryId: c1.id });
|
||||
});
|
||||
});
|
||||
|
||||
describe('workflow key', () => {
|
||||
it('revision', async () => {
|
||||
const w1 = await WorkflowModel.create({
|
||||
|
Loading…
Reference in New Issue
Block a user