@nocobase/plugin-workflow-manual 0.21.0-alpha.14 → 0.21.0-alpha.15

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.
@@ -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.14",
7
- "@nocobase/plugin-workflow": "0.21.0-alpha.14",
6
+ "@nocobase/client": "0.21.0-alpha.15",
7
+ "@nocobase/plugin-workflow": "0.21.0-alpha.15",
8
8
  "@ant-design/icons": "5.2.6",
9
9
  "react-i18next": "11.18.6",
10
- "@nocobase/utils": "0.21.0-alpha.14",
11
- "@nocobase/server": "0.21.0-alpha.14",
12
- "@nocobase/actions": "0.21.0-alpha.14",
13
- "@nocobase/resourcer": "0.21.0-alpha.14",
14
- "@nocobase/plugin-workflow-test": "0.21.0-alpha.14",
15
- "@nocobase/test": "0.21.0-alpha.14",
10
+ "@nocobase/utils": "0.21.0-alpha.15",
11
+ "@nocobase/server": "0.21.0-alpha.15",
12
+ "@nocobase/actions": "0.21.0-alpha.15",
13
+ "@nocobase/resourcer": "0.21.0-alpha.15",
14
+ "@nocobase/plugin-workflow-test": "0.21.0-alpha.15",
15
+ "@nocobase/test": "0.21.0-alpha.15",
16
16
  "@formily/core": "2.3.0",
17
17
  "@formily/antd-v5": "1.1.9",
18
- "@nocobase/database": "0.21.0-alpha.14",
18
+ "@nocobase/database": "0.21.0-alpha.15",
19
19
  "lodash": "4.17.21"
20
20
  };
@@ -100,7 +100,7 @@ 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
105
  status: import_plugin_workflow.JOB_STATUS.PENDING,
106
106
  result: mode ? [] : null,
@@ -126,7 +126,8 @@ class ManualInstruction_default extends import_plugin_workflow.Instruction {
126
126
  }
127
127
  async resume(node, job, processor) {
128
128
  var _a;
129
- const { assignees = [], mode } = node.config;
129
+ const { mode } = node.config;
130
+ const assignees = [...new Set(processor.getParsedValue(node.config.assignees, node.id).flat().filter(Boolean))];
130
131
  const UserJobModel = this.workflow.app.db.getModel("users_jobs");
131
132
  const distribution = await UserJobModel.count({
132
133
  where: {
@@ -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.14",
7
+ "version": "0.21.0-alpha.15",
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": "dbcca03c0535e14f0b09fd13306731b4438829c4",
33
+ "gitHead": "155a252452eba37d8047d7f4a1c3fb518679abf0",
34
34
  "keywords": [
35
35
  "Workflow"
36
36
  ]
@@ -93,7 +93,7 @@ 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
99
  status: JOB_STATUS.PENDING,
@@ -124,7 +124,8 @@ export default class extends Instruction {
124
124
 
125
125
  async resume(node, job, processor: Processor) {
126
126
  // NOTE: check all users jobs related if all done then continue as parallel
127
- const { assignees = [], mode } = node.config as ManualConfig;
127
+ const { mode } = node.config as ManualConfig;
128
+ const assignees = [...new Set(processor.getParsedValue(node.config.assignees, node.id).flat().filter(Boolean))];
128
129
 
129
130
  const UserJobModel = this.workflow.app.db.getModel('users_jobs');
130
131
  const distribution = await UserJobModel.count({
@@ -0,0 +1,127 @@
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('multiple', () => {
54
+ it('assignees from nested array', async () => {
55
+ const n1 = await workflow.createNode({
56
+ type: 'manual',
57
+ config: {
58
+ assignees: [`{{$context.data.category.posts.createdById}}`],
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.STARTED);
76
+ const [j1] = await pending.getJobs();
77
+ expect(j1.status).toBe(JOB_STATUS.PENDING);
78
+
79
+ const usersJobs = await UserJobModel.findAll();
80
+ expect(usersJobs.length).toBe(1);
81
+ expect(usersJobs[0].status).toBe(JOB_STATUS.PENDING);
82
+ expect(usersJobs[0].userId).toBe(users[0].id);
83
+ expect(usersJobs[0].jobId).toBe(j1.id);
84
+
85
+ const res1 = await agent.resource('users_jobs').submit({
86
+ filterByTk: usersJobs[0].id,
87
+ values: { result: { f1: {}, _: 'resolve' } },
88
+ });
89
+ expect(res1.status).toBe(401);
90
+
91
+ const res2 = await userAgents[1].resource('users_jobs').submit({
92
+ filterByTk: usersJobs[0].id,
93
+ values: {
94
+ result: { f1: {}, _: 'resolve' },
95
+ },
96
+ });
97
+ expect(res2.status).toBe(403);
98
+
99
+ const res3 = await userAgents[0].resource('users_jobs').submit({
100
+ filterByTk: usersJobs[0].id,
101
+ values: {
102
+ result: { f1: { a: 1 }, _: 'resolve' },
103
+ },
104
+ });
105
+ expect(res3.status).toBe(202);
106
+
107
+ await sleep(1000);
108
+
109
+ const [j2] = await pending.getJobs();
110
+ expect(j2.status).toBe(JOB_STATUS.RESOLVED);
111
+ expect(j2.result).toEqual({ f1: { a: 1 }, _: 'resolve' });
112
+
113
+ const usersJobsAfter = await UserJobModel.findAll();
114
+ expect(usersJobsAfter.length).toBe(1);
115
+ expect(usersJobsAfter[0].status).toBe(JOB_STATUS.RESOLVED);
116
+ expect(usersJobsAfter[0].result).toEqual({ f1: { a: 1 }, _: 'resolve' });
117
+
118
+ const res4 = await userAgents[0].resource('users_jobs').submit({
119
+ filterByTk: usersJobs[0].id,
120
+ values: {
121
+ result: { f1: { a: 2 }, _: 'resolve' },
122
+ },
123
+ });
124
+ expect(res4.status).toBe(400);
125
+ });
126
+ });
127
+ });
@@ -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.getParsedValue(userJob.node.config.assignees ?? [], userJob.nodeId);
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
  }