@steedos/standard-process-approval 2.2.55-beta.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/main/default/applications/.gitkeep +0 -0
- package/main/default/applications/process_automation.app.yml +49 -0
- package/main/default/client/action_field_updates.client.js +155 -0
- package/main/default/client/core.client.js +134 -0
- package/main/default/client/process.client.js +211 -0
- package/main/default/client/process_node.client.js +36 -0
- package/main/default/client/workflow_notifications.client.js +74 -0
- package/main/default/objectTranslations/action_field_updates.en/action_field_updates.en.objectTranslation.yml +69 -0
- package/main/default/objectTranslations/action_field_updates.zh-CN/action_field_updates.zh-CN.objectTranslation.yml +72 -0
- package/main/default/objectTranslations/process_definition.en/process_definition.en.objectTranslation.yml +150 -0
- package/main/default/objectTranslations/process_definition.zh-CN/process_definition.zh-CN.objectTranslation.yml +145 -0
- package/main/default/objectTranslations/process_flows.en/process_flows.en.objectTranslation.yml +41 -0
- package/main/default/objectTranslations/process_flows.zh-CN/process_flows.zh-CN.objectTranslation.yml +41 -0
- package/main/default/objectTranslations/process_flows_criteria.en/process_flows_criteria.en.objectTranslation.yml +38 -0
- package/main/default/objectTranslations/process_flows_criteria.zh-CN/process_flows_criteria.zh-CN.objectTranslation.yml +38 -0
- package/main/default/objectTranslations/process_flows_criteria_action.en/process_flows_criteria_action.en.objectTranslation.yml +47 -0
- package/main/default/objectTranslations/process_flows_criteria_action.zh-CN/process_flows_criteria_action.zh-CN.objectTranslation.yml +47 -0
- package/main/default/objectTranslations/process_instance.en/process_instance.en.objectTranslation.yml +63 -0
- package/main/default/objectTranslations/process_instance.zh-CN/process_instance.zh-CN.objectTranslation.yml +63 -0
- package/main/default/objectTranslations/process_instance_history.en/process_instance_history.en.objectTranslation.yml +109 -0
- package/main/default/objectTranslations/process_instance_history.zh-CN/process_instance_history.zh-CN.objectTranslation.yml +109 -0
- package/main/default/objectTranslations/process_instance_node.en/process_instance_node.en.objectTranslation.yml +59 -0
- package/main/default/objectTranslations/process_instance_node.zh-CN/process_instance_node.zh-CN.objectTranslation.yml +59 -0
- package/main/default/objectTranslations/process_node.en/process_node.en.objectTranslation.yml +120 -0
- package/main/default/objectTranslations/process_node.zh-CN/process_node.zh-CN.objectTranslation.yml +116 -0
- package/main/default/objectTranslations/workflow_notifications.en/workflow_notifications.en.objectTranslation.yml +41 -0
- package/main/default/objectTranslations/workflow_notifications.zh-CN/workflow_notifications.zh-CN.objectTranslation.yml +44 -0
- package/main/default/objectTranslations/workflow_rule.en/workflow_rule.en.objectTranslation.yml +53 -0
- package/main/default/objectTranslations/workflow_rule.zh-CN/workflow_rule.zh-CN.objectTranslation.yml +60 -0
- package/main/default/objects/process/approval/process_definition.action.js +65 -0
- package/main/default/objects/process/approval/process_definition.function.js +39 -0
- package/main/default/objects/process/approval/process_definition.object.yml +313 -0
- package/main/default/objects/process/approval/process_node.object.yml +267 -0
- package/main/default/objects/process/flows/process_flows.object.yml +48 -0
- package/main/default/objects/process/flows/process_flows_criteria.object.yml +46 -0
- package/main/default/objects/process/flows/process_flows_criteria_action.object.yml +56 -0
- package/main/default/objects/process/process_instance/process_instance.object.yml +65 -0
- package/main/default/objects/process/process_instance/process_instance_history.action.js +26 -0
- package/main/default/objects/process/process_instance/process_instance_history.object.yml +153 -0
- package/main/default/objects/process/process_instance/process_instance_node.object.yml +59 -0
- package/main/default/objects/workflow-actions/action_field_updates.action.js +33 -0
- package/main/default/objects/workflow-actions/action_field_updates.object.yml +197 -0
- package/main/default/objects/workflow-actions/workflow_notifications.action.js +33 -0
- package/main/default/objects/workflow-actions/workflow_notifications.object.yml +107 -0
- package/main/default/objects/workflow-actions/workflow_rule.action.js +33 -0
- package/main/default/objects/workflow-actions/workflow_rule.object.yml +112 -0
- package/main/default/permissionsets/.gitkeep +0 -0
- package/main/default/profiles/.gitkeep +0 -0
- package/main/default/tabs/.gitkeep +0 -0
- package/main/default/triggers/.gitkeep +0 -0
- package/main/default/triggers/action_field_updates.trigger.js +175 -0
- package/main/default/triggers/process_definition.trigger.js +132 -0
- package/main/default/triggers/process_instance_history.trigger.js +42 -0
- package/main/default/triggers/process_node.trigger.js +232 -0
- package/main/default/triggers/workflow_notifications.trigger.js +236 -0
- package/main/default/triggers/workflow_rule.trigger.js +96 -0
- package/package.json +16 -0
- package/package.service.js +75 -0
- package/public/.md +3 -0
- package/src/.md +3 -0
- package/webapp/.md +1 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
const _ = require("underscore");
|
|
2
|
+
const util = require('@steedos/standard-objects').util;
|
|
3
|
+
const objectql = require("@steedos/objectql");
|
|
4
|
+
const InternalData = require('@steedos/standard-objects').internalData;
|
|
5
|
+
|
|
6
|
+
const checkReevaluateParent = (doc)=>{
|
|
7
|
+
if(doc.reevaluate_on_change && doc.target_object && doc.object_name && doc.target_object != doc.object_name){
|
|
8
|
+
throw new Error('action_field_updates_field__error_reevaluate_parent');
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const getInternalActionFieldUpdates = function(sourceActionFieldUpdates, filters){
|
|
13
|
+
let dbActionFieldUpdates = Creator.getCollection("action_field_updates").find(filters, {fields:{_id:1, name:1}}).fetch();
|
|
14
|
+
let actionFieldUpdates = [];
|
|
15
|
+
|
|
16
|
+
if(!filters.is_system){
|
|
17
|
+
_.forEach(sourceActionFieldUpdates, function(doc){
|
|
18
|
+
if(!_.find(dbActionFieldUpdates, function(p){
|
|
19
|
+
return p.name === doc.name
|
|
20
|
+
})){
|
|
21
|
+
actionFieldUpdates.push(doc);
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
return actionFieldUpdates;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
beforeInsert: async function () {
|
|
30
|
+
await util.checkAPIName(this.object_name, 'name', this.doc.name, undefined, [['is_system','!=', true]]);
|
|
31
|
+
checkReevaluateParent(this.doc);
|
|
32
|
+
},
|
|
33
|
+
beforeUpdate: async function () {
|
|
34
|
+
if (_.has(this.doc, 'name')) {
|
|
35
|
+
await util.checkAPIName(this.object_name, 'name', this.doc.name, this.id, [['is_system','!=', true]]);
|
|
36
|
+
}
|
|
37
|
+
checkReevaluateParent(this.doc);
|
|
38
|
+
},
|
|
39
|
+
afterFind: async function(){
|
|
40
|
+
let filters = InternalData.parserFilters(this.query.filters)
|
|
41
|
+
let actionFieldUpdates = [];
|
|
42
|
+
|
|
43
|
+
if(filters.name && filters.name.$in){
|
|
44
|
+
for(let name of filters.name.$in){
|
|
45
|
+
let actionFieldUpdate = objectql.getActionFieldUpdate(name);
|
|
46
|
+
if(actionFieldUpdate){
|
|
47
|
+
actionFieldUpdates.push(actionFieldUpdate);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}else if(filters._id && !filters._id.$ne){
|
|
51
|
+
let action = objectql.getActionFieldUpdate(filters._id);
|
|
52
|
+
if(action){
|
|
53
|
+
actionFieldUpdates.push(action);
|
|
54
|
+
}
|
|
55
|
+
}else if(filters.object_name){
|
|
56
|
+
actionFieldUpdates = objectql.getObjectActionFieldUpdates(filters.object_name);
|
|
57
|
+
delete filters.object_name;
|
|
58
|
+
}else{
|
|
59
|
+
actionFieldUpdates = objectql.getAllActionFieldUpdates();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if(filters._id && filters._id.$ne){
|
|
63
|
+
if(!_.isArray(filters._id.$ne)){
|
|
64
|
+
filters._id.$ne = [filters._id.$ne]
|
|
65
|
+
}
|
|
66
|
+
for(let neid of filters._id.$ne){
|
|
67
|
+
actionFieldUpdates = _.filter(actionFieldUpdates, function(item){
|
|
68
|
+
return item._id !== neid
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
actionFieldUpdates = getInternalActionFieldUpdates(actionFieldUpdates, filters);
|
|
74
|
+
|
|
75
|
+
if(actionFieldUpdates && actionFieldUpdates.length>0){
|
|
76
|
+
this.data.values = this.data.values.concat(actionFieldUpdates)
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
afterAggregate: async function(){
|
|
80
|
+
let filters = InternalData.parserFilters(this.query.filters)
|
|
81
|
+
let actionFieldUpdates = [];
|
|
82
|
+
|
|
83
|
+
if(filters.name && filters.name.$in){
|
|
84
|
+
for(let name of filters.name.$in){
|
|
85
|
+
let actionFieldUpdate = objectql.getActionFieldUpdate(name);
|
|
86
|
+
if(actionFieldUpdate){
|
|
87
|
+
actionFieldUpdates.push(actionFieldUpdate);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}else if(filters._id && !filters._id.$ne){
|
|
91
|
+
let action = objectql.getActionFieldUpdate(filters._id);
|
|
92
|
+
if(action){
|
|
93
|
+
actionFieldUpdates.push(action);
|
|
94
|
+
}
|
|
95
|
+
}else if(filters.object_name){
|
|
96
|
+
actionFieldUpdates = objectql.getObjectActionFieldUpdates(filters.object_name);
|
|
97
|
+
delete filters.object_name;
|
|
98
|
+
}else{
|
|
99
|
+
actionFieldUpdates = objectql.getAllActionFieldUpdates();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if(filters._id && filters._id.$ne){
|
|
103
|
+
if(!_.isArray(filters._id.$ne)){
|
|
104
|
+
filters._id.$ne = [filters._id.$ne]
|
|
105
|
+
}
|
|
106
|
+
for(let neid of filters._id.$ne){
|
|
107
|
+
actionFieldUpdates = _.filter(actionFieldUpdates, function(item){
|
|
108
|
+
return item._id !== neid
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
actionFieldUpdates = getInternalActionFieldUpdates(actionFieldUpdates, filters);
|
|
114
|
+
|
|
115
|
+
if(actionFieldUpdates && actionFieldUpdates.length>0){
|
|
116
|
+
this.data.values = this.data.values.concat(actionFieldUpdates)
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
afterCount: async function(){
|
|
120
|
+
let filters = InternalData.parserFilters(this.query.filters)
|
|
121
|
+
let actionFieldUpdates = [];
|
|
122
|
+
|
|
123
|
+
if(filters.name && filters.name.$in){
|
|
124
|
+
for(let name of filters.name.$in){
|
|
125
|
+
let actionFieldUpdate = objectql.getActionFieldUpdate(name);
|
|
126
|
+
if(actionFieldUpdate){
|
|
127
|
+
actionFieldUpdates.push(actionFieldUpdate);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}else if(filters._id && !filters._id.$ne){
|
|
131
|
+
let action = objectql.getActionFieldUpdate(filters._id);
|
|
132
|
+
if(action){
|
|
133
|
+
actionFieldUpdates.push(action);
|
|
134
|
+
}
|
|
135
|
+
}else if(filters.object_name){
|
|
136
|
+
actionFieldUpdates = objectql.getObjectActionFieldUpdates(filters.object_name);
|
|
137
|
+
delete filters.object_name;
|
|
138
|
+
}else{
|
|
139
|
+
actionFieldUpdates = objectql.getAllActionFieldUpdates();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if(filters._id && filters._id.$ne){
|
|
143
|
+
if(!_.isArray(filters._id.$ne)){
|
|
144
|
+
filters._id.$ne = [filters._id.$ne]
|
|
145
|
+
}
|
|
146
|
+
for(let neid of filters._id.$ne){
|
|
147
|
+
actionFieldUpdates = _.filter(actionFieldUpdates, function(item){
|
|
148
|
+
return item._id !== neid
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
actionFieldUpdates = getInternalActionFieldUpdates(actionFieldUpdates, filters);
|
|
154
|
+
|
|
155
|
+
if(actionFieldUpdates && actionFieldUpdates.length>0){
|
|
156
|
+
this.data.values = this.data.values + actionFieldUpdates.length
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
afterFindOne: async function(){
|
|
160
|
+
if(_.isEmpty(this.data.values)){
|
|
161
|
+
let id = this.id
|
|
162
|
+
|
|
163
|
+
let dbFieldUpdate = Creator.getCollection("action_field_updates").find({name: id}).fetch();
|
|
164
|
+
if(dbFieldUpdate && dbFieldUpdate.length > 0){
|
|
165
|
+
this.data.values = dbFieldUpdate[0];
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
let actionFieldUpdate = objectql.getActionFieldUpdate(id);
|
|
170
|
+
if(actionFieldUpdate){
|
|
171
|
+
this.data.values = actionFieldUpdate;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
const _ = require("underscore");
|
|
2
|
+
const util = require('@steedos/standard-objects').util;
|
|
3
|
+
const objectql = require('@steedos/objectql');
|
|
4
|
+
const InternalData = require('@steedos/standard-objects').internalData;
|
|
5
|
+
|
|
6
|
+
function setSpaceAndOwner(record, that){
|
|
7
|
+
record['space'] = that.spaceId
|
|
8
|
+
record['owner'] = that.userId
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const getInternalApprovalProcesses = function(sourceApprovalProcesses, filters){
|
|
12
|
+
delete filters.active;
|
|
13
|
+
let dbApprovalProcesses = Creator.getCollection("process_definition").find(filters, {fields:{_id:1, name:1}}).fetch();
|
|
14
|
+
let approvalProcesses = [];
|
|
15
|
+
|
|
16
|
+
if(!filters.is_system){
|
|
17
|
+
_.forEach(sourceApprovalProcesses, function(doc){
|
|
18
|
+
if(!_.find(dbApprovalProcesses, function(p){
|
|
19
|
+
return p.name === doc.name
|
|
20
|
+
})){
|
|
21
|
+
approvalProcesses.push(doc);
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
return approvalProcesses;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
beforeInsert: async function () {
|
|
30
|
+
await util.checkAPIName(this.object_name, 'name', this.doc.name, undefined, [['is_system','!=', true]]);
|
|
31
|
+
|
|
32
|
+
objectql.checkFormula(this.doc.entry_criteria, this.doc.object_name)
|
|
33
|
+
|
|
34
|
+
if(!this.doc.initial_submission_record_lock){
|
|
35
|
+
this.doc.initial_submission_record_lock = 'lock';
|
|
36
|
+
}
|
|
37
|
+
if(!this.doc.recall_record_lock){
|
|
38
|
+
this.doc.recall_record_lock = 'unlock';
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
beforeUpdate: async function () {
|
|
42
|
+
if(_.has(this.doc, 'object_name')){
|
|
43
|
+
var process = await objectql.getObject("process_definition").findOne(this.id);
|
|
44
|
+
if(process.object_name != this.doc.object_name){
|
|
45
|
+
throw new Error('禁止修改对象名称');
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
if (_.has(this.doc, 'name')) {
|
|
49
|
+
await util.checkAPIName(this.object_name, 'name', this.doc.name, this.id, [['is_system','!=', true]]);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
objectql.checkFormula(this.doc.entry_criteria, this.doc.object_name)
|
|
53
|
+
},
|
|
54
|
+
afterFind: async function(){
|
|
55
|
+
let filters = InternalData.parserFilters(this.query.filters)
|
|
56
|
+
let approvalProcesses = [];
|
|
57
|
+
if(filters.name){
|
|
58
|
+
approvalProcess = objectql.getSourceApprovalProcess(filters.name);
|
|
59
|
+
if(approvalProcess){
|
|
60
|
+
approvalProcesses.push(approvalProcess);
|
|
61
|
+
}
|
|
62
|
+
}else{
|
|
63
|
+
approvalProcesses = objectql.getSourceApprovalProcesses();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (filters.object_name){
|
|
67
|
+
approvalProcesses = _.where(approvalProcesses, {object_name: filters.object_name});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
approvalProcesses = getInternalApprovalProcesses(approvalProcesses, filters);
|
|
71
|
+
|
|
72
|
+
if(approvalProcesses){
|
|
73
|
+
this.data.values = this.data.values.concat(approvalProcesses)
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
afterAggregate: async function(){
|
|
77
|
+
let filters = InternalData.parserFilters(this.query.filters)
|
|
78
|
+
let approvalProcesses = [];
|
|
79
|
+
if(filters.name){
|
|
80
|
+
approvalProcess = objectql.getSourceApprovalProcess(filters.name);
|
|
81
|
+
if(approvalProcess){
|
|
82
|
+
approvalProcesses.push(approvalProcess);
|
|
83
|
+
}
|
|
84
|
+
}else{
|
|
85
|
+
approvalProcesses = objectql.getSourceApprovalProcesses();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (filters.object_name){
|
|
89
|
+
approvalProcesses = _.where(approvalProcesses, {object_name: filters.object_name});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
approvalProcesses = getInternalApprovalProcesses(approvalProcesses, filters);
|
|
93
|
+
|
|
94
|
+
if(approvalProcesses){
|
|
95
|
+
this.data.values = this.data.values.concat(approvalProcesses)
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
afterCount: async function(){
|
|
99
|
+
let filters = InternalData.parserFilters(this.query.filters)
|
|
100
|
+
let approvalProcesses = [];
|
|
101
|
+
if(filters.name){
|
|
102
|
+
approvalProcess = objectql.getSourceApprovalProcess(filters.name);
|
|
103
|
+
if(approvalProcess){
|
|
104
|
+
approvalProcesses.push(approvalProcess);
|
|
105
|
+
}
|
|
106
|
+
}else{
|
|
107
|
+
approvalProcesses = objectql.getSourceApprovalProcesses();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (filters.object_name){
|
|
111
|
+
approvalProcesses = _.where(approvalProcesses, {object_name: filters.object_name});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
approvalProcesses = getInternalApprovalProcesses(approvalProcesses, filters);
|
|
115
|
+
|
|
116
|
+
if(approvalProcesses){
|
|
117
|
+
this.data.values = this.data.values + approvalProcesses.length
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
afterFindOne: async function(){
|
|
121
|
+
if(_.isEmpty(this.data.values)){
|
|
122
|
+
let id = this.id
|
|
123
|
+
if(id){
|
|
124
|
+
let approvalProcess = objectql.getSourceApprovalProcess(id);
|
|
125
|
+
if(approvalProcess){
|
|
126
|
+
setSpaceAndOwner(approvalProcess, this);
|
|
127
|
+
this.data.values = approvalProcess;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const _ = require("underscore");
|
|
2
|
+
const auth = require("@steedos/auth");
|
|
3
|
+
|
|
4
|
+
const getLng = async function(userId){
|
|
5
|
+
const userSession = await auth.getSessionByUserId(userId);
|
|
6
|
+
return userSession ? userSession.language : null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const getEmptyNodeTitle = async function(userId){
|
|
10
|
+
let lng = await getLng(userId);
|
|
11
|
+
return TAPi18n.__('process_approval_empty_node_title', {}, lng);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
afterFindOne: async function () {
|
|
16
|
+
let userId = this.userId;
|
|
17
|
+
if(this.data.values && !this.data.values.step_node){
|
|
18
|
+
this.data.values.name = await getEmptyNodeTitle(userId);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
afterFind: async function () {
|
|
22
|
+
let userId = this.userId;
|
|
23
|
+
if(this.data.values){
|
|
24
|
+
for (const value of this.data.values) {
|
|
25
|
+
if(!value.step_node){
|
|
26
|
+
value.name = await getEmptyNodeTitle(userId);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
},
|
|
32
|
+
afterAggregate: async function () {
|
|
33
|
+
let userId = this.userId;
|
|
34
|
+
if(this.data.values){
|
|
35
|
+
for (const value of this.data.values) {
|
|
36
|
+
if(!value.step_node){
|
|
37
|
+
value.name = await getEmptyNodeTitle(userId);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
const _ = require("underscore");
|
|
2
|
+
const objectql = require('@steedos/objectql');
|
|
3
|
+
const util = require('@steedos/standard-objects').util;
|
|
4
|
+
const InternalData = require('@steedos/standard-objects').internalData;
|
|
5
|
+
|
|
6
|
+
function setSpaceAndOwner(record, that){
|
|
7
|
+
record['space'] = that.spaceId
|
|
8
|
+
record['owner'] = that.userId
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const reviseRecordOrder = async function (processId, record) {
|
|
13
|
+
let processNodes = await objectql.getObject("process_node").find({ filters: ['process_definition', '=', processId], sort: 'order asc' });
|
|
14
|
+
if (record) {
|
|
15
|
+
const recordOrder = record.order;
|
|
16
|
+
const recordId = record._id;
|
|
17
|
+
const afterNodes = _.filter(processNodes, function (node) {
|
|
18
|
+
if (node._id != recordId && node.order >= recordOrder) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
})
|
|
23
|
+
let _afterIndex = recordOrder + 1;
|
|
24
|
+
for (const processNode of afterNodes) {
|
|
25
|
+
await objectql.getObject("process_node").directUpdate(processNode._id, { order: _afterIndex });
|
|
26
|
+
_afterIndex++;
|
|
27
|
+
}
|
|
28
|
+
processNodes = await objectql.getObject("process_node").find({ filters: ['process_definition', '=', processId], sort: 'order asc' });
|
|
29
|
+
}
|
|
30
|
+
let _index = 1;
|
|
31
|
+
for (const processNode of processNodes) {
|
|
32
|
+
if (processNode.order != _index) {
|
|
33
|
+
await objectql.getObject("process_node").directUpdate(processNode._id, { order: _index });
|
|
34
|
+
}
|
|
35
|
+
_index++;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const processNodeFirst = await objectql.getObject("process_node").find({ filters: [['process_definition', '=', processId], ['order', '=', 1]] });
|
|
39
|
+
for (const processNode of processNodeFirst) {
|
|
40
|
+
if (processNode.reject_behavior != 'reject_request') {
|
|
41
|
+
await objectql.getObject("process_node").directUpdate(processNode._id, { reject_behavior: 'reject_request' });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const newProcessNodes = await objectql.getObject("process_node").find({ filters: ['process_definition', '=', processId], sort: 'order asc' });
|
|
46
|
+
for (const processNode of newProcessNodes) {
|
|
47
|
+
if (processNode.order != 1) {
|
|
48
|
+
if(processNode.order == newProcessNodes.length){
|
|
49
|
+
if(processNode.if_criteria_not_met != 'approve'){
|
|
50
|
+
await objectql.getObject("process_node").directUpdate(processNode._id, { if_criteria_not_met: 'approve' });
|
|
51
|
+
}
|
|
52
|
+
}else{
|
|
53
|
+
if(processNode.if_criteria_not_met === 'reject'){
|
|
54
|
+
await objectql.getObject("process_node").directUpdate(processNode._id, { if_criteria_not_met: 'approve' });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const allowChange = async function(processId){
|
|
62
|
+
if(processId){
|
|
63
|
+
var process = await objectql.getObject("process_definition").findOne(processId);
|
|
64
|
+
if(process){
|
|
65
|
+
if(process.active){
|
|
66
|
+
return false;
|
|
67
|
+
}else{
|
|
68
|
+
var processInstancesCount = await objectql.getObject('process_instance').count({filters: ['process_definition', '=', processId]});
|
|
69
|
+
if(processInstancesCount > 0){
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return true
|
|
74
|
+
}else{
|
|
75
|
+
throw new Error('未找到批准过程');
|
|
76
|
+
}
|
|
77
|
+
}else{
|
|
78
|
+
throw new Error('未找到批准过程');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const allowEdit = async function(recordId, doc){
|
|
83
|
+
var unAllowEditFields = ['process_definition', 'filtrad', 'entry_criteria', 'if_criteria_not_met', 'reject_behavior'];
|
|
84
|
+
var record = await objectql.getObject('process_node').findOne(recordId);
|
|
85
|
+
if(record){
|
|
86
|
+
if(!(await allowChange(record.process_definition))){
|
|
87
|
+
_.each(unAllowEditFields, function(fieldName){
|
|
88
|
+
if(_.has(doc, fieldName) && doc[fieldName] != record[fieldName]){
|
|
89
|
+
throw new Error('批准过程已启用或者已提交过审批,不能修改审批步骤的批准过程、步骤条件、拒绝行为');
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const getProcessNodeObjectName = async function(processId){
|
|
97
|
+
const process = await objectql.getObject("process_definition").findOne(processId);
|
|
98
|
+
if(process){
|
|
99
|
+
return process.object_name
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
module.exports = {
|
|
104
|
+
beforeInsert: async function () {
|
|
105
|
+
|
|
106
|
+
if(!(await allowChange(this.doc.process_definition)))
|
|
107
|
+
{
|
|
108
|
+
throw new Error('批准过程已启用或者已提交过审批, 禁止添加、删除批准步骤');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (this.doc.order === 1) {
|
|
112
|
+
this.doc.reject_behavior = 'reject_request'
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (this.doc.order != 1 && this.doc.if_criteria_not_met === 'reject') {
|
|
116
|
+
throw new Error('仅第一个步骤的不满足条件可以为拒绝记录');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (this.doc.order === 1) {
|
|
120
|
+
this.doc.reject_behavior = 'reject_request';
|
|
121
|
+
}
|
|
122
|
+
await util.checkAPIName(this.object_name, 'name', this.doc.name, null, [['process_definition', '=', this.doc.process_definition]]);
|
|
123
|
+
if(!this.doc.filtrad){
|
|
124
|
+
const objectName = await getProcessNodeObjectName(this.doc.process_definition);
|
|
125
|
+
if(objectName){
|
|
126
|
+
objectql.checkFormula(this.doc.entry_criteria, objectName)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
},
|
|
131
|
+
afterInsert: async function () {
|
|
132
|
+
await reviseRecordOrder(this.doc.process_definition, this.doc);
|
|
133
|
+
},
|
|
134
|
+
beforeUpdate: async function () {
|
|
135
|
+
|
|
136
|
+
await allowEdit(this.id, this.doc);
|
|
137
|
+
|
|
138
|
+
if (this.doc.order === 1) {
|
|
139
|
+
this.doc.reject_behavior = 'reject_request'
|
|
140
|
+
}
|
|
141
|
+
if (_.has(this.doc, 'process_definition')) {
|
|
142
|
+
const record = await objectql.getObject("process_node").findOne(this.id)
|
|
143
|
+
if (record.process_definition != this.doc.process_definition) {
|
|
144
|
+
throw new Error('禁止修改 批准过程 字段');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (_.has(this.doc, 'name')) {
|
|
148
|
+
await util.checkAPIName(this.object_name, 'name', this.doc.name, this.id, [['process_definition', '=', this.doc.process_definition]]);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if(!this.doc.filtrad && this.doc.process_definition){
|
|
152
|
+
const objectName = await getProcessNodeObjectName(this.doc.process_definition);
|
|
153
|
+
if(objectName){
|
|
154
|
+
objectql.checkFormula(this.doc.entry_criteria, objectName)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
afterUpdate: async function () {
|
|
159
|
+
const record = await objectql.getObject("process_node").findOne(this.id)
|
|
160
|
+
await reviseRecordOrder(record.process_definition, record);
|
|
161
|
+
},
|
|
162
|
+
beforeDelete: async function(){
|
|
163
|
+
let doc = await objectql.getObject('process_node').findOne(this.id);
|
|
164
|
+
if(!(await allowChange(doc.process_definition)))
|
|
165
|
+
{
|
|
166
|
+
throw new Error('批准过程已启用或者已提交过审批, 禁止添加、删除批准步骤');
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
afterDelete: async function () {
|
|
170
|
+
await reviseRecordOrder(this.previousDoc.process_definition);
|
|
171
|
+
},
|
|
172
|
+
afterFind: async function(){
|
|
173
|
+
let filters = InternalData.parserFilters(this.query.filters)
|
|
174
|
+
let processNodes = [];
|
|
175
|
+
if(filters.process_definition){
|
|
176
|
+
approvalProcess = objectql.getSourceApprovalProcess(filters.process_definition);
|
|
177
|
+
if(approvalProcess){
|
|
178
|
+
processNodes = approvalProcess.process_nodes
|
|
179
|
+
}
|
|
180
|
+
delete filters.process_definition
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if(processNodes){
|
|
184
|
+
for(let node of processNodes){
|
|
185
|
+
setSpaceAndOwner(node, this);
|
|
186
|
+
}
|
|
187
|
+
this.data.values = this.data.values.concat(processNodes)
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
afterAggregate: async function(){
|
|
191
|
+
let filters = InternalData.parserFilters(this.query.filters)
|
|
192
|
+
let processNodes = [];
|
|
193
|
+
if(filters.process_definition){
|
|
194
|
+
approvalProcess = objectql.getSourceApprovalProcess(filters.process_definition);
|
|
195
|
+
if(approvalProcess){
|
|
196
|
+
processNodes = approvalProcess.process_nodes
|
|
197
|
+
}
|
|
198
|
+
delete filters.process_definition
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if(processNodes){
|
|
202
|
+
this.data.values = this.data.values.concat(processNodes)
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
afterCount: async function(){
|
|
206
|
+
let filters = InternalData.parserFilters(this.query.filters)
|
|
207
|
+
let processNodes = [];
|
|
208
|
+
if(filters.process_definition){
|
|
209
|
+
approvalProcess = objectql.getSourceApprovalProcess(filters.process_definition);
|
|
210
|
+
if(approvalProcess){
|
|
211
|
+
processNodes = approvalProcess.process_nodes
|
|
212
|
+
}
|
|
213
|
+
delete filters.process_definition
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if(processNodes){
|
|
217
|
+
this.data.values = this.data.values + processNodes.length
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
afterFindOne: async function(){
|
|
221
|
+
if(_.isEmpty(this.data.values)){
|
|
222
|
+
let id = this.id
|
|
223
|
+
let objectName = id.substr(0, id.indexOf("."));
|
|
224
|
+
if(objectName){
|
|
225
|
+
let processNode = objectql.getSourceProcessNode(objectName, id.substr(id.indexOf(".")+1));
|
|
226
|
+
if(processNode){
|
|
227
|
+
this.data.values = processNode;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|