@steedos/process 2.2.55-beta.7 → 2.3.0-beta.10
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/lib/approve.js +7 -7
- package/lib/approve.js.map +1 -1
- package/lib/express-middleware.js +0 -1
- package/lib/express-middleware.js.map +1 -1
- package/lib/notifications.js +6 -6
- package/lib/notifications.js.map +1 -1
- package/lib/permission.js +17 -17
- package/lib/permission.js.map +1 -1
- package/lib/permission_manager.js +17 -30
- package/lib/permission_manager.js.map +1 -1
- package/lib/platform_action_manager.js +24 -24
- package/lib/platform_action_manager.js.map +1 -1
- package/lib/process_manager.js +185 -241
- package/lib/process_manager.js.map +1 -1
- package/lib/reassign.js +7 -7
- package/lib/reassign.js.map +1 -1
- package/lib/recall.js +10 -10
- package/lib/recall.js.map +1 -1
- package/lib/reject.js +7 -7
- package/lib/reject.js.map +1 -1
- package/lib/submit.js +5 -5
- package/lib/submit.js.map +1 -1
- package/package.json +4 -4
package/lib/process_manager.js
CHANGED
|
@@ -46,20 +46,20 @@ var _ = require("underscore");
|
|
|
46
46
|
var lockObjectRecord = function (objectName, reocrdId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
47
47
|
return __generator(this, function (_a) {
|
|
48
48
|
switch (_a.label) {
|
|
49
|
-
case 0: return [4
|
|
49
|
+
case 0: return [4, objectql.getObject(objectName).directUpdate(reocrdId, { locked: true })];
|
|
50
50
|
case 1:
|
|
51
51
|
_a.sent();
|
|
52
|
-
return [2
|
|
52
|
+
return [2];
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
55
|
}); };
|
|
56
56
|
var unlockObjectRecord = function (objectName, reocrdId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
57
57
|
return __generator(this, function (_a) {
|
|
58
58
|
switch (_a.label) {
|
|
59
|
-
case 0: return [4
|
|
59
|
+
case 0: return [4, objectql.getObject(objectName).directUpdate(reocrdId, { locked: false })];
|
|
60
60
|
case 1:
|
|
61
61
|
_a.sent();
|
|
62
|
-
return [2
|
|
62
|
+
return [2];
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
}); };
|
|
@@ -69,39 +69,39 @@ var getProcessNodeApprover = function (instanceId, processNode, userSession, cho
|
|
|
69
69
|
switch (_c.label) {
|
|
70
70
|
case 0:
|
|
71
71
|
nodeApprover = [];
|
|
72
|
-
if (!isBack) return [3
|
|
73
|
-
return [4
|
|
72
|
+
if (!isBack) return [3, 4];
|
|
73
|
+
return [4, objectql.getObject("process_instance_node").find({ filters: [['process_instance', '=', instanceId], ['process_node', '=', processNode._id]], sort: "created desc" })];
|
|
74
74
|
case 1:
|
|
75
75
|
processInstanceNodes = _c.sent();
|
|
76
|
-
if (!!_.isEmpty(processInstanceNodes)) return [3
|
|
76
|
+
if (!!_.isEmpty(processInstanceNodes)) return [3, 3];
|
|
77
77
|
lastProcessInstanceNode = processInstanceNodes[0];
|
|
78
|
-
return [4
|
|
78
|
+
return [4, objectql.getObject("process_instance_history").find({ filters: ['process_instance_node', '=', lastProcessInstanceNode._id] })];
|
|
79
79
|
case 2:
|
|
80
80
|
nodeHistroy = _c.sent();
|
|
81
81
|
_.each(nodeHistroy, function (item) {
|
|
82
82
|
nodeApprover.push(item.original_actor);
|
|
83
83
|
});
|
|
84
84
|
_c.label = 3;
|
|
85
|
-
case 3: return [3
|
|
85
|
+
case 3: return [3, 27];
|
|
86
86
|
case 4:
|
|
87
87
|
approver = processNode.approver;
|
|
88
|
-
if (!(approver === 'auto_assign')) return [3
|
|
88
|
+
if (!(approver === 'auto_assign')) return [3, 26];
|
|
89
89
|
if (!_.isEmpty(processNode.assigned_approver_users)) {
|
|
90
90
|
nodeApprover = nodeApprover.concat(processNode.assigned_approver_users);
|
|
91
91
|
}
|
|
92
|
-
if (!!_.isEmpty(processNode.assigned_approver_roles)) return [3
|
|
92
|
+
if (!!_.isEmpty(processNode.assigned_approver_roles)) return [3, 10];
|
|
93
93
|
_i = 0, _a = processNode.assigned_approver_roles;
|
|
94
94
|
_c.label = 5;
|
|
95
95
|
case 5:
|
|
96
|
-
if (!(_i < _a.length)) return [3
|
|
96
|
+
if (!(_i < _a.length)) return [3, 10];
|
|
97
97
|
roleId = _a[_i];
|
|
98
|
-
return [4
|
|
98
|
+
return [4, objectql.getObject("roles").find({ filters: ['api_name', '=', roleId] })];
|
|
99
99
|
case 6:
|
|
100
100
|
dbRoles = _c.sent();
|
|
101
|
-
if (!(dbRoles && dbRoles.length > 0 && !_.isEmpty(dbRoles[0].users))) return [3
|
|
101
|
+
if (!(dbRoles && dbRoles.length > 0 && !_.isEmpty(dbRoles[0].users))) return [3, 7];
|
|
102
102
|
nodeApprover = nodeApprover.concat(dbRoles[0].users);
|
|
103
|
-
return [3
|
|
104
|
-
case 7: return [4
|
|
103
|
+
return [3, 9];
|
|
104
|
+
case 7: return [4, objectql.getObject('roles').findOne(roleId)];
|
|
105
105
|
case 8:
|
|
106
106
|
role = _c.sent();
|
|
107
107
|
if (role && !_.isEmpty(role.users)) {
|
|
@@ -110,13 +110,13 @@ var getProcessNodeApprover = function (instanceId, processNode, userSession, cho
|
|
|
110
110
|
_c.label = 9;
|
|
111
111
|
case 9:
|
|
112
112
|
_i++;
|
|
113
|
-
return [3
|
|
113
|
+
return [3, 5];
|
|
114
114
|
case 10:
|
|
115
|
-
if (!!_.isEmpty(processNode.assigned_approver_flow_roles)) return [3
|
|
115
|
+
if (!!_.isEmpty(processNode.assigned_approver_flow_roles)) return [3, 21];
|
|
116
116
|
submitted_by_1 = userSession.userId;
|
|
117
117
|
spaceId_1 = userSession.spaceId;
|
|
118
|
-
if (!instanceId) return [3
|
|
119
|
-
return [4
|
|
118
|
+
if (!instanceId) return [3, 12];
|
|
119
|
+
return [4, objectql.getObject("process_instance").findOne(instanceId)];
|
|
120
120
|
case 11:
|
|
121
121
|
processInstance = _c.sent();
|
|
122
122
|
submitted_by_1 = processInstance.submitted_by;
|
|
@@ -127,16 +127,16 @@ var getProcessNodeApprover = function (instanceId, processNode, userSession, cho
|
|
|
127
127
|
_b = 0, flowRoleKeys_1 = flowRoleKeys;
|
|
128
128
|
_c.label = 13;
|
|
129
129
|
case 13:
|
|
130
|
-
if (!(_b < flowRoleKeys_1.length)) return [3
|
|
130
|
+
if (!(_b < flowRoleKeys_1.length)) return [3, 19];
|
|
131
131
|
flowRoleKey = flowRoleKeys_1[_b];
|
|
132
132
|
dbFlowRole = void 0;
|
|
133
|
-
return [4
|
|
133
|
+
return [4, objectql.getObject("flow_roles").find({ filters: ['api_name', '=', flowRoleKey] })];
|
|
134
134
|
case 14:
|
|
135
135
|
dbFlowRoles = _c.sent();
|
|
136
|
-
if (!(dbFlowRoles && dbFlowRoles.length == 1)) return [3
|
|
136
|
+
if (!(dbFlowRoles && dbFlowRoles.length == 1)) return [3, 15];
|
|
137
137
|
dbFlowRole = dbFlowRoles[0];
|
|
138
|
-
return [3
|
|
139
|
-
case 15: return [4
|
|
138
|
+
return [3, 17];
|
|
139
|
+
case 15: return [4, objectql.getObject("flow_roles").findOne(flowRoleKey)];
|
|
140
140
|
case 16:
|
|
141
141
|
dbFlowRole = _c.sent();
|
|
142
142
|
_c.label = 17;
|
|
@@ -145,8 +145,8 @@ var getProcessNodeApprover = function (instanceId, processNode, userSession, cho
|
|
|
145
145
|
_c.label = 18;
|
|
146
146
|
case 18:
|
|
147
147
|
_b++;
|
|
148
|
-
return [3
|
|
149
|
-
case 19: return [4
|
|
148
|
+
return [3, 13];
|
|
149
|
+
case 19: return [4, new Promise(function (resolve, reject) {
|
|
150
150
|
Fiber(function () {
|
|
151
151
|
try {
|
|
152
152
|
var handlers_1 = getHandlersManager.getHandlersByUserAndRoles(submitted_by_1, assigned_approver_flow_role_ids_1, spaceId_1);
|
|
@@ -162,12 +162,12 @@ var getProcessNodeApprover = function (instanceId, processNode, userSession, cho
|
|
|
162
162
|
nodeApprover = nodeApprover.concat(handlers);
|
|
163
163
|
_c.label = 21;
|
|
164
164
|
case 21:
|
|
165
|
-
if (!!_.isEmpty(processNode.assigned_approver_user_field)) return [3
|
|
166
|
-
if (!instanceId) return [3
|
|
167
|
-
return [4
|
|
165
|
+
if (!!_.isEmpty(processNode.assigned_approver_user_field)) return [3, 25];
|
|
166
|
+
if (!instanceId) return [3, 24];
|
|
167
|
+
return [4, objectql.getObject("process_instance").findOne(instanceId)];
|
|
168
168
|
case 22:
|
|
169
169
|
processInstance = _c.sent();
|
|
170
|
-
return [4
|
|
170
|
+
return [4, objectql.getObject(processInstance.target_object.o).findOne(processInstance.target_object.ids[0])];
|
|
171
171
|
case 23:
|
|
172
172
|
record = _c.sent();
|
|
173
173
|
_c.label = 24;
|
|
@@ -184,15 +184,15 @@ var getProcessNodeApprover = function (instanceId, processNode, userSession, cho
|
|
|
184
184
|
});
|
|
185
185
|
}
|
|
186
186
|
_c.label = 25;
|
|
187
|
-
case 25: return [3
|
|
187
|
+
case 25: return [3, 27];
|
|
188
188
|
case 26:
|
|
189
189
|
if (approver === 'submitter_choose') {
|
|
190
190
|
if (chooseApprover) {
|
|
191
191
|
if (_.isString(chooseApprover)) {
|
|
192
|
-
return [2
|
|
192
|
+
return [2, [chooseApprover]];
|
|
193
193
|
}
|
|
194
194
|
else if (_.isArray(chooseApprover)) {
|
|
195
|
-
return [2
|
|
195
|
+
return [2, _.uniq(_.compact(chooseApprover))];
|
|
196
196
|
}
|
|
197
197
|
else {
|
|
198
198
|
throw new objectql_1.SteedosError('process_approval_error_invalidChooseApprover');
|
|
@@ -203,15 +203,15 @@ var getProcessNodeApprover = function (instanceId, processNode, userSession, cho
|
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
_c.label = 27;
|
|
206
|
-
case 27: return [2
|
|
206
|
+
case 27: return [2, _.uniq(_.compact(nodeApprover))];
|
|
207
207
|
}
|
|
208
208
|
});
|
|
209
209
|
}); };
|
|
210
210
|
var getProcessNodes = function (processDefinitionId, spaceId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
211
211
|
return __generator(this, function (_a) {
|
|
212
212
|
switch (_a.label) {
|
|
213
|
-
case 0: return [4
|
|
214
|
-
case 1: return [2
|
|
213
|
+
case 0: return [4, objectql.getObject('process_node').find({ filters: [['process_definition', '=', processDefinitionId], ['space', '=', spaceId]], sort: "order asc" })];
|
|
214
|
+
case 1: return [2, _a.sent()];
|
|
215
215
|
}
|
|
216
216
|
});
|
|
217
217
|
}); };
|
|
@@ -219,19 +219,19 @@ var addInstanceHistory = function (spaceId, instanceId, status, comment, options
|
|
|
219
219
|
var instance, name, node, instanceHistory;
|
|
220
220
|
return __generator(this, function (_a) {
|
|
221
221
|
switch (_a.label) {
|
|
222
|
-
case 0: return [4
|
|
222
|
+
case 0: return [4, objectql.getObject("process_instance").findOne(instanceId)];
|
|
223
223
|
case 1:
|
|
224
224
|
instance = _a.sent();
|
|
225
225
|
name = '';
|
|
226
|
-
if (!options.nodeId) return [3
|
|
227
|
-
return [4
|
|
226
|
+
if (!options.nodeId) return [3, 3];
|
|
227
|
+
return [4, objectql.getObject("process_node").findOne(options.nodeId)];
|
|
228
228
|
case 2:
|
|
229
229
|
node = _a.sent();
|
|
230
230
|
if (node) {
|
|
231
231
|
name = node.label;
|
|
232
232
|
}
|
|
233
233
|
_a.label = 3;
|
|
234
|
-
case 3: return [4
|
|
234
|
+
case 3: return [4, objectql.getObject("process_instance_history").insert({
|
|
235
235
|
name: name,
|
|
236
236
|
process_instance: instanceId,
|
|
237
237
|
target_object: instance.target_object,
|
|
@@ -246,18 +246,18 @@ var addInstanceHistory = function (spaceId, instanceId, status, comment, options
|
|
|
246
246
|
})];
|
|
247
247
|
case 4:
|
|
248
248
|
instanceHistory = _a.sent();
|
|
249
|
-
if (!(status === 'approved' || status === 'rejected')) return [3
|
|
250
|
-
return [4
|
|
249
|
+
if (!(status === 'approved' || status === 'rejected')) return [3, 6];
|
|
250
|
+
return [4, handleProcessInstance(instanceHistory.process_instance, status, userSession)];
|
|
251
251
|
case 5:
|
|
252
252
|
_a.sent();
|
|
253
253
|
_a.label = 6;
|
|
254
254
|
case 6:
|
|
255
|
-
if (!(status === 'pending')) return [3
|
|
256
|
-
return [4
|
|
255
|
+
if (!(status === 'pending')) return [3, 8];
|
|
256
|
+
return [4, (0, notifications_1.sendNotifications)(instance.created_by, options.actor, { instanceHistory: instanceHistory, status: status, instance: instance })];
|
|
257
257
|
case 7:
|
|
258
258
|
_a.sent();
|
|
259
259
|
_a.label = 8;
|
|
260
|
-
case 8: return [2
|
|
260
|
+
case 8: return [2];
|
|
261
261
|
}
|
|
262
262
|
});
|
|
263
263
|
}); };
|
|
@@ -268,7 +268,7 @@ var addInstanceNode = function (instanceId, node, userSession, nodeApprover) { r
|
|
|
268
268
|
case 0:
|
|
269
269
|
nodeId = node._id;
|
|
270
270
|
nodeName = node.label;
|
|
271
|
-
return [4
|
|
271
|
+
return [4, objectql.getObject("process_instance_node").insert({
|
|
272
272
|
process_instance: instanceId,
|
|
273
273
|
process_node: nodeId,
|
|
274
274
|
process_node_name: nodeName,
|
|
@@ -281,50 +281,48 @@ var addInstanceNode = function (instanceId, node, userSession, nodeApprover) { r
|
|
|
281
281
|
_i = 0, nodeApprover_1 = nodeApprover;
|
|
282
282
|
_a.label = 2;
|
|
283
283
|
case 2:
|
|
284
|
-
if (!(_i < nodeApprover_1.length)) return [3
|
|
284
|
+
if (!(_i < nodeApprover_1.length)) return [3, 5];
|
|
285
285
|
actor = nodeApprover_1[_i];
|
|
286
|
-
return [4
|
|
286
|
+
return [4, addInstanceHistory(userSession.spaceId, instanceId, 'pending', null, { nodeId: nodeId, actor: actor, originalActor: actor, submitted_by: userSession.userId, instanceNodeId: instanceNode._id }, userSession)];
|
|
287
287
|
case 3:
|
|
288
288
|
_a.sent();
|
|
289
289
|
_a.label = 4;
|
|
290
290
|
case 4:
|
|
291
291
|
_i++;
|
|
292
|
-
return [3
|
|
293
|
-
case 5: return [2
|
|
292
|
+
return [3, 2];
|
|
293
|
+
case 5: return [2];
|
|
294
294
|
}
|
|
295
295
|
});
|
|
296
296
|
}); };
|
|
297
297
|
var getNextNode = function (nodes, index, objectName, recordId, userSession) {
|
|
298
298
|
if (index === void 0) { index = 0; }
|
|
299
299
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
300
|
-
var
|
|
300
|
+
var node, canEntry;
|
|
301
301
|
return __generator(this, function (_a) {
|
|
302
302
|
switch (_a.label) {
|
|
303
303
|
case 0:
|
|
304
|
-
spaceId = userSession.spaceId;
|
|
305
|
-
currentUserId = userSession.userId;
|
|
306
304
|
node = nodes[index];
|
|
307
|
-
if (!node) return [3
|
|
308
|
-
if (!node.filtrad) return [3
|
|
309
|
-
return [2
|
|
310
|
-
case 1: return [4
|
|
305
|
+
if (!node) return [3, 6];
|
|
306
|
+
if (!node.filtrad) return [3, 1];
|
|
307
|
+
return [2, node];
|
|
308
|
+
case 1: return [4, objectql.computeFormula(node.entry_criteria, objectName, recordId, userSession)];
|
|
311
309
|
case 2:
|
|
312
310
|
canEntry = _a.sent();
|
|
313
|
-
if (!canEntry) return [3
|
|
314
|
-
return [2
|
|
311
|
+
if (!canEntry) return [3, 3];
|
|
312
|
+
return [2, node];
|
|
315
313
|
case 3:
|
|
316
|
-
if (!(node.if_criteria_not_met === 'skip')) return [3
|
|
317
|
-
return [4
|
|
318
|
-
case 4: return [2
|
|
314
|
+
if (!(node.if_criteria_not_met === 'skip')) return [3, 5];
|
|
315
|
+
return [4, getNextNode(nodes, index + 1, objectName, recordId, userSession)];
|
|
316
|
+
case 4: return [2, _a.sent()];
|
|
319
317
|
case 5:
|
|
320
318
|
if (node.if_criteria_not_met === 'reject') {
|
|
321
|
-
return [2
|
|
319
|
+
return [2, { to_final_rejection: true }];
|
|
322
320
|
}
|
|
323
321
|
else if (node.if_criteria_not_met === 'approve') {
|
|
324
|
-
return [2
|
|
322
|
+
return [2, { to_final_approval: true }];
|
|
325
323
|
}
|
|
326
324
|
_a.label = 6;
|
|
327
|
-
case 6: return [2
|
|
325
|
+
case 6: return [2];
|
|
328
326
|
}
|
|
329
327
|
});
|
|
330
328
|
});
|
|
@@ -333,101 +331,62 @@ var toNextNode = function (instanceId, node, nextApprovers, userSession) { retur
|
|
|
333
331
|
return __generator(this, function (_a) {
|
|
334
332
|
switch (_a.label) {
|
|
335
333
|
case 0:
|
|
336
|
-
if (!node) return [3
|
|
337
|
-
return [4
|
|
334
|
+
if (!node) return [3, 2];
|
|
335
|
+
return [4, addInstanceNode(instanceId, node, userSession, nextApprovers)];
|
|
338
336
|
case 1:
|
|
339
337
|
_a.sent();
|
|
340
338
|
_a.label = 2;
|
|
341
|
-
case 2: return [2
|
|
339
|
+
case 2: return [2];
|
|
342
340
|
}
|
|
343
341
|
});
|
|
344
342
|
}); };
|
|
345
|
-
//TODO nextApprovers
|
|
346
|
-
// const toNextNode = async (instanceId: string, comment: string, nodes: any, index: number = 0, objectName: string, recordId: string, userSession: any, nextApprovers?)=>{
|
|
347
|
-
// let spaceId = userSession.spaceId;
|
|
348
|
-
// let currentUserId = userSession.userId;
|
|
349
|
-
// let node = nodes[index];
|
|
350
|
-
// if(node){
|
|
351
|
-
// if(node.filtrad){
|
|
352
|
-
// await addInstanceNode(instanceId, node, userSession);
|
|
353
|
-
// }else{
|
|
354
|
-
// const canEntry = await objectql.computeFormula(node.entry_criteria, objectName, recordId, currentUserId, spaceId);
|
|
355
|
-
// if(canEntry){
|
|
356
|
-
// await addInstanceNode(instanceId, node, userSession);
|
|
357
|
-
// }else{
|
|
358
|
-
// if(node.if_criteria_not_met === 'skip'){
|
|
359
|
-
// await toNextNode(instanceId, comment, nodes, index + 1, objectName, recordId, userSession)
|
|
360
|
-
// }else{
|
|
361
|
-
// let options = {actor: currentUserId}
|
|
362
|
-
// if(node.if_criteria_not_met === 'reject'){
|
|
363
|
-
// await addInstanceHistory(userSession.spaceId, instanceId, "rejected", comment, options, userSession)
|
|
364
|
-
// }else if(node.if_criteria_not_met === 'approve'){
|
|
365
|
-
// // await addInstanceHistory(userSession.spaceId, instanceId, "approved", comment, options)
|
|
366
|
-
// }
|
|
367
|
-
// }
|
|
368
|
-
// }
|
|
369
|
-
// }
|
|
370
|
-
// }
|
|
371
|
-
// }
|
|
372
343
|
var getPreviousNode = function (instanceId, currentNode, userSession) { return __awaiter(void 0, void 0, void 0, function () {
|
|
373
344
|
var previousInstanceNodes, previousInstanceNode, previousNode;
|
|
374
345
|
return __generator(this, function (_a) {
|
|
375
346
|
switch (_a.label) {
|
|
376
|
-
case 0: return [4
|
|
347
|
+
case 0: return [4, objectql.getObject("process_instance_node").find({ filters: [['process_instance', '=', instanceId], ['process_node', '!=', currentNode._id]], sort: 'created desc' })];
|
|
377
348
|
case 1:
|
|
378
349
|
previousInstanceNodes = _a.sent();
|
|
379
|
-
if (!!_.isEmpty(previousInstanceNodes)) return [3
|
|
350
|
+
if (!!_.isEmpty(previousInstanceNodes)) return [3, 3];
|
|
380
351
|
previousInstanceNode = previousInstanceNodes[0];
|
|
381
|
-
return [4
|
|
352
|
+
return [4, objectql.getObject("process_node").findOne(previousInstanceNode.process_node)];
|
|
382
353
|
case 2:
|
|
383
354
|
previousNode = _a.sent();
|
|
384
|
-
return [2
|
|
355
|
+
return [2, previousNode];
|
|
385
356
|
case 3: throw new objectql_1.SteedosError('not find previous node');
|
|
386
357
|
}
|
|
387
358
|
});
|
|
388
359
|
}); };
|
|
389
|
-
// const toPreviousNode = async (instanceId: string, currentNode: any, userSession: any)=>{
|
|
390
|
-
// const previousInstanceNodes = await objectql.getObject("process_instance_node").find({filters: [['process_instance', '=', instanceId], ['process_node', '!=', currentNode._id]], sort: 'created desc'});
|
|
391
|
-
// if(!_.isEmpty(previousInstanceNodes)){
|
|
392
|
-
// const previousInstanceNode = previousInstanceNodes[0];
|
|
393
|
-
// const previousNode = await objectql.getObject("process_node").findOne(previousInstanceNode.process_node)
|
|
394
|
-
// await addInstanceNode(instanceId, previousNode, userSession, true);
|
|
395
|
-
// }else{
|
|
396
|
-
// throw new SteedosError('not find previous node')
|
|
397
|
-
// }
|
|
398
|
-
// }
|
|
399
|
-
//TODO 处理提交权限
|
|
400
360
|
var getObjectProcessDefinition = function (objectName, recordId, userSession) { return __awaiter(void 0, void 0, void 0, function () {
|
|
401
|
-
var spaceId,
|
|
361
|
+
var spaceId, processes, process, _i, processes_1, _process, canEntry;
|
|
402
362
|
return __generator(this, function (_a) {
|
|
403
363
|
switch (_a.label) {
|
|
404
364
|
case 0:
|
|
405
365
|
spaceId = userSession.spaceId;
|
|
406
|
-
|
|
407
|
-
return [4 /*yield*/, objectql.getObject('process_definition').find({ filters: [['object_name', '=', objectName], ['space', '=', spaceId], ['active', '=', true]], sort: "order asc" })];
|
|
366
|
+
return [4, objectql.getObject('process_definition').find({ filters: [['object_name', '=', objectName], ['space', '=', spaceId], ['active', '=', true]], sort: "order asc" })];
|
|
408
367
|
case 1:
|
|
409
368
|
processes = _a.sent();
|
|
410
369
|
if (processes.length < 1) {
|
|
411
|
-
return [2
|
|
370
|
+
return [2, null];
|
|
412
371
|
}
|
|
413
372
|
process = null;
|
|
414
373
|
_i = 0, processes_1 = processes;
|
|
415
374
|
_a.label = 2;
|
|
416
375
|
case 2:
|
|
417
|
-
if (!(_i < processes_1.length)) return [3
|
|
376
|
+
if (!(_i < processes_1.length)) return [3, 5];
|
|
418
377
|
_process = processes_1[_i];
|
|
419
|
-
return [4
|
|
378
|
+
return [4, objectql.computeFormula(_process.entry_criteria, objectName, recordId, userSession)];
|
|
420
379
|
case 3:
|
|
421
380
|
canEntry = _a.sent();
|
|
422
381
|
if (canEntry) {
|
|
423
382
|
process = _process;
|
|
424
|
-
return [3
|
|
383
|
+
return [3, 5];
|
|
425
384
|
}
|
|
426
385
|
_a.label = 4;
|
|
427
386
|
case 4:
|
|
428
387
|
_i++;
|
|
429
|
-
return [3
|
|
430
|
-
case 5: return [2
|
|
388
|
+
return [3, 2];
|
|
389
|
+
case 5: return [2, process];
|
|
431
390
|
}
|
|
432
391
|
});
|
|
433
392
|
}); };
|
|
@@ -436,16 +395,16 @@ var recordSubmit = function (processDefinitionId, objectName, recordId, userSess
|
|
|
436
395
|
var pendingInstanceCount, nodes, nextNode, to_final_rejection, to_final_approval, approver, record, instance, options, options;
|
|
437
396
|
return __generator(this, function (_a) {
|
|
438
397
|
switch (_a.label) {
|
|
439
|
-
case 0: return [4
|
|
398
|
+
case 0: return [4, objectql.getObject("process_instance").count({ filters: [['target_object.o', '=', objectName], ['target_object.ids', '=', recordId], ['status', '=', 'pending']] })];
|
|
440
399
|
case 1:
|
|
441
400
|
pendingInstanceCount = _a.sent();
|
|
442
401
|
if (pendingInstanceCount > 0) {
|
|
443
402
|
throw new objectql_1.SteedosError('process_approval_error_processInstancePending');
|
|
444
403
|
}
|
|
445
|
-
return [4
|
|
404
|
+
return [4, getProcessNodes(processDefinitionId, userSession.spaceId)];
|
|
446
405
|
case 2:
|
|
447
406
|
nodes = _a.sent();
|
|
448
|
-
return [4
|
|
407
|
+
return [4, getNextNode(nodes, 0, objectName, recordId, userSession)];
|
|
449
408
|
case 3:
|
|
450
409
|
nextNode = _a.sent();
|
|
451
410
|
to_final_rejection = false;
|
|
@@ -457,15 +416,15 @@ var recordSubmit = function (processDefinitionId, objectName, recordId, userSess
|
|
|
457
416
|
to_final_approval = true;
|
|
458
417
|
}
|
|
459
418
|
approver = null;
|
|
460
|
-
if (!(!to_final_rejection && !to_final_rejection)) return [3
|
|
461
|
-
return [4
|
|
419
|
+
if (!(!to_final_rejection && !to_final_rejection)) return [3, 6];
|
|
420
|
+
return [4, objectql.getObject(objectName).findOne(recordId)];
|
|
462
421
|
case 4:
|
|
463
422
|
record = _a.sent();
|
|
464
|
-
return [4
|
|
423
|
+
return [4, getProcessNodeApprover(null, nextNode, userSession, chooseApprover, false, record)];
|
|
465
424
|
case 5:
|
|
466
425
|
approver = _a.sent();
|
|
467
426
|
_a.label = 6;
|
|
468
|
-
case 6: return [4
|
|
427
|
+
case 6: return [4, objectql.getObject("process_instance").insert({
|
|
469
428
|
process_definition: processDefinitionId,
|
|
470
429
|
target_object: {
|
|
471
430
|
"o": objectName,
|
|
@@ -478,33 +437,33 @@ var recordSubmit = function (processDefinitionId, objectName, recordId, userSess
|
|
|
478
437
|
})];
|
|
479
438
|
case 7:
|
|
480
439
|
instance = _a.sent();
|
|
481
|
-
return [4
|
|
440
|
+
return [4, lockObjectRecord(objectName, recordId)];
|
|
482
441
|
case 8:
|
|
483
442
|
_a.sent();
|
|
484
|
-
return [4
|
|
443
|
+
return [4, (0, platform_action_manager_1.runProcessAction)(processDefinitionId, 'initial_submission', recordId, userSession)];
|
|
485
444
|
case 9:
|
|
486
445
|
_a.sent();
|
|
487
|
-
return [4
|
|
446
|
+
return [4, addInstanceHistory(userSession.spaceId, instance._id, "started", comment, { actor: userSession.userId }, userSession)];
|
|
488
447
|
case 10:
|
|
489
448
|
_a.sent();
|
|
490
|
-
if (!to_final_rejection) return [3
|
|
449
|
+
if (!to_final_rejection) return [3, 12];
|
|
491
450
|
options = { actor: userSession.userId };
|
|
492
|
-
return [4
|
|
451
|
+
return [4, addInstanceHistory(userSession.spaceId, instance._id, "rejected", comment, options, userSession)];
|
|
493
452
|
case 11:
|
|
494
453
|
_a.sent();
|
|
495
|
-
return [3
|
|
454
|
+
return [3, 16];
|
|
496
455
|
case 12:
|
|
497
|
-
if (!to_final_approval) return [3
|
|
456
|
+
if (!to_final_approval) return [3, 14];
|
|
498
457
|
options = { actor: userSession.userId };
|
|
499
|
-
return [4
|
|
458
|
+
return [4, addInstanceHistory(userSession.spaceId, instance._id, "approved", comment, options, userSession)];
|
|
500
459
|
case 13:
|
|
501
460
|
_a.sent();
|
|
502
|
-
return [3
|
|
503
|
-
case 14: return [4
|
|
461
|
+
return [3, 16];
|
|
462
|
+
case 14: return [4, toNextNode(instance._id, nextNode, approver, userSession)];
|
|
504
463
|
case 15:
|
|
505
464
|
_a.sent();
|
|
506
465
|
_a.label = 16;
|
|
507
|
-
case 16: return [2
|
|
466
|
+
case 16: return [2];
|
|
508
467
|
}
|
|
509
468
|
});
|
|
510
469
|
}); };
|
|
@@ -515,8 +474,8 @@ var getReocrdProcessInstance = function (objectName, recordId, status, userSessi
|
|
|
515
474
|
switch (_a.label) {
|
|
516
475
|
case 0:
|
|
517
476
|
spaceId = userSession.spaceId;
|
|
518
|
-
return [4
|
|
519
|
-
case 1: return [2
|
|
477
|
+
return [4, objectql.getObject("process_instance").find({ filters: [['space', '=', spaceId], ['status', '=', status], ['target_object.o', '=', objectName], ['target_object.ids', '=', recordId]] })];
|
|
478
|
+
case 1: return [2, _a.sent()];
|
|
520
479
|
}
|
|
521
480
|
});
|
|
522
481
|
}); };
|
|
@@ -528,13 +487,13 @@ var getProcessInstanceWorkitem = function (instanceHistoryId, userSession) { ret
|
|
|
528
487
|
case 0:
|
|
529
488
|
spaceId = userSession.spaceId;
|
|
530
489
|
userId = userSession.userId;
|
|
531
|
-
return [4
|
|
490
|
+
return [4, objectql.getObject("process_instance_history").find({ filters: [['_id', '=', instanceHistoryId], ['step_status', '=', 'pending'], ['actor', '=', userId], ['space', '=', spaceId]] })];
|
|
532
491
|
case 1:
|
|
533
492
|
workitme = _a.sent();
|
|
534
493
|
if (workitme.length > 0) {
|
|
535
|
-
return [2
|
|
494
|
+
return [2, workitme[0]];
|
|
536
495
|
}
|
|
537
|
-
return [2
|
|
496
|
+
return [2];
|
|
538
497
|
}
|
|
539
498
|
});
|
|
540
499
|
}); };
|
|
@@ -562,75 +521,61 @@ var getProcessNodeActionWhenByStatus = function (processStatus) {
|
|
|
562
521
|
}
|
|
563
522
|
return when;
|
|
564
523
|
};
|
|
565
|
-
// export const getProcessInstanceWorkitem = async (objectName: string, recordId: string, userSession: any)=>{
|
|
566
|
-
// let spaceId = userSession.spaceId;
|
|
567
|
-
// let userId = userSession.userId; //TODO 代理
|
|
568
|
-
// const instances = await objectql.getObject("process_instance").find({filters: [['space', '=', spaceId], ['status', '=', 'pending'], ['target_object.o', '=', objectName], ['target_object.ids', '=', recordId]]});
|
|
569
|
-
// if(instances.length < 1){
|
|
570
|
-
// return
|
|
571
|
-
// }
|
|
572
|
-
// const instance = instances[0];
|
|
573
|
-
// const workitme = await objectql.getObject("process_instance_history").find({filters: [['process_instance', '=', instance._id], ['step_status', '=', 'pending'], ['actor', '=', userId]]})
|
|
574
|
-
// if(workitme.length > 0){
|
|
575
|
-
// return workitme[0];
|
|
576
|
-
// }
|
|
577
|
-
// }
|
|
578
|
-
//TODO 编写trigger 处理elapsed_time
|
|
579
524
|
var handleProcessInstance = function (instanceId, processStatus, userSession) { return __awaiter(void 0, void 0, void 0, function () {
|
|
580
525
|
var otherPendingInstanceNodeCount, pInstance, process_1, when;
|
|
581
526
|
return __generator(this, function (_a) {
|
|
582
527
|
switch (_a.label) {
|
|
583
|
-
case 0: return [4
|
|
528
|
+
case 0: return [4, objectql.getObject("process_instance_node").count({ filters: [['process_instance', '=', instanceId], ['node_status', '=', 'pending']] })];
|
|
584
529
|
case 1:
|
|
585
530
|
otherPendingInstanceNodeCount = _a.sent();
|
|
586
|
-
if (!(otherPendingInstanceNodeCount === 0)) return [3
|
|
587
|
-
return [4
|
|
531
|
+
if (!(otherPendingInstanceNodeCount === 0)) return [3, 18];
|
|
532
|
+
return [4, objectql.getObject("process_instance").update(instanceId, { status: processStatus, completed_date: new Date(), last_actor: userSession.userId })];
|
|
588
533
|
case 2:
|
|
589
534
|
pInstance = _a.sent();
|
|
590
|
-
if (!(processStatus === 'removed')) return [3
|
|
591
|
-
return [4
|
|
535
|
+
if (!(processStatus === 'removed')) return [3, 4];
|
|
536
|
+
return [4, unlockObjectRecord(pInstance.target_object.o, pInstance.target_object.ids[0])];
|
|
592
537
|
case 3:
|
|
593
538
|
_a.sent();
|
|
594
|
-
return [3
|
|
595
|
-
case 4: return [4
|
|
539
|
+
return [3, 14];
|
|
540
|
+
case 4: return [4, objectql.getObject("process_definition").findOne(pInstance.process_definition)];
|
|
596
541
|
case 5:
|
|
597
542
|
process_1 = _a.sent();
|
|
598
|
-
if (!(processStatus === 'approved')) return [3
|
|
599
|
-
if (!(process_1.final_approval_record_lock === 'unlock')) return [3
|
|
600
|
-
return [4
|
|
543
|
+
if (!(processStatus === 'approved')) return [3, 10];
|
|
544
|
+
if (!(process_1.final_approval_record_lock === 'unlock')) return [3, 7];
|
|
545
|
+
return [4, unlockObjectRecord(pInstance.target_object.o, pInstance.target_object.ids[0])];
|
|
601
546
|
case 6:
|
|
602
547
|
_a.sent();
|
|
603
|
-
return [3
|
|
604
|
-
case 7: return [4
|
|
548
|
+
return [3, 9];
|
|
549
|
+
case 7: return [4, lockObjectRecord(pInstance.target_object.o, pInstance.target_object.ids[0])];
|
|
605
550
|
case 8:
|
|
606
551
|
_a.sent();
|
|
607
552
|
_a.label = 9;
|
|
608
|
-
case 9: return [3
|
|
553
|
+
case 9: return [3, 14];
|
|
609
554
|
case 10:
|
|
610
|
-
if (!(processStatus === 'rejected')) return [3
|
|
611
|
-
if (!(process_1.final_rejection_record_lock === 'unlock')) return [3
|
|
612
|
-
return [4
|
|
555
|
+
if (!(processStatus === 'rejected')) return [3, 14];
|
|
556
|
+
if (!(process_1.final_rejection_record_lock === 'unlock')) return [3, 12];
|
|
557
|
+
return [4, unlockObjectRecord(pInstance.target_object.o, pInstance.target_object.ids[0])];
|
|
613
558
|
case 11:
|
|
614
559
|
_a.sent();
|
|
615
|
-
return [3
|
|
616
|
-
case 12: return [4
|
|
560
|
+
return [3, 14];
|
|
561
|
+
case 12: return [4, lockObjectRecord(pInstance.target_object.o, pInstance.target_object.ids[0])];
|
|
617
562
|
case 13:
|
|
618
563
|
_a.sent();
|
|
619
564
|
_a.label = 14;
|
|
620
565
|
case 14:
|
|
621
566
|
when = getProcessActionWhenByStatus(processStatus);
|
|
622
|
-
if (!when) return [3
|
|
623
|
-
return [4
|
|
567
|
+
if (!when) return [3, 16];
|
|
568
|
+
return [4, (0, platform_action_manager_1.runProcessAction)(pInstance.process_definition, when, pInstance.target_object.ids[0], userSession)];
|
|
624
569
|
case 15:
|
|
625
570
|
_a.sent();
|
|
626
571
|
_a.label = 16;
|
|
627
572
|
case 16:
|
|
628
|
-
if (!(['approved', 'rejected'].indexOf(processStatus) > -1)) return [3
|
|
629
|
-
return [4
|
|
573
|
+
if (!(['approved', 'rejected'].indexOf(processStatus) > -1)) return [3, 18];
|
|
574
|
+
return [4, (0, notifications_1.sendNotifications)(pInstance.created_by, pInstance.created_by, { status: processStatus, instance: pInstance })];
|
|
630
575
|
case 17:
|
|
631
576
|
_a.sent();
|
|
632
577
|
_a.label = 18;
|
|
633
|
-
case 18: return [2
|
|
578
|
+
case 18: return [2];
|
|
634
579
|
}
|
|
635
580
|
});
|
|
636
581
|
}); };
|
|
@@ -638,57 +583,56 @@ var getCurrentInstanceNode = function (instanceId) { return __awaiter(void 0, vo
|
|
|
638
583
|
var pendingNodes, currentNode;
|
|
639
584
|
return __generator(this, function (_a) {
|
|
640
585
|
switch (_a.label) {
|
|
641
|
-
case 0: return [4
|
|
586
|
+
case 0: return [4, objectql.getObject("process_instance_node").find({ filters: [['process_instance', '=', instanceId], ['node_status', '=', 'pending']] })];
|
|
642
587
|
case 1:
|
|
643
588
|
pendingNodes = _a.sent();
|
|
644
589
|
currentNode = null;
|
|
645
590
|
if (pendingNodes.length > 0) {
|
|
646
591
|
currentNode = pendingNodes[0];
|
|
647
592
|
}
|
|
648
|
-
return [2
|
|
593
|
+
return [2, currentNode];
|
|
649
594
|
}
|
|
650
595
|
});
|
|
651
596
|
}); };
|
|
652
597
|
var getProcessInstance = function (instanceId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
653
598
|
return __generator(this, function (_a) {
|
|
654
599
|
switch (_a.label) {
|
|
655
|
-
case 0: return [4
|
|
656
|
-
case 1: return [2
|
|
600
|
+
case 0: return [4, objectql.getObject("process_instance").findOne(instanceId)];
|
|
601
|
+
case 1: return [2, _a.sent()];
|
|
657
602
|
}
|
|
658
603
|
});
|
|
659
604
|
}); };
|
|
660
605
|
var getProcessNode = function (processNodeId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
661
606
|
return __generator(this, function (_a) {
|
|
662
607
|
switch (_a.label) {
|
|
663
|
-
case 0: return [4
|
|
664
|
-
case 1: return [2
|
|
608
|
+
case 0: return [4, objectql.getObject("process_node").findOne(processNodeId)];
|
|
609
|
+
case 1: return [2, _a.sent()];
|
|
665
610
|
}
|
|
666
611
|
});
|
|
667
612
|
}); };
|
|
668
|
-
//TODO 编写trigger 处理elapsed_time
|
|
669
613
|
var handleProcessInstanceNode = function (instanceId, currentInstanceNode, processStatus, nextNodeOptions, userSession) { return __awaiter(void 0, void 0, void 0, function () {
|
|
670
614
|
var otherPendingInstanceHistoryCount, finalProcessStatus, when, instance, to_final_rejection, to_final_approval;
|
|
671
615
|
return __generator(this, function (_a) {
|
|
672
616
|
switch (_a.label) {
|
|
673
|
-
case 0: return [4
|
|
617
|
+
case 0: return [4, objectql.getObject("process_instance_history").count({ filters: [['process_instance', '=', instanceId], ['step_status', '=', 'pending']] })];
|
|
674
618
|
case 1:
|
|
675
619
|
otherPendingInstanceHistoryCount = _a.sent();
|
|
676
|
-
if (!(otherPendingInstanceHistoryCount === 0)) return [3
|
|
620
|
+
if (!(otherPendingInstanceHistoryCount === 0)) return [3, 11];
|
|
677
621
|
finalProcessStatus = processStatus;
|
|
678
|
-
return [4
|
|
622
|
+
return [4, objectql.getObject("process_instance_node").updateMany([['process_instance', '=', instanceId], ['node_status', '=', 'pending']], { node_status: processStatus, completed_date: new Date(), last_actor: userSession.userId })];
|
|
679
623
|
case 2:
|
|
680
624
|
_a.sent();
|
|
681
625
|
when = getProcessNodeActionWhenByStatus(processStatus);
|
|
682
|
-
if (!when) return [3
|
|
683
|
-
return [4
|
|
626
|
+
if (!when) return [3, 5];
|
|
627
|
+
return [4, objectql.getObject("process_instance").findOne(instanceId)];
|
|
684
628
|
case 3:
|
|
685
629
|
instance = _a.sent();
|
|
686
|
-
return [4
|
|
630
|
+
return [4, (0, platform_action_manager_1.runProcessNodeAction)(currentInstanceNode.process_node, when, instance.target_object.ids[0], userSession)];
|
|
687
631
|
case 4:
|
|
688
632
|
_a.sent();
|
|
689
633
|
_a.label = 5;
|
|
690
634
|
case 5:
|
|
691
|
-
if (!nextNodeOptions) return [3
|
|
635
|
+
if (!nextNodeOptions) return [3, 9];
|
|
692
636
|
to_final_rejection = false;
|
|
693
637
|
to_final_approval = false;
|
|
694
638
|
if (nextNodeOptions.node.to_final_rejection) {
|
|
@@ -699,36 +643,36 @@ var handleProcessInstanceNode = function (instanceId, currentInstanceNode, proce
|
|
|
699
643
|
to_final_approval = true;
|
|
700
644
|
finalProcessStatus = 'approved';
|
|
701
645
|
}
|
|
702
|
-
if (!to_final_rejection) return [3
|
|
703
|
-
return [3
|
|
646
|
+
if (!to_final_rejection) return [3, 6];
|
|
647
|
+
return [3, 9];
|
|
704
648
|
case 6:
|
|
705
|
-
if (!to_final_approval) return [3
|
|
706
|
-
return [3
|
|
707
|
-
case 7: return [4
|
|
649
|
+
if (!to_final_approval) return [3, 7];
|
|
650
|
+
return [3, 9];
|
|
651
|
+
case 7: return [4, toNextNode(instanceId, nextNodeOptions.node, nextNodeOptions.approve, userSession)];
|
|
708
652
|
case 8:
|
|
709
653
|
_a.sent();
|
|
710
654
|
_a.label = 9;
|
|
711
|
-
case 9: return [4
|
|
655
|
+
case 9: return [4, handleProcessInstance(instanceId, finalProcessStatus, userSession)];
|
|
712
656
|
case 10:
|
|
713
657
|
_a.sent();
|
|
714
658
|
_a.label = 11;
|
|
715
|
-
case 11: return [2
|
|
659
|
+
case 11: return [2];
|
|
716
660
|
}
|
|
717
661
|
});
|
|
718
662
|
}); };
|
|
719
663
|
var getInstanceHistory = function (instanceHistoryId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
720
664
|
return __generator(this, function (_a) {
|
|
721
665
|
switch (_a.label) {
|
|
722
|
-
case 0: return [4
|
|
723
|
-
case 1: return [2
|
|
666
|
+
case 0: return [4, objectql.getObject("process_instance_history").findOne(instanceHistoryId)];
|
|
667
|
+
case 1: return [2, _a.sent()];
|
|
724
668
|
}
|
|
725
669
|
});
|
|
726
670
|
}); };
|
|
727
671
|
var getPendingInstanceHistoryCount = function (instanceId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
728
672
|
return __generator(this, function (_a) {
|
|
729
673
|
switch (_a.label) {
|
|
730
|
-
case 0: return [4
|
|
731
|
-
case 1: return [2
|
|
674
|
+
case 0: return [4, objectql.getObject("process_instance_history").count({ filters: [['process_instance', '=', instanceId], ['step_status', '=', 'pending']] })];
|
|
675
|
+
case 1: return [2, _a.sent()];
|
|
732
676
|
}
|
|
733
677
|
});
|
|
734
678
|
}); };
|
|
@@ -736,16 +680,16 @@ var handleProcessInstanceWorkitem = function (currentInstanceNode, processStatus
|
|
|
736
680
|
var instanceHistory, when_multiple_approvers, processNode;
|
|
737
681
|
return __generator(this, function (_a) {
|
|
738
682
|
switch (_a.label) {
|
|
739
|
-
case 0: return [4
|
|
683
|
+
case 0: return [4, getInstanceHistory(instanceHistoryId)];
|
|
740
684
|
case 1:
|
|
741
685
|
instanceHistory = _a.sent();
|
|
742
|
-
if (!(processStatus === 'rejected' || processStatus === 'approved')) return [3
|
|
743
|
-
return [4
|
|
686
|
+
if (!(processStatus === 'rejected' || processStatus === 'approved')) return [3, 6];
|
|
687
|
+
return [4, objectql.getObject("process_instance_history").update(instanceHistoryId, { step_status: processStatus, comments: comment, actor: userSession.userId })];
|
|
744
688
|
case 2:
|
|
745
689
|
_a.sent();
|
|
746
690
|
when_multiple_approvers = 'first_response';
|
|
747
|
-
if (!instanceHistory.step_node) return [3
|
|
748
|
-
return [4
|
|
691
|
+
if (!instanceHistory.step_node) return [3, 4];
|
|
692
|
+
return [4, objectql.getObject("process_node").findOne(instanceHistory.step_node)];
|
|
749
693
|
case 3:
|
|
750
694
|
processNode = _a.sent();
|
|
751
695
|
if (processNode && processNode.when_multiple_approvers) {
|
|
@@ -753,15 +697,15 @@ var handleProcessInstanceWorkitem = function (currentInstanceNode, processStatus
|
|
|
753
697
|
}
|
|
754
698
|
_a.label = 4;
|
|
755
699
|
case 4:
|
|
756
|
-
if (!(when_multiple_approvers === 'first_response' || (when_multiple_approvers === 'unanimous' && processStatus === 'rejected'))) return [3
|
|
757
|
-
return [4
|
|
700
|
+
if (!(when_multiple_approvers === 'first_response' || (when_multiple_approvers === 'unanimous' && processStatus === 'rejected'))) return [3, 6];
|
|
701
|
+
return [4, objectql.getObject("process_instance_history").updateMany([['_id', '!=', instanceHistory._id], ['process_instance', '=', instanceHistory.process_instance], ['step_status', '=', 'pending']], { step_status: 'no_response' })];
|
|
758
702
|
case 5:
|
|
759
703
|
_a.sent();
|
|
760
704
|
_a.label = 6;
|
|
761
|
-
case 6: return [4
|
|
705
|
+
case 6: return [4, handleProcessInstanceNode(instanceHistory.process_instance, currentInstanceNode, processStatus, nextNodeOptions, userSession)];
|
|
762
706
|
case 7:
|
|
763
707
|
_a.sent();
|
|
764
|
-
return [2
|
|
708
|
+
return [2];
|
|
765
709
|
}
|
|
766
710
|
});
|
|
767
711
|
}); };
|
|
@@ -771,46 +715,46 @@ var processInstanceWorkitemApprove = function (instanceHistoryId, userSession, c
|
|
|
771
715
|
switch (_c.label) {
|
|
772
716
|
case 0:
|
|
773
717
|
nextNodeOptions = null;
|
|
774
|
-
return [4
|
|
718
|
+
return [4, getInstanceHistory(instanceHistoryId)];
|
|
775
719
|
case 1:
|
|
776
720
|
instanceHistory = _c.sent();
|
|
777
721
|
instanceId = instanceHistory.process_instance;
|
|
778
|
-
return [4
|
|
722
|
+
return [4, getCurrentInstanceNode(instanceId)];
|
|
779
723
|
case 2:
|
|
780
724
|
currentInstanceNode = _c.sent();
|
|
781
|
-
return [4
|
|
725
|
+
return [4, getProcessInstance(instanceId)];
|
|
782
726
|
case 3:
|
|
783
727
|
instance = _c.sent();
|
|
784
|
-
return [4
|
|
728
|
+
return [4, getProcessNode(instanceHistory.step_node)];
|
|
785
729
|
case 4:
|
|
786
730
|
currentProcessNode = _c.sent();
|
|
787
|
-
return [4
|
|
731
|
+
return [4, getProcessNodes(instance.process_definition, userSession.spaceId)];
|
|
788
732
|
case 5:
|
|
789
733
|
nodes = _c.sent();
|
|
790
734
|
index = _.findIndex(nodes, function (item) { return item._id === currentInstanceNode.process_node; });
|
|
791
735
|
_a = currentProcessNode.when_multiple_approvers === 'first_response';
|
|
792
|
-
if (_a) return [3
|
|
793
|
-
return [4
|
|
736
|
+
if (_a) return [3, 7];
|
|
737
|
+
return [4, getPendingInstanceHistoryCount(instanceId)];
|
|
794
738
|
case 6:
|
|
795
739
|
_a = (_c.sent()) < 2;
|
|
796
740
|
_c.label = 7;
|
|
797
741
|
case 7:
|
|
798
|
-
if (!_a) return [3
|
|
799
|
-
return [4
|
|
742
|
+
if (!_a) return [3, 10];
|
|
743
|
+
return [4, getNextNode(nodes, index + 1, instance.target_object.o, instance.target_object.ids[0], userSession)];
|
|
800
744
|
case 8:
|
|
801
745
|
nextNode = _c.sent();
|
|
802
|
-
if (!nextNode) return [3
|
|
746
|
+
if (!nextNode) return [3, 10];
|
|
803
747
|
nextNodeOptions = {};
|
|
804
748
|
nextNodeOptions.node = nextNode;
|
|
805
749
|
_b = nextNodeOptions;
|
|
806
|
-
return [4
|
|
750
|
+
return [4, getProcessNodeApprover(instanceId, nextNodeOptions.node, userSession, chooseApprover, false)];
|
|
807
751
|
case 9:
|
|
808
752
|
_b.approve = _c.sent();
|
|
809
753
|
_c.label = 10;
|
|
810
|
-
case 10: return [4
|
|
754
|
+
case 10: return [4, handleProcessInstanceWorkitem(currentInstanceNode, 'approved', instanceHistoryId, userSession, comment, nextNodeOptions)];
|
|
811
755
|
case 11:
|
|
812
756
|
_c.sent();
|
|
813
|
-
return [2
|
|
757
|
+
return [2];
|
|
814
758
|
}
|
|
815
759
|
});
|
|
816
760
|
}); };
|
|
@@ -821,31 +765,31 @@ var processInstanceWorkitemReject = function (instanceHistoryId, userSession, co
|
|
|
821
765
|
switch (_c.label) {
|
|
822
766
|
case 0:
|
|
823
767
|
nextNodeOptions = null;
|
|
824
|
-
return [4
|
|
768
|
+
return [4, getInstanceHistory(instanceHistoryId)];
|
|
825
769
|
case 1:
|
|
826
770
|
instanceHistory = _c.sent();
|
|
827
771
|
instanceId = instanceHistory.process_instance;
|
|
828
|
-
return [4
|
|
772
|
+
return [4, getCurrentInstanceNode(instanceId)];
|
|
829
773
|
case 2:
|
|
830
774
|
currentInstanceNode = _c.sent();
|
|
831
|
-
return [4
|
|
775
|
+
return [4, getProcessNode(instanceHistory.step_node)];
|
|
832
776
|
case 3:
|
|
833
777
|
currentProcessNode = _c.sent();
|
|
834
|
-
if (!(currentProcessNode.reject_behavior === 'back_to_previous')) return [3
|
|
778
|
+
if (!(currentProcessNode.reject_behavior === 'back_to_previous')) return [3, 6];
|
|
835
779
|
nextNodeOptions = {};
|
|
836
780
|
_a = nextNodeOptions;
|
|
837
|
-
return [4
|
|
781
|
+
return [4, getPreviousNode(instanceId, currentProcessNode, userSession)];
|
|
838
782
|
case 4:
|
|
839
783
|
_a.node = _c.sent();
|
|
840
784
|
_b = nextNodeOptions;
|
|
841
|
-
return [4
|
|
785
|
+
return [4, getProcessNodeApprover(instanceId, nextNodeOptions.node, userSession, null, true)];
|
|
842
786
|
case 5:
|
|
843
787
|
_b.approve = _c.sent();
|
|
844
788
|
_c.label = 6;
|
|
845
|
-
case 6: return [4
|
|
789
|
+
case 6: return [4, handleProcessInstanceWorkitem(currentInstanceNode, 'rejected', instanceHistoryId, userSession, comment, nextNodeOptions)];
|
|
846
790
|
case 7:
|
|
847
791
|
_c.sent();
|
|
848
|
-
return [2
|
|
792
|
+
return [2];
|
|
849
793
|
}
|
|
850
794
|
});
|
|
851
795
|
}); };
|
|
@@ -861,17 +805,17 @@ var processInstanceWorkitemReassign = function (instanceHistoryId, userSession,
|
|
|
861
805
|
if (!_.isString(chooseApprover)) {
|
|
862
806
|
throw new objectql_1.SteedosError('process_approval_error_reassign_approver_mustBeString');
|
|
863
807
|
}
|
|
864
|
-
return [4
|
|
808
|
+
return [4, objectql.getObject("process_instance_history").update(instanceHistoryId, {
|
|
865
809
|
step_status: "reassigned",
|
|
866
810
|
actor: chooseApprover,
|
|
867
811
|
comments: comment
|
|
868
812
|
})];
|
|
869
813
|
case 1:
|
|
870
814
|
history = _a.sent();
|
|
871
|
-
return [4
|
|
815
|
+
return [4, addInstanceHistory(userSession.spaceId, history.process_instance, 'pending', null, { nodeId: history.step_node, actor: chooseApprover, originalActor: history.original_actor, submitted_by: userSession.userId }, userSession)];
|
|
872
816
|
case 2:
|
|
873
817
|
_a.sent();
|
|
874
|
-
return [2
|
|
818
|
+
return [2];
|
|
875
819
|
}
|
|
876
820
|
});
|
|
877
821
|
}); };
|
|
@@ -882,13 +826,13 @@ var processInstanceWorkitemRemovebyInstance = function (instanceId, userSession,
|
|
|
882
826
|
switch (_a.label) {
|
|
883
827
|
case 0:
|
|
884
828
|
processStatus = 'removed';
|
|
885
|
-
return [4
|
|
829
|
+
return [4, objectql.getObject("process_instance_history").updateMany([['process_instance', '=', instanceId], ['step_status', '=', 'pending']], { step_status: processStatus, comments: comment })];
|
|
886
830
|
case 1:
|
|
887
831
|
_a.sent();
|
|
888
|
-
return [4
|
|
832
|
+
return [4, handleProcessInstanceNode(instanceId, null, processStatus, null, userSession)];
|
|
889
833
|
case 2:
|
|
890
834
|
_a.sent();
|
|
891
|
-
return [2
|
|
835
|
+
return [2];
|
|
892
836
|
}
|
|
893
837
|
});
|
|
894
838
|
}); };
|