mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 21:49:25 +08: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 },
|
params: { triggerWorkflows = '', values },
|
||||||
} = context.action;
|
} = context.action;
|
||||||
const dataSourceHeader = context.get('x-data-source') || 'main';
|
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 { currentUser, currentRole } = context.state;
|
||||||
const { model: UserModel } = this.workflow.db.getCollection('users');
|
const { model: UserModel } = this.workflow.db.getCollection('users');
|
||||||
const userInfo = {
|
const userInfo = {
|
||||||
@ -95,8 +98,8 @@ export default class extends Trigger {
|
|||||||
const syncGroup = [];
|
const syncGroup = [];
|
||||||
const asyncGroup = [];
|
const asyncGroup = [];
|
||||||
for (const workflow of triggeringLocalWorkflows.concat(...globalWorkflows.values())) {
|
for (const workflow of triggeringLocalWorkflows.concat(...globalWorkflows.values())) {
|
||||||
const { collection, appends = [] } = workflow.config;
|
const { appends = [] } = workflow.config;
|
||||||
const [dataSourceName, collectionName] = parseCollectionName(collection);
|
const [dataSourceName, collectionName] = parseCollectionName(workflow.config.collection);
|
||||||
const dataPath = triggersKeysMap.get(workflow.key);
|
const dataPath = triggersKeysMap.get(workflow.key);
|
||||||
const event = [workflow];
|
const event = [workflow];
|
||||||
if (context.action.resourceName !== 'workflows') {
|
if (context.action.resourceName !== 'workflows') {
|
||||||
|
@ -10,7 +10,7 @@ describe('workflow > action-trigger', () => {
|
|||||||
let db: Database;
|
let db: Database;
|
||||||
let agent;
|
let agent;
|
||||||
let PostRepo;
|
let PostRepo;
|
||||||
let CommentRepo;
|
let CategoryRepo;
|
||||||
let WorkflowModel;
|
let WorkflowModel;
|
||||||
let UserRepo;
|
let UserRepo;
|
||||||
let users;
|
let users;
|
||||||
@ -25,7 +25,7 @@ describe('workflow > action-trigger', () => {
|
|||||||
db = app.db;
|
db = app.db;
|
||||||
WorkflowModel = db.getCollection('workflows').model;
|
WorkflowModel = db.getCollection('workflows').model;
|
||||||
PostRepo = db.getCollection('posts').repository;
|
PostRepo = db.getCollection('posts').repository;
|
||||||
CommentRepo = db.getCollection('comments').repository;
|
CategoryRepo = db.getCollection('categories').repository;
|
||||||
UserRepo = db.getCollection('users').repository;
|
UserRepo = db.getCollection('users').repository;
|
||||||
|
|
||||||
users = await UserRepo.create({
|
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', () => {
|
describe('workflow key', () => {
|
||||||
it('revision', async () => {
|
it('revision', async () => {
|
||||||
const w1 = await WorkflowModel.create({
|
const w1 = await WorkflowModel.create({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user