@nocobase/plugin-workflow-manual 0.21.0-alpha.14 → 0.21.0-alpha.16
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/externalVersion.js
CHANGED
|
@@ -3,18 +3,18 @@ module.exports = {
|
|
|
3
3
|
"antd": "5.12.8",
|
|
4
4
|
"dayjs": "1.11.10",
|
|
5
5
|
"react": "18.2.0",
|
|
6
|
-
"@nocobase/client": "0.21.0-alpha.
|
|
7
|
-
"@nocobase/plugin-workflow": "0.21.0-alpha.
|
|
6
|
+
"@nocobase/client": "0.21.0-alpha.16",
|
|
7
|
+
"@nocobase/plugin-workflow": "0.21.0-alpha.16",
|
|
8
8
|
"@ant-design/icons": "5.2.6",
|
|
9
9
|
"react-i18next": "11.18.6",
|
|
10
|
-
"@nocobase/utils": "0.21.0-alpha.
|
|
11
|
-
"@nocobase/server": "0.21.0-alpha.
|
|
12
|
-
"@nocobase/actions": "0.21.0-alpha.
|
|
13
|
-
"@nocobase/resourcer": "0.21.0-alpha.
|
|
14
|
-
"@nocobase/plugin-workflow-test": "0.21.0-alpha.
|
|
15
|
-
"@nocobase/test": "0.21.0-alpha.
|
|
10
|
+
"@nocobase/utils": "0.21.0-alpha.16",
|
|
11
|
+
"@nocobase/server": "0.21.0-alpha.16",
|
|
12
|
+
"@nocobase/actions": "0.21.0-alpha.16",
|
|
13
|
+
"@nocobase/resourcer": "0.21.0-alpha.16",
|
|
14
|
+
"@nocobase/plugin-workflow-test": "0.21.0-alpha.16",
|
|
15
|
+
"@nocobase/test": "0.21.0-alpha.16",
|
|
16
16
|
"@formily/core": "2.3.0",
|
|
17
17
|
"@formily/antd-v5": "1.1.9",
|
|
18
|
-
"@nocobase/database": "0.21.0-alpha.
|
|
18
|
+
"@nocobase/database": "0.21.0-alpha.16",
|
|
19
19
|
"lodash": "4.17.21"
|
|
20
20
|
};
|
|
@@ -100,14 +100,17 @@ class ManualInstruction_default extends import_plugin_workflow.Instruction {
|
|
|
100
100
|
formTypes = new import_utils.Registry();
|
|
101
101
|
async run(node, prevJob, processor) {
|
|
102
102
|
const { mode, ...config } = node.config;
|
|
103
|
-
const assignees = [...new Set(processor.getParsedValue(config.assignees, node.id)
|
|
103
|
+
const assignees = [...new Set(processor.getParsedValue(config.assignees, node.id).flat().filter(Boolean))];
|
|
104
104
|
const job = await processor.saveJob({
|
|
105
|
-
status: import_plugin_workflow.JOB_STATUS.PENDING,
|
|
105
|
+
status: assignees.length ? import_plugin_workflow.JOB_STATUS.PENDING : import_plugin_workflow.JOB_STATUS.RESOLVED,
|
|
106
106
|
result: mode ? [] : null,
|
|
107
107
|
nodeId: node.id,
|
|
108
108
|
nodeKey: node.key,
|
|
109
109
|
upstreamId: (prevJob == null ? void 0 : prevJob.id) ?? null
|
|
110
110
|
});
|
|
111
|
+
if (!assignees.length) {
|
|
112
|
+
return job;
|
|
113
|
+
}
|
|
111
114
|
const UserJobModel = this.workflow.app.db.getModel("users_jobs");
|
|
112
115
|
await UserJobModel.bulkCreate(
|
|
113
116
|
assignees.map((userId) => ({
|
|
@@ -126,7 +129,8 @@ class ManualInstruction_default extends import_plugin_workflow.Instruction {
|
|
|
126
129
|
}
|
|
127
130
|
async resume(node, job, processor) {
|
|
128
131
|
var _a;
|
|
129
|
-
const {
|
|
132
|
+
const { mode } = node.config;
|
|
133
|
+
const assignees = [...new Set(processor.getParsedValue(node.config.assignees, node.id).flat().filter(Boolean))];
|
|
130
134
|
const UserJobModel = this.workflow.app.db.getModel("users_jobs");
|
|
131
135
|
const distribution = await UserJobModel.count({
|
|
132
136
|
where: {
|
package/dist/server/actions.js
CHANGED
|
@@ -63,7 +63,7 @@ async function submit(context, next) {
|
|
|
63
63
|
userJob.execution.workflow = userJob.workflow;
|
|
64
64
|
const processor = plugin.createProcessor(userJob.execution);
|
|
65
65
|
await processor.prepare();
|
|
66
|
-
const assignees = processor.getParsedValue(userJob.node.config.assignees ?? [], userJob.nodeId);
|
|
66
|
+
const assignees = processor.getParsedValue(userJob.node.config.assignees ?? [], userJob.nodeId).flat().filter(Boolean);
|
|
67
67
|
if (!assignees.includes(currentUser.id) || userJob.userId !== currentUser.id) {
|
|
68
68
|
return context.throw(403);
|
|
69
69
|
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"displayName.zh-CN": "工作流:人工处理节点",
|
|
5
5
|
"description": "Could be used for workflows which some of decisions are made by users.",
|
|
6
6
|
"description.zh-CN": "用于人工控制部分决策的流程。",
|
|
7
|
-
"version": "0.21.0-alpha.
|
|
7
|
+
"version": "0.21.0-alpha.16",
|
|
8
8
|
"license": "AGPL-3.0",
|
|
9
9
|
"main": "./dist/server/index.js",
|
|
10
10
|
"homepage": "https://docs.nocobase.com/handbook/workflow-manual",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@nocobase/test": "0.x",
|
|
31
31
|
"@nocobase/utils": "0.x"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "2914500f14e4454cc5702a49371230865660ca33",
|
|
34
34
|
"keywords": [
|
|
35
35
|
"Workflow"
|
|
36
36
|
]
|
|
@@ -93,16 +93,20 @@ export default class extends Instruction {
|
|
|
93
93
|
|
|
94
94
|
async run(node, prevJob, processor: Processor) {
|
|
95
95
|
const { mode, ...config } = node.config as ManualConfig;
|
|
96
|
-
const assignees = [...new Set(processor.getParsedValue(config.assignees, node.id)
|
|
96
|
+
const assignees = [...new Set(processor.getParsedValue(config.assignees, node.id).flat().filter(Boolean))];
|
|
97
97
|
|
|
98
98
|
const job = await processor.saveJob({
|
|
99
|
-
status: JOB_STATUS.PENDING,
|
|
99
|
+
status: assignees.length ? JOB_STATUS.PENDING : JOB_STATUS.RESOLVED,
|
|
100
100
|
result: mode ? [] : null,
|
|
101
101
|
nodeId: node.id,
|
|
102
102
|
nodeKey: node.key,
|
|
103
103
|
upstreamId: prevJob?.id ?? null,
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
+
if (!assignees.length) {
|
|
107
|
+
return job;
|
|
108
|
+
}
|
|
109
|
+
|
|
106
110
|
// NOTE: batch create users jobs
|
|
107
111
|
const UserJobModel = this.workflow.app.db.getModel('users_jobs');
|
|
108
112
|
await UserJobModel.bulkCreate(
|
|
@@ -124,7 +128,8 @@ export default class extends Instruction {
|
|
|
124
128
|
|
|
125
129
|
async resume(node, job, processor: Processor) {
|
|
126
130
|
// NOTE: check all users jobs related if all done then continue as parallel
|
|
127
|
-
const {
|
|
131
|
+
const { mode } = node.config as ManualConfig;
|
|
132
|
+
const assignees = [...new Set(processor.getParsedValue(node.config.assignees, node.id).flat().filter(Boolean))];
|
|
128
133
|
|
|
129
134
|
const UserJobModel = this.workflow.app.db.getModel('users_jobs');
|
|
130
135
|
const distribution = await UserJobModel.count({
|
|
@@ -0,0 +1,153 @@
|
|
|
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 > assignees', () => {
|
|
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
|
+
appends: ['category', 'category.posts'],
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
afterEach(() => app.destroy());
|
|
52
|
+
|
|
53
|
+
describe('no', () => {
|
|
54
|
+
it('empty assignees', async () => {
|
|
55
|
+
const n1 = await workflow.createNode({
|
|
56
|
+
type: 'manual',
|
|
57
|
+
config: {
|
|
58
|
+
assignees: [],
|
|
59
|
+
forms: {
|
|
60
|
+
f1: {
|
|
61
|
+
actions: [{ status: JOB_STATUS.RESOLVED, key: 'resolve' }],
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const post = await PostRepo.create({
|
|
68
|
+
values: { title: 't1', category: { title: 'c1' } },
|
|
69
|
+
context: { state: { currentUser: users[0] } },
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
await sleep(500);
|
|
73
|
+
|
|
74
|
+
const [pending] = await workflow.getExecutions();
|
|
75
|
+
expect(pending.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('multiple', () => {
|
|
80
|
+
it('assignees from nested array', async () => {
|
|
81
|
+
const n1 = await workflow.createNode({
|
|
82
|
+
type: 'manual',
|
|
83
|
+
config: {
|
|
84
|
+
assignees: [`{{$context.data.category.posts.createdById}}`],
|
|
85
|
+
forms: {
|
|
86
|
+
f1: {
|
|
87
|
+
actions: [{ status: JOB_STATUS.RESOLVED, key: 'resolve' }],
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const post = await PostRepo.create({
|
|
94
|
+
values: { title: 't1', category: { title: 'c1' } },
|
|
95
|
+
context: { state: { currentUser: users[0] } },
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
await sleep(500);
|
|
99
|
+
|
|
100
|
+
const [pending] = await workflow.getExecutions();
|
|
101
|
+
expect(pending.status).toBe(EXECUTION_STATUS.STARTED);
|
|
102
|
+
const [j1] = await pending.getJobs();
|
|
103
|
+
expect(j1.status).toBe(JOB_STATUS.PENDING);
|
|
104
|
+
|
|
105
|
+
const usersJobs = await UserJobModel.findAll();
|
|
106
|
+
expect(usersJobs.length).toBe(1);
|
|
107
|
+
expect(usersJobs[0].status).toBe(JOB_STATUS.PENDING);
|
|
108
|
+
expect(usersJobs[0].userId).toBe(users[0].id);
|
|
109
|
+
expect(usersJobs[0].jobId).toBe(j1.id);
|
|
110
|
+
|
|
111
|
+
const res1 = await agent.resource('users_jobs').submit({
|
|
112
|
+
filterByTk: usersJobs[0].id,
|
|
113
|
+
values: { result: { f1: {}, _: 'resolve' } },
|
|
114
|
+
});
|
|
115
|
+
expect(res1.status).toBe(401);
|
|
116
|
+
|
|
117
|
+
const res2 = await userAgents[1].resource('users_jobs').submit({
|
|
118
|
+
filterByTk: usersJobs[0].id,
|
|
119
|
+
values: {
|
|
120
|
+
result: { f1: {}, _: 'resolve' },
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
expect(res2.status).toBe(403);
|
|
124
|
+
|
|
125
|
+
const res3 = await userAgents[0].resource('users_jobs').submit({
|
|
126
|
+
filterByTk: usersJobs[0].id,
|
|
127
|
+
values: {
|
|
128
|
+
result: { f1: { a: 1 }, _: 'resolve' },
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
expect(res3.status).toBe(202);
|
|
132
|
+
|
|
133
|
+
await sleep(1000);
|
|
134
|
+
|
|
135
|
+
const [j2] = await pending.getJobs();
|
|
136
|
+
expect(j2.status).toBe(JOB_STATUS.RESOLVED);
|
|
137
|
+
expect(j2.result).toEqual({ f1: { a: 1 }, _: 'resolve' });
|
|
138
|
+
|
|
139
|
+
const usersJobsAfter = await UserJobModel.findAll();
|
|
140
|
+
expect(usersJobsAfter.length).toBe(1);
|
|
141
|
+
expect(usersJobsAfter[0].status).toBe(JOB_STATUS.RESOLVED);
|
|
142
|
+
expect(usersJobsAfter[0].result).toEqual({ f1: { a: 1 }, _: 'resolve' });
|
|
143
|
+
|
|
144
|
+
const res4 = await userAgents[0].resource('users_jobs').submit({
|
|
145
|
+
filterByTk: usersJobs[0].id,
|
|
146
|
+
values: {
|
|
147
|
+
result: { f1: { a: 2 }, _: 'resolve' },
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
expect(res4.status).toBe(400);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
package/src/server/actions.ts
CHANGED
|
@@ -50,7 +50,10 @@ export async function submit(context: Context, next) {
|
|
|
50
50
|
await processor.prepare();
|
|
51
51
|
|
|
52
52
|
// NOTE: validate assignee
|
|
53
|
-
const assignees = processor
|
|
53
|
+
const assignees = processor
|
|
54
|
+
.getParsedValue(userJob.node.config.assignees ?? [], userJob.nodeId)
|
|
55
|
+
.flat()
|
|
56
|
+
.filter(Boolean);
|
|
54
57
|
if (!assignees.includes(currentUser.id) || userJob.userId !== currentUser.id) {
|
|
55
58
|
return context.throw(403);
|
|
56
59
|
}
|