@nocobase/plugin-workflow-manual 1.0.0-alpha.2 → 1.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/WorkflowTodo.d.ts +8 -0
- package/dist/client/WorkflowTodoBlockInitializer.d.ts +8 -0
- package/dist/client/index.d.ts +8 -0
- package/dist/client/index.js +9 -0
- package/dist/client/instruction/AssigneesSelect.d.ts +8 -0
- package/dist/client/instruction/FormBlockInitializer.d.ts +8 -0
- package/dist/client/instruction/FormBlockProvider.d.ts +8 -0
- package/dist/client/instruction/ModeConfig.d.ts +8 -0
- package/dist/client/instruction/SchemaConfig.d.ts +8 -0
- package/dist/client/instruction/createManualFormBlockUISchema.d.ts +8 -0
- package/dist/client/instruction/forms/create.d.ts +8 -0
- package/dist/client/instruction/forms/custom.d.ts +8 -0
- package/dist/client/instruction/forms/update.d.ts +8 -0
- package/dist/client/instruction/index.d.ts +8 -0
- package/dist/client/instruction/utils.d.ts +8 -0
- package/dist/externalVersion.js +18 -9
- package/dist/index.d.ts +8 -0
- package/dist/index.js +9 -0
- package/dist/locale/index.d.ts +8 -0
- package/dist/locale/index.js +9 -0
- package/dist/server/ManualInstruction.d.ts +8 -0
- package/dist/server/ManualInstruction.js +9 -0
- package/dist/server/Plugin.d.ts +8 -0
- package/dist/server/Plugin.js +9 -0
- package/dist/server/actions.d.ts +8 -0
- package/dist/server/actions.js +9 -0
- package/dist/server/collections/1-users_jobs.d.ts +8 -0
- package/dist/server/collections/1-users_jobs.js +9 -0
- package/dist/server/collections/2-jobs.d.ts +8 -0
- package/dist/server/collections/2-jobs.js +9 -0
- package/dist/server/collections/3-users.d.ts +8 -0
- package/dist/server/collections/3-users.js +9 -0
- package/dist/server/forms/create.d.ts +8 -0
- package/dist/server/forms/create.js +9 -0
- package/dist/server/forms/index.d.ts +8 -0
- package/dist/server/forms/index.js +9 -0
- package/dist/server/forms/update.d.ts +8 -0
- package/dist/server/forms/update.js +9 -0
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.js +9 -0
- package/dist/server/migrations/20240325213145-fix-schema.d.ts +8 -0
- package/dist/server/migrations/20240325213145-fix-schema.js +9 -0
- package/package.json +2 -2
- package/src/client/WorkflowTodo.tsx +0 -647
- package/src/client/WorkflowTodoBlockInitializer.tsx +0 -32
- package/src/client/__e2e__/assignees.test.ts +0 -0
- package/src/client/__e2e__/createRecordForm.test.ts +0 -2287
- package/src/client/__e2e__/customFormBlocks.test.ts +0 -1933
- package/src/client/__e2e__/datablocks.test.ts +0 -1208
- package/src/client/__e2e__/updateRecordForm.test.ts +0 -2338
- package/src/client/__e2e__/workflowTodo.test.ts +0 -242
- package/src/client/index.ts +0 -51
- package/src/client/instruction/AssigneesSelect.tsx +0 -39
- package/src/client/instruction/FormBlockInitializer.tsx +0 -79
- package/src/client/instruction/FormBlockProvider.tsx +0 -92
- package/src/client/instruction/ModeConfig.tsx +0 -85
- package/src/client/instruction/SchemaConfig.tsx +0 -659
- package/src/client/instruction/createManualFormBlockUISchema.ts +0 -5
- package/src/client/instruction/forms/create.tsx +0 -123
- package/src/client/instruction/forms/custom.tsx +0 -439
- package/src/client/instruction/forms/update.tsx +0 -167
- package/src/client/instruction/index.tsx +0 -160
- package/src/client/instruction/utils.ts +0 -19
- package/src/index.ts +0 -2
- package/src/locale/en-US.json +0 -30
- package/src/locale/index.ts +0 -14
- package/src/locale/ko_KR.json +0 -32
- package/src/locale/zh-CN.json +0 -32
- package/src/server/ManualInstruction.ts +0 -157
- package/src/server/Plugin.ts +0 -43
- package/src/server/__tests__/assignees.test.ts +0 -153
- package/src/server/__tests__/collections/categories.ts +0 -15
- package/src/server/__tests__/collections/comments.ts +0 -24
- package/src/server/__tests__/collections/posts.ts +0 -40
- package/src/server/__tests__/collections/replies.ts +0 -9
- package/src/server/__tests__/collections/tags.ts +0 -15
- package/src/server/__tests__/data-source.test.ts +0 -223
- package/src/server/__tests__/form.test.ts +0 -637
- package/src/server/__tests__/mode.test.ts +0 -561
- package/src/server/actions.ts +0 -103
- package/src/server/collections/1-users_jobs.ts +0 -52
- package/src/server/collections/2-jobs.ts +0 -19
- package/src/server/collections/3-users.ts +0 -17
- package/src/server/forms/create.ts +0 -30
- package/src/server/forms/index.ts +0 -13
- package/src/server/forms/update.ts +0 -30
- package/src/server/index.ts +0 -1
- package/src/server/migrations/20240325213145-fix-schema.ts +0 -82
|
@@ -1,561 +0,0 @@
|
|
|
1
|
-
import Database from '@nocobase/database';
|
|
2
|
-
import { EXECUTION_STATUS, JOB_STATUS } from '@nocobase/plugin-workflow';
|
|
3
|
-
import { getApp, sleep } from '@nocobase/plugin-workflow-test';
|
|
4
|
-
import { MockServer } from '@nocobase/test';
|
|
5
|
-
|
|
6
|
-
// NOTE: skipped because time is not stable on github ci, but should work in local
|
|
7
|
-
describe('workflow > instructions > manual', () => {
|
|
8
|
-
let app: MockServer;
|
|
9
|
-
let agent;
|
|
10
|
-
let userAgents;
|
|
11
|
-
let db: Database;
|
|
12
|
-
let PostRepo;
|
|
13
|
-
let CommentRepo;
|
|
14
|
-
let WorkflowModel;
|
|
15
|
-
let workflow;
|
|
16
|
-
let UserModel;
|
|
17
|
-
let users;
|
|
18
|
-
let UserJobModel;
|
|
19
|
-
|
|
20
|
-
beforeEach(async () => {
|
|
21
|
-
app = await getApp({
|
|
22
|
-
plugins: ['users', 'auth', 'workflow-manual'],
|
|
23
|
-
});
|
|
24
|
-
// await app.getPlugin('auth').install();
|
|
25
|
-
agent = app.agent();
|
|
26
|
-
db = app.db;
|
|
27
|
-
WorkflowModel = db.getCollection('workflows').model;
|
|
28
|
-
PostRepo = db.getCollection('posts').repository;
|
|
29
|
-
CommentRepo = db.getCollection('comments').repository;
|
|
30
|
-
UserModel = db.getCollection('users').model;
|
|
31
|
-
UserJobModel = db.getModel('users_jobs');
|
|
32
|
-
|
|
33
|
-
users = await UserModel.bulkCreate([
|
|
34
|
-
{ id: 2, nickname: 'a' },
|
|
35
|
-
{ id: 3, nickname: 'b' },
|
|
36
|
-
]);
|
|
37
|
-
|
|
38
|
-
userAgents = users.map((user) => app.agent().login(user));
|
|
39
|
-
|
|
40
|
-
workflow = await WorkflowModel.create({
|
|
41
|
-
enabled: true,
|
|
42
|
-
type: 'collection',
|
|
43
|
-
config: {
|
|
44
|
-
mode: 1,
|
|
45
|
-
collection: 'posts',
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
afterEach(() => app.destroy());
|
|
51
|
-
|
|
52
|
-
describe('mode: 0 (single record)', () => {
|
|
53
|
-
it('the only user assigned could submit', async () => {
|
|
54
|
-
const n1 = await workflow.createNode({
|
|
55
|
-
type: 'manual',
|
|
56
|
-
config: {
|
|
57
|
-
assignees: [users[0].id],
|
|
58
|
-
forms: {
|
|
59
|
-
f1: {
|
|
60
|
-
actions: [{ status: JOB_STATUS.RESOLVED, key: 'resolve' }],
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
67
|
-
|
|
68
|
-
await sleep(500);
|
|
69
|
-
|
|
70
|
-
const [pending] = await workflow.getExecutions();
|
|
71
|
-
expect(pending.status).toBe(EXECUTION_STATUS.STARTED);
|
|
72
|
-
const [j1] = await pending.getJobs();
|
|
73
|
-
expect(j1.status).toBe(JOB_STATUS.PENDING);
|
|
74
|
-
|
|
75
|
-
const usersJobs = await UserJobModel.findAll();
|
|
76
|
-
expect(usersJobs.length).toBe(1);
|
|
77
|
-
expect(usersJobs[0].status).toBe(JOB_STATUS.PENDING);
|
|
78
|
-
expect(usersJobs[0].userId).toBe(users[0].id);
|
|
79
|
-
expect(usersJobs[0].jobId).toBe(j1.id);
|
|
80
|
-
|
|
81
|
-
const res1 = await agent.resource('users_jobs').submit({
|
|
82
|
-
filterByTk: usersJobs[0].id,
|
|
83
|
-
values: { result: { f1: {}, _: 'resolve' } },
|
|
84
|
-
});
|
|
85
|
-
expect(res1.status).toBe(401);
|
|
86
|
-
|
|
87
|
-
const res2 = await userAgents[1].resource('users_jobs').submit({
|
|
88
|
-
filterByTk: usersJobs[0].id,
|
|
89
|
-
values: {
|
|
90
|
-
result: { f1: {}, _: 'resolve' },
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
expect(res2.status).toBe(403);
|
|
94
|
-
|
|
95
|
-
const res3 = await userAgents[0].resource('users_jobs').submit({
|
|
96
|
-
filterByTk: usersJobs[0].id,
|
|
97
|
-
values: {
|
|
98
|
-
result: { f1: { a: 1 }, _: 'resolve' },
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
expect(res3.status).toBe(202);
|
|
102
|
-
|
|
103
|
-
await sleep(1000);
|
|
104
|
-
|
|
105
|
-
const [j2] = await pending.getJobs();
|
|
106
|
-
expect(j2.status).toBe(JOB_STATUS.RESOLVED);
|
|
107
|
-
expect(j2.result).toEqual({ f1: { a: 1 }, _: 'resolve' });
|
|
108
|
-
|
|
109
|
-
const usersJobsAfter = await UserJobModel.findAll();
|
|
110
|
-
expect(usersJobsAfter.length).toBe(1);
|
|
111
|
-
expect(usersJobsAfter[0].status).toBe(JOB_STATUS.RESOLVED);
|
|
112
|
-
expect(usersJobsAfter[0].result).toEqual({ f1: { a: 1 }, _: 'resolve' });
|
|
113
|
-
|
|
114
|
-
const res4 = await userAgents[0].resource('users_jobs').submit({
|
|
115
|
-
filterByTk: usersJobs[0].id,
|
|
116
|
-
values: {
|
|
117
|
-
result: { f1: { a: 2 }, _: 'resolve' },
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
expect(res4.status).toBe(400);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('any user assigned could submit', async () => {
|
|
124
|
-
const n1 = await workflow.createNode({
|
|
125
|
-
type: 'manual',
|
|
126
|
-
config: {
|
|
127
|
-
assignees: [users[0].id, users[1].id],
|
|
128
|
-
forms: {
|
|
129
|
-
f1: {
|
|
130
|
-
actions: [{ status: JOB_STATUS.RESOLVED, key: 'resolve' }],
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
137
|
-
|
|
138
|
-
await sleep(500);
|
|
139
|
-
|
|
140
|
-
const [pending] = await workflow.getExecutions();
|
|
141
|
-
expect(pending.status).toBe(EXECUTION_STATUS.STARTED);
|
|
142
|
-
const [j1] = await pending.getJobs();
|
|
143
|
-
expect(j1.status).toBe(JOB_STATUS.PENDING);
|
|
144
|
-
|
|
145
|
-
const usersJobs = await j1.getUsersJobs();
|
|
146
|
-
|
|
147
|
-
const res1 = await userAgents[1].resource('users_jobs').submit({
|
|
148
|
-
filterByTk: usersJobs.find((item) => item.userId === users[1].id).id,
|
|
149
|
-
values: {
|
|
150
|
-
result: { f1: { a: 1 }, _: 'resolve' },
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
expect(res1.status).toBe(202);
|
|
154
|
-
|
|
155
|
-
await sleep(1000);
|
|
156
|
-
|
|
157
|
-
const [j2] = await pending.getJobs();
|
|
158
|
-
expect(j2.status).toBe(JOB_STATUS.RESOLVED);
|
|
159
|
-
expect(j2.result).toEqual({ f1: { a: 1 }, _: 'resolve' });
|
|
160
|
-
|
|
161
|
-
const res2 = await userAgents[0].resource('users_jobs').submit({
|
|
162
|
-
filterByTk: usersJobs.find((item) => item.userId === users[0].id).id,
|
|
163
|
-
values: {
|
|
164
|
-
result: { f1: { a: 1 }, _: 'resolve' },
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
expect(res2.status).toBe(400);
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('also could submit to users_jobs api', async () => {
|
|
171
|
-
const n1 = await workflow.createNode({
|
|
172
|
-
type: 'manual',
|
|
173
|
-
config: {
|
|
174
|
-
assignees: [users[0].id],
|
|
175
|
-
forms: {
|
|
176
|
-
f1: {
|
|
177
|
-
actions: [{ status: JOB_STATUS.RESOLVED, key: 'resolve' }],
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
184
|
-
|
|
185
|
-
await sleep(500);
|
|
186
|
-
|
|
187
|
-
const UserJobModel = db.getModel('users_jobs');
|
|
188
|
-
const usersJobs = await UserJobModel.findAll();
|
|
189
|
-
expect(usersJobs.length).toBe(1);
|
|
190
|
-
expect(usersJobs[0].get('status')).toBe(JOB_STATUS.PENDING);
|
|
191
|
-
expect(usersJobs[0].get('userId')).toBe(users[0].id);
|
|
192
|
-
|
|
193
|
-
const res = await userAgents[0].resource('users_jobs').submit({
|
|
194
|
-
filterByTk: usersJobs[0].get('id'),
|
|
195
|
-
values: {
|
|
196
|
-
result: { f1: { a: 1 }, _: 'resolve' },
|
|
197
|
-
},
|
|
198
|
-
});
|
|
199
|
-
expect(res.status).toBe(202);
|
|
200
|
-
|
|
201
|
-
await sleep(1000);
|
|
202
|
-
|
|
203
|
-
const [execution] = await workflow.getExecutions();
|
|
204
|
-
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
205
|
-
const [job] = await execution.getJobs();
|
|
206
|
-
expect(job.status).toBe(JOB_STATUS.RESOLVED);
|
|
207
|
-
expect(job.result).toEqual({ f1: { a: 1 }, _: 'resolve' });
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
describe('mode: 1 (multiple record, all)', () => {
|
|
212
|
-
it('all resolved', async () => {
|
|
213
|
-
const n1 = await workflow.createNode({
|
|
214
|
-
type: 'manual',
|
|
215
|
-
config: {
|
|
216
|
-
assignees: [users[0].id, users[1].id],
|
|
217
|
-
mode: 1,
|
|
218
|
-
forms: {
|
|
219
|
-
f1: {
|
|
220
|
-
actions: [{ status: JOB_STATUS.RESOLVED, key: 'resolve' }],
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
},
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
227
|
-
|
|
228
|
-
await sleep(500);
|
|
229
|
-
|
|
230
|
-
const UserJobModel = db.getModel('users_jobs');
|
|
231
|
-
const pendingJobs = await UserJobModel.findAll({
|
|
232
|
-
order: [['userId', 'ASC']],
|
|
233
|
-
});
|
|
234
|
-
expect(pendingJobs.length).toBe(2);
|
|
235
|
-
|
|
236
|
-
const res1 = await userAgents[0].resource('users_jobs').submit({
|
|
237
|
-
filterByTk: pendingJobs[0].get('id'),
|
|
238
|
-
values: {
|
|
239
|
-
result: { f1: { a: 1 }, _: 'resolve' },
|
|
240
|
-
},
|
|
241
|
-
});
|
|
242
|
-
expect(res1.status).toBe(202);
|
|
243
|
-
|
|
244
|
-
await sleep(1000);
|
|
245
|
-
|
|
246
|
-
const [e1] = await workflow.getExecutions();
|
|
247
|
-
expect(e1.status).toBe(EXECUTION_STATUS.STARTED);
|
|
248
|
-
const [j1] = await e1.getJobs();
|
|
249
|
-
expect(j1.status).toBe(JOB_STATUS.PENDING);
|
|
250
|
-
expect(j1.result).toBe(0.5);
|
|
251
|
-
const usersJobs1 = await UserJobModel.findAll({
|
|
252
|
-
order: [['userId', 'ASC']],
|
|
253
|
-
});
|
|
254
|
-
expect(usersJobs1.length).toBe(2);
|
|
255
|
-
|
|
256
|
-
const res2 = await userAgents[1].resource('users_jobs').submit({
|
|
257
|
-
filterByTk: pendingJobs[1].get('id'),
|
|
258
|
-
values: {
|
|
259
|
-
result: { f1: { a: 2 }, _: 'resolve' },
|
|
260
|
-
},
|
|
261
|
-
});
|
|
262
|
-
expect(res2.status).toBe(202);
|
|
263
|
-
|
|
264
|
-
await sleep(1000);
|
|
265
|
-
|
|
266
|
-
const [e2] = await workflow.getExecutions();
|
|
267
|
-
expect(e2.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
268
|
-
const [j2] = await e2.getJobs();
|
|
269
|
-
expect(j2.status).toBe(JOB_STATUS.RESOLVED);
|
|
270
|
-
expect(j2.result).toBe(1);
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
it('first rejected', async () => {
|
|
274
|
-
const n1 = await workflow.createNode({
|
|
275
|
-
type: 'manual',
|
|
276
|
-
config: {
|
|
277
|
-
assignees: [users[0].id, users[1].id],
|
|
278
|
-
mode: 1,
|
|
279
|
-
forms: {
|
|
280
|
-
f1: {
|
|
281
|
-
actions: [{ status: JOB_STATUS.REJECTED, key: 'reject' }],
|
|
282
|
-
},
|
|
283
|
-
},
|
|
284
|
-
},
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
288
|
-
|
|
289
|
-
await sleep(500);
|
|
290
|
-
|
|
291
|
-
const UserJobModel = db.getModel('users_jobs');
|
|
292
|
-
const pendingJobs = await UserJobModel.findAll({
|
|
293
|
-
order: [['userId', 'ASC']],
|
|
294
|
-
});
|
|
295
|
-
expect(pendingJobs.length).toBe(2);
|
|
296
|
-
|
|
297
|
-
const res1 = await userAgents[0].resource('users_jobs').submit({
|
|
298
|
-
filterByTk: pendingJobs[0].get('id'),
|
|
299
|
-
values: {
|
|
300
|
-
result: { f1: { a: 0 }, _: 'reject' },
|
|
301
|
-
},
|
|
302
|
-
});
|
|
303
|
-
expect(res1.status).toBe(202);
|
|
304
|
-
|
|
305
|
-
await sleep(1000);
|
|
306
|
-
|
|
307
|
-
const [e1] = await workflow.getExecutions();
|
|
308
|
-
expect(e1.status).toBe(EXECUTION_STATUS.REJECTED);
|
|
309
|
-
const [j1] = await e1.getJobs();
|
|
310
|
-
expect(j1.status).toBe(JOB_STATUS.REJECTED);
|
|
311
|
-
expect(j1.result).toBe(0.5);
|
|
312
|
-
const usersJobs1 = await UserJobModel.findAll({
|
|
313
|
-
order: [['userId', 'ASC']],
|
|
314
|
-
});
|
|
315
|
-
expect(usersJobs1.length).toBe(2);
|
|
316
|
-
|
|
317
|
-
const res2 = await userAgents[1].resource('users_jobs').submit({
|
|
318
|
-
filterByTk: pendingJobs[1].get('id'),
|
|
319
|
-
values: {
|
|
320
|
-
result: { f1: { a: 0 }, _: 'reject' },
|
|
321
|
-
},
|
|
322
|
-
});
|
|
323
|
-
expect(res2.status).toBe(400);
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
it('last rejected', async () => {
|
|
327
|
-
const n1 = await workflow.createNode({
|
|
328
|
-
type: 'manual',
|
|
329
|
-
config: {
|
|
330
|
-
assignees: [users[0].id, users[1].id],
|
|
331
|
-
mode: 1,
|
|
332
|
-
forms: {
|
|
333
|
-
f1: {
|
|
334
|
-
actions: [
|
|
335
|
-
{ status: JOB_STATUS.RESOLVED, key: 'resolve' },
|
|
336
|
-
{ status: JOB_STATUS.REJECTED, key: 'reject' },
|
|
337
|
-
],
|
|
338
|
-
},
|
|
339
|
-
},
|
|
340
|
-
},
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
344
|
-
|
|
345
|
-
await sleep(500);
|
|
346
|
-
|
|
347
|
-
const UserJobModel = db.getModel('users_jobs');
|
|
348
|
-
const pendingJobs = await UserJobModel.findAll({
|
|
349
|
-
order: [['userId', 'ASC']],
|
|
350
|
-
});
|
|
351
|
-
expect(pendingJobs.length).toBe(2);
|
|
352
|
-
|
|
353
|
-
const res1 = await userAgents[0].resource('users_jobs').submit({
|
|
354
|
-
filterByTk: pendingJobs[0].get('id'),
|
|
355
|
-
values: {
|
|
356
|
-
result: { f1: { a: 1 }, _: 'resolve' },
|
|
357
|
-
},
|
|
358
|
-
});
|
|
359
|
-
expect(res1.status).toBe(202);
|
|
360
|
-
|
|
361
|
-
await sleep(1000);
|
|
362
|
-
|
|
363
|
-
const [e1] = await workflow.getExecutions();
|
|
364
|
-
expect(e1.status).toBe(EXECUTION_STATUS.STARTED);
|
|
365
|
-
const [j1] = await e1.getJobs();
|
|
366
|
-
expect(j1.status).toBe(JOB_STATUS.PENDING);
|
|
367
|
-
expect(j1.result).toBe(0.5);
|
|
368
|
-
const usersJobs1 = await UserJobModel.findAll({
|
|
369
|
-
order: [['userId', 'ASC']],
|
|
370
|
-
});
|
|
371
|
-
expect(usersJobs1.length).toBe(2);
|
|
372
|
-
|
|
373
|
-
const res2 = await userAgents[1].resource('users_jobs').submit({
|
|
374
|
-
filterByTk: pendingJobs[1].get('id'),
|
|
375
|
-
values: {
|
|
376
|
-
result: { f1: { a: 0 }, _: 'reject' },
|
|
377
|
-
},
|
|
378
|
-
});
|
|
379
|
-
expect(res2.status).toBe(202);
|
|
380
|
-
|
|
381
|
-
await sleep(1000);
|
|
382
|
-
|
|
383
|
-
const [e2] = await workflow.getExecutions();
|
|
384
|
-
expect(e2.status).toBe(EXECUTION_STATUS.REJECTED);
|
|
385
|
-
const [j2] = await e2.getJobs();
|
|
386
|
-
expect(j2.status).toBe(JOB_STATUS.REJECTED);
|
|
387
|
-
expect(j2.result).toBe(1);
|
|
388
|
-
});
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
describe('mode: -1 (multiple record, any)', () => {
|
|
392
|
-
it('first resolved', async () => {
|
|
393
|
-
const n1 = await workflow.createNode({
|
|
394
|
-
type: 'manual',
|
|
395
|
-
config: {
|
|
396
|
-
assignees: [users[0].id, users[1].id],
|
|
397
|
-
mode: -1,
|
|
398
|
-
forms: {
|
|
399
|
-
f1: {
|
|
400
|
-
actions: [
|
|
401
|
-
{ status: JOB_STATUS.RESOLVED, key: 'resolve' },
|
|
402
|
-
{ status: JOB_STATUS.REJECTED, key: 'reject' },
|
|
403
|
-
],
|
|
404
|
-
},
|
|
405
|
-
},
|
|
406
|
-
},
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
410
|
-
|
|
411
|
-
await sleep(500);
|
|
412
|
-
|
|
413
|
-
const UserJobModel = db.getModel('users_jobs');
|
|
414
|
-
const pendingJobs = await UserJobModel.findAll({
|
|
415
|
-
order: [['userId', 'ASC']],
|
|
416
|
-
});
|
|
417
|
-
expect(pendingJobs.length).toBe(2);
|
|
418
|
-
|
|
419
|
-
const res1 = await userAgents[0].resource('users_jobs').submit({
|
|
420
|
-
filterByTk: pendingJobs[0].get('id'),
|
|
421
|
-
values: {
|
|
422
|
-
result: { f1: { a: 1 }, _: 'resolve' },
|
|
423
|
-
},
|
|
424
|
-
});
|
|
425
|
-
expect(res1.status).toBe(202);
|
|
426
|
-
|
|
427
|
-
await sleep(1000);
|
|
428
|
-
|
|
429
|
-
const [e1] = await workflow.getExecutions();
|
|
430
|
-
expect(e1.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
431
|
-
const [j1] = await e1.getJobs();
|
|
432
|
-
expect(j1.status).toBe(JOB_STATUS.RESOLVED);
|
|
433
|
-
expect(j1.result).toBe(0.5);
|
|
434
|
-
|
|
435
|
-
const res2 = await userAgents[1].resource('users_jobs').submit({
|
|
436
|
-
filterByTk: pendingJobs[1].get('id'),
|
|
437
|
-
values: {
|
|
438
|
-
result: { f1: { a: 0 }, _: 'reject' },
|
|
439
|
-
},
|
|
440
|
-
});
|
|
441
|
-
expect(res2.status).toBe(400);
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
it('any resolved', async () => {
|
|
445
|
-
const n1 = await workflow.createNode({
|
|
446
|
-
type: 'manual',
|
|
447
|
-
config: {
|
|
448
|
-
assignees: [users[0].id, users[1].id],
|
|
449
|
-
mode: -1,
|
|
450
|
-
forms: {
|
|
451
|
-
f1: {
|
|
452
|
-
actions: [
|
|
453
|
-
{ status: JOB_STATUS.RESOLVED, key: 'resolve' },
|
|
454
|
-
{ status: JOB_STATUS.REJECTED, key: 'reject' },
|
|
455
|
-
],
|
|
456
|
-
},
|
|
457
|
-
},
|
|
458
|
-
},
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
462
|
-
|
|
463
|
-
await sleep(500);
|
|
464
|
-
|
|
465
|
-
const UserJobModel = db.getModel('users_jobs');
|
|
466
|
-
const pendingJobs = await UserJobModel.findAll({
|
|
467
|
-
order: [['userId', 'ASC']],
|
|
468
|
-
});
|
|
469
|
-
expect(pendingJobs.length).toBe(2);
|
|
470
|
-
|
|
471
|
-
const res1 = await userAgents[0].resource('users_jobs').submit({
|
|
472
|
-
filterByTk: pendingJobs[0].get('id'),
|
|
473
|
-
values: {
|
|
474
|
-
result: { f1: { a: 0 }, _: 'reject' },
|
|
475
|
-
},
|
|
476
|
-
});
|
|
477
|
-
expect(res1.status).toBe(202);
|
|
478
|
-
|
|
479
|
-
await sleep(1000);
|
|
480
|
-
|
|
481
|
-
const [e1] = await workflow.getExecutions();
|
|
482
|
-
expect(e1.status).toBe(EXECUTION_STATUS.STARTED);
|
|
483
|
-
const [j1] = await e1.getJobs();
|
|
484
|
-
expect(j1.status).toBe(JOB_STATUS.PENDING);
|
|
485
|
-
expect(j1.result).toBe(0.5);
|
|
486
|
-
|
|
487
|
-
const res2 = await userAgents[1].resource('users_jobs').submit({
|
|
488
|
-
filterByTk: pendingJobs[1].get('id'),
|
|
489
|
-
values: {
|
|
490
|
-
result: { f1: { a: 1 }, _: 'resolve' },
|
|
491
|
-
},
|
|
492
|
-
});
|
|
493
|
-
expect(res2.status).toBe(202);
|
|
494
|
-
|
|
495
|
-
await sleep(1000);
|
|
496
|
-
|
|
497
|
-
const [e2] = await workflow.getExecutions();
|
|
498
|
-
expect(e2.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
499
|
-
const [j2] = await e2.getJobs();
|
|
500
|
-
expect(j2.status).toBe(JOB_STATUS.RESOLVED);
|
|
501
|
-
expect(j2.result).toBe(1);
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
it('all rejected', async () => {
|
|
505
|
-
const n1 = await workflow.createNode({
|
|
506
|
-
type: 'manual',
|
|
507
|
-
config: {
|
|
508
|
-
assignees: [users[0].id, users[1].id],
|
|
509
|
-
mode: -1,
|
|
510
|
-
forms: {
|
|
511
|
-
f1: {
|
|
512
|
-
actions: [{ status: JOB_STATUS.REJECTED, key: 'reject' }],
|
|
513
|
-
},
|
|
514
|
-
},
|
|
515
|
-
},
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
519
|
-
|
|
520
|
-
await sleep(500);
|
|
521
|
-
|
|
522
|
-
const UserJobModel = db.getModel('users_jobs');
|
|
523
|
-
const pendingJobs = await UserJobModel.findAll({
|
|
524
|
-
order: [['userId', 'ASC']],
|
|
525
|
-
});
|
|
526
|
-
expect(pendingJobs.length).toBe(2);
|
|
527
|
-
|
|
528
|
-
const res1 = await userAgents[0].resource('users_jobs').submit({
|
|
529
|
-
filterByTk: pendingJobs[0].get('id'),
|
|
530
|
-
values: {
|
|
531
|
-
result: { f1: { a: 0 }, _: 'reject' },
|
|
532
|
-
},
|
|
533
|
-
});
|
|
534
|
-
expect(res1.status).toBe(202);
|
|
535
|
-
|
|
536
|
-
await sleep(1000);
|
|
537
|
-
|
|
538
|
-
const [e1] = await workflow.getExecutions();
|
|
539
|
-
expect(e1.status).toBe(EXECUTION_STATUS.STARTED);
|
|
540
|
-
const [j1] = await e1.getJobs();
|
|
541
|
-
expect(j1.status).toBe(JOB_STATUS.PENDING);
|
|
542
|
-
expect(j1.result).toBe(0.5);
|
|
543
|
-
|
|
544
|
-
const res2 = await userAgents[1].resource('users_jobs').submit({
|
|
545
|
-
filterByTk: pendingJobs[1].get('id'),
|
|
546
|
-
values: {
|
|
547
|
-
result: { f1: { a: 0 }, _: 'reject' },
|
|
548
|
-
},
|
|
549
|
-
});
|
|
550
|
-
expect(res2.status).toBe(202);
|
|
551
|
-
|
|
552
|
-
await sleep(1000);
|
|
553
|
-
|
|
554
|
-
const [e2] = await workflow.getExecutions();
|
|
555
|
-
expect(e2.status).toBe(EXECUTION_STATUS.REJECTED);
|
|
556
|
-
const [j2] = await e2.getJobs();
|
|
557
|
-
expect(j2.status).toBe(JOB_STATUS.REJECTED);
|
|
558
|
-
expect(j2.result).toBe(1);
|
|
559
|
-
});
|
|
560
|
-
});
|
|
561
|
-
});
|
package/src/server/actions.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { Context, utils } from '@nocobase/actions';
|
|
2
|
-
import WorkflowPlugin, { EXECUTION_STATUS, JOB_STATUS } from '@nocobase/plugin-workflow';
|
|
3
|
-
|
|
4
|
-
import ManualInstruction from './ManualInstruction';
|
|
5
|
-
|
|
6
|
-
export async function submit(context: Context, next) {
|
|
7
|
-
const repository = utils.getRepositoryFromParams(context);
|
|
8
|
-
const { filterByTk, values } = context.action.params;
|
|
9
|
-
const { currentUser } = context.state;
|
|
10
|
-
|
|
11
|
-
if (!currentUser) {
|
|
12
|
-
return context.throw(401);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const plugin: WorkflowPlugin = context.app.getPlugin(WorkflowPlugin);
|
|
16
|
-
const instruction = plugin.instructions.get('manual') as ManualInstruction;
|
|
17
|
-
|
|
18
|
-
const userJob = await repository.findOne({
|
|
19
|
-
filterByTk,
|
|
20
|
-
// filter: {
|
|
21
|
-
// userId: currentUser?.id
|
|
22
|
-
// },
|
|
23
|
-
appends: ['job', 'node', 'execution', 'workflow'],
|
|
24
|
-
context,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
if (!userJob) {
|
|
28
|
-
return context.throw(404);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const { forms = {} } = userJob.node.config;
|
|
32
|
-
const [formKey] = Object.keys(values.result ?? {}).filter((key) => key !== '_');
|
|
33
|
-
const actionKey = values.result?._;
|
|
34
|
-
|
|
35
|
-
const actionItem = forms[formKey]?.actions?.find((item) => item.key === actionKey);
|
|
36
|
-
// NOTE: validate status
|
|
37
|
-
if (
|
|
38
|
-
userJob.status !== JOB_STATUS.PENDING ||
|
|
39
|
-
userJob.job.status !== JOB_STATUS.PENDING ||
|
|
40
|
-
userJob.execution.status !== EXECUTION_STATUS.STARTED ||
|
|
41
|
-
!userJob.workflow.enabled ||
|
|
42
|
-
!actionKey ||
|
|
43
|
-
actionItem?.status == null
|
|
44
|
-
) {
|
|
45
|
-
return context.throw(400);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
userJob.execution.workflow = userJob.workflow;
|
|
49
|
-
const processor = plugin.createProcessor(userJob.execution);
|
|
50
|
-
await processor.prepare();
|
|
51
|
-
|
|
52
|
-
// NOTE: validate assignee
|
|
53
|
-
const assignees = processor
|
|
54
|
-
.getParsedValue(userJob.node.config.assignees ?? [], userJob.nodeId)
|
|
55
|
-
.flat()
|
|
56
|
-
.filter(Boolean);
|
|
57
|
-
if (!assignees.includes(currentUser.id) || userJob.userId !== currentUser.id) {
|
|
58
|
-
return context.throw(403);
|
|
59
|
-
}
|
|
60
|
-
const presetValues = processor.getParsedValue(actionItem.values ?? {}, userJob.nodeId, {
|
|
61
|
-
// @deprecated
|
|
62
|
-
currentUser: currentUser,
|
|
63
|
-
// @deprecated
|
|
64
|
-
currentRecord: values.result[formKey],
|
|
65
|
-
// @deprecated
|
|
66
|
-
currentTime: new Date(),
|
|
67
|
-
$user: currentUser,
|
|
68
|
-
$nForm: values.result[formKey],
|
|
69
|
-
$nDate: {
|
|
70
|
-
now: new Date(),
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
userJob.set({
|
|
75
|
-
status: actionItem.status,
|
|
76
|
-
result:
|
|
77
|
-
actionItem.status > JOB_STATUS.PENDING
|
|
78
|
-
? { [formKey]: Object.assign(values.result[formKey], presetValues), _: actionKey }
|
|
79
|
-
: Object.assign(userJob.result ?? {}, values.result),
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
const handler = instruction.formTypes.get(forms[formKey].type);
|
|
83
|
-
if (handler && userJob.status) {
|
|
84
|
-
await handler.call(instruction, userJob, forms[formKey], processor);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
await userJob.save();
|
|
88
|
-
|
|
89
|
-
await processor.exit();
|
|
90
|
-
|
|
91
|
-
context.body = userJob;
|
|
92
|
-
context.status = 202;
|
|
93
|
-
|
|
94
|
-
await next();
|
|
95
|
-
|
|
96
|
-
userJob.job.execution = userJob.execution;
|
|
97
|
-
userJob.job.latestUserJob = userJob;
|
|
98
|
-
|
|
99
|
-
// NOTE: resume the process and no `await` for quick returning
|
|
100
|
-
processor.logger.info(`manual node (${userJob.nodeId}) action trigger execution (${userJob.execution.id}) to resume`);
|
|
101
|
-
|
|
102
|
-
plugin.resume(userJob.job);
|
|
103
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { defineCollection } from '@nocobase/database';
|
|
2
|
-
|
|
3
|
-
export default defineCollection({
|
|
4
|
-
name: 'users_jobs',
|
|
5
|
-
dumpRules: {
|
|
6
|
-
group: 'log',
|
|
7
|
-
},
|
|
8
|
-
shared: true,
|
|
9
|
-
fields: [
|
|
10
|
-
{
|
|
11
|
-
type: 'bigInt',
|
|
12
|
-
name: 'id',
|
|
13
|
-
primaryKey: true,
|
|
14
|
-
autoIncrement: true,
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
type: 'belongsTo',
|
|
18
|
-
name: 'job',
|
|
19
|
-
target: 'jobs',
|
|
20
|
-
foreignKey: 'jobId',
|
|
21
|
-
primaryKey: false,
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
type: 'belongsTo',
|
|
25
|
-
name: 'user',
|
|
26
|
-
target: 'users',
|
|
27
|
-
foreignKey: 'userId',
|
|
28
|
-
primaryKey: false,
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
type: 'belongsTo',
|
|
32
|
-
name: 'execution',
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
type: 'belongsTo',
|
|
36
|
-
name: 'node',
|
|
37
|
-
target: 'flow_nodes',
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
type: 'belongsTo',
|
|
41
|
-
name: 'workflow',
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
type: 'integer',
|
|
45
|
-
name: 'status',
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
type: 'jsonb',
|
|
49
|
-
name: 'result',
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
});
|