@tachybase/plugin-workflow-approval 1.6.0 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/base/ApprovalPane.schema.d.ts +9 -3
- package/dist/client/common/tools/cleanAssociationIds.d.ts +9 -0
- package/dist/client/index.js +29 -65
- package/dist/externalVersion.js +7 -7
- package/dist/locale/en-US.json +2 -1
- package/dist/locale/zh-CN.json +2 -1
- package/dist/server/actions/approvalCarbonCopy.d.ts +1 -1
- package/dist/server/actions/approvalCarbonCopy.js +7 -7
- package/dist/server/actions/approvalRecords.d.ts +2 -2
- package/dist/server/actions/approvalRecords.js +19 -19
- package/dist/server/actions/approvals.d.ts +6 -6
- package/dist/server/actions/approvals.js +61 -82
- package/dist/server/actions/index.js +1 -1
- package/dist/server/actions/workflows.d.ts +1 -1
- package/dist/server/actions/workflows.js +3 -3
- package/dist/server/plugin.js +0 -3
- package/dist/server/triggers/Approval.d.ts +3 -3
- package/dist/server/triggers/Approval.js +35 -21
- package/dist/server/utils.d.ts +2 -2
- package/dist/server/utils.js +4 -4
- package/package.json +9 -9
package/dist/externalVersion.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
"@tachybase/client": "1.6.
|
|
3
|
-
"@tego/server": "1.
|
|
4
|
-
"@tachybase/module-workflow": "1.6.
|
|
2
|
+
"@tachybase/client": "1.6.3",
|
|
3
|
+
"@tego/server": "1.6.1",
|
|
4
|
+
"@tachybase/module-workflow": "1.6.3",
|
|
5
5
|
"lodash": "4.17.21",
|
|
6
6
|
"react": "18.3.1",
|
|
7
|
-
"@tachybase/schema": "1.
|
|
7
|
+
"@tachybase/schema": "1.6.1",
|
|
8
8
|
"antd": "5.22.5",
|
|
9
|
-
"@tachybase/module-ui-schema": "1.6.
|
|
9
|
+
"@tachybase/module-ui-schema": "1.6.3",
|
|
10
10
|
"sequelize": "6.37.5",
|
|
11
|
-
"@tego/client": "1.
|
|
11
|
+
"@tego/client": "1.6.1",
|
|
12
12
|
"react-i18next": "16.2.1",
|
|
13
13
|
"react-router-dom": "6.28.1",
|
|
14
|
-
"@ant-design/icons": "
|
|
14
|
+
"@ant-design/icons": "6.1.0",
|
|
15
15
|
"dayjs": "1.11.13",
|
|
16
16
|
"ahooks": "3.9.0"
|
|
17
17
|
};
|
package/dist/locale/en-US.json
CHANGED
|
@@ -196,7 +196,7 @@
|
|
|
196
196
|
"Notice Center": "Notice Center",
|
|
197
197
|
"Notice blocks": "Notice blocks",
|
|
198
198
|
"Null": "Null",
|
|
199
|
-
"Off": "
|
|
199
|
+
"Off": "Disabled",
|
|
200
200
|
"On": "On",
|
|
201
201
|
"On going": "On going",
|
|
202
202
|
"Only support standard JSON data": "Only support standard JSON data",
|
|
@@ -286,6 +286,7 @@
|
|
|
286
286
|
"Unprocessed": "Unprocessed",
|
|
287
287
|
"Update record": "Update record",
|
|
288
288
|
"Update record form": "Update record form",
|
|
289
|
+
"Updated time": "Updated time",
|
|
289
290
|
"Usage of SQL query result is not supported yet.": "Usage of SQL query result is not supported yet.",
|
|
290
291
|
"Use a collection to match form data.": "Use a collection to match form data.",
|
|
291
292
|
"Use variable": "Use variable",
|
package/dist/locale/zh-CN.json
CHANGED
|
@@ -234,7 +234,7 @@
|
|
|
234
234
|
"Notice": "通知",
|
|
235
235
|
"Notice Center": "通知中心",
|
|
236
236
|
"Notice blocks": "通知卡片",
|
|
237
|
-
"Off": "
|
|
237
|
+
"Off": "禁用",
|
|
238
238
|
"On": "启用",
|
|
239
239
|
"On going": "进行中",
|
|
240
240
|
"Only support standard JSON data": "仅支持标准 JSON 数据",
|
|
@@ -357,6 +357,7 @@
|
|
|
357
357
|
"Update record": "更新数据",
|
|
358
358
|
"Update record form": "更新数据表单",
|
|
359
359
|
"Update records of a collection. You can use variables from upstream nodes as query conditions and field values.": "更新一个数据表中的数据。可以使用上游节点里的变量作为查询条件和数据值。",
|
|
360
|
+
"Updated time": "更新时间",
|
|
360
361
|
"Use transaction": "启用事务",
|
|
361
362
|
"Use variable": "使用变量",
|
|
362
363
|
"Used to store expressions for use in workflows so that different expressions can be called for different data.": "用于存储表达式,在工作流中使用,以便针对不同的数据调用不同的表达式。",
|
|
@@ -25,15 +25,15 @@ var import_server = require("@tego/server");
|
|
|
25
25
|
var import_status = require("../constants/status");
|
|
26
26
|
var import_utils = require("../utils");
|
|
27
27
|
const approvalCarbonCopy = {
|
|
28
|
-
async listCentralized(
|
|
29
|
-
const centralizedApprovalFlow = await
|
|
28
|
+
async listCentralized(ctx, next) {
|
|
29
|
+
const centralizedApprovalFlow = await ctx.db.getRepository(import_module_workflow.COLLECTION_WORKFLOWS_NAME).find({
|
|
30
30
|
filter: {
|
|
31
31
|
type: "approval",
|
|
32
32
|
"config.centralized": true
|
|
33
33
|
},
|
|
34
34
|
fields: ["id"]
|
|
35
35
|
});
|
|
36
|
-
|
|
36
|
+
ctx.action.mergeParams({
|
|
37
37
|
filter: {
|
|
38
38
|
workflowId: centralizedApprovalFlow.map((item) => item.id),
|
|
39
39
|
approval: {
|
|
@@ -43,10 +43,10 @@ const approvalCarbonCopy = {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
|
-
await import_server.actions.list(
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
await import_server.actions.list(ctx, next);
|
|
47
|
+
if (ctx.body.rows) {
|
|
48
|
+
ctx.body.rows = (0, import_utils.findUniqueObjects)(
|
|
49
|
+
ctx.body.rows,
|
|
50
50
|
["userId", "approvalId"],
|
|
51
51
|
"createdAt",
|
|
52
52
|
(a, b) => new Date(a).getTime() - new Date(b).getTime()
|
|
@@ -25,29 +25,29 @@ var import_server = require("@tego/server");
|
|
|
25
25
|
var import_error_code = require("../constants/error-code");
|
|
26
26
|
var import_status = require("../constants/status");
|
|
27
27
|
const approvalRecords = {
|
|
28
|
-
async listCentralized(
|
|
29
|
-
const centralizedApprovalFlow = await
|
|
28
|
+
async listCentralized(ctx, next) {
|
|
29
|
+
const centralizedApprovalFlow = await ctx.db.getRepository("workflows").find({
|
|
30
30
|
filter: {
|
|
31
31
|
type: "approval",
|
|
32
32
|
"config.centralized": true
|
|
33
33
|
},
|
|
34
34
|
fields: ["id"]
|
|
35
35
|
});
|
|
36
|
-
|
|
36
|
+
ctx.action.mergeParams({
|
|
37
37
|
filter: {
|
|
38
38
|
workflowId: centralizedApprovalFlow.map((item) => item.id)
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
|
-
return import_server.actions.list(
|
|
41
|
+
return import_server.actions.list(ctx, next);
|
|
42
42
|
},
|
|
43
|
-
async submit(
|
|
43
|
+
async submit(ctx, next) {
|
|
44
44
|
var _a, _b;
|
|
45
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
46
|
-
const { filterByTk, values } =
|
|
45
|
+
const repository = import_server.utils.getRepositoryFromParams(ctx);
|
|
46
|
+
const { filterByTk, values } = ctx.action.params;
|
|
47
47
|
const { data, status, needUpdateRecord } = values || {};
|
|
48
|
-
const { currentUser } =
|
|
48
|
+
const { currentUser } = ctx.state;
|
|
49
49
|
if (!currentUser) {
|
|
50
|
-
return
|
|
50
|
+
return ctx.throw(401);
|
|
51
51
|
}
|
|
52
52
|
const approvalRecord = await repository.findOne({
|
|
53
53
|
filterByTk,
|
|
@@ -55,22 +55,22 @@ const approvalRecords = {
|
|
|
55
55
|
userId: currentUser == null ? void 0 : currentUser.id
|
|
56
56
|
},
|
|
57
57
|
appends: ["job", "node", "execution", "workflow", "approval"],
|
|
58
|
-
context
|
|
58
|
+
context: ctx
|
|
59
59
|
});
|
|
60
60
|
if (!approvalRecord) {
|
|
61
|
-
return
|
|
61
|
+
return ctx.throw(404);
|
|
62
62
|
}
|
|
63
63
|
switch (true) {
|
|
64
64
|
// case !approvalRecord.workflow.enabled:
|
|
65
|
-
// return
|
|
65
|
+
// return ctx.throw(400, ERROR_CODE_MAP['not_enable_workflow']);
|
|
66
66
|
case ((_a = approvalRecord.execution) == null ? void 0 : _a.status):
|
|
67
|
-
return
|
|
67
|
+
return ctx.throw(400, import_error_code.ERROR_CODE_MAP["execution_finished"]);
|
|
68
68
|
case ((_b = approvalRecord.job) == null ? void 0 : _b.status):
|
|
69
|
-
return
|
|
69
|
+
return ctx.throw(400, import_error_code.ERROR_CODE_MAP["job_finished"]);
|
|
70
70
|
case approvalRecord.status !== import_status.APPROVAL_ACTION_STATUS.PENDING:
|
|
71
|
-
return
|
|
71
|
+
return ctx.throw(400, import_error_code.ERROR_CODE_MAP["not_approval_pending"]);
|
|
72
72
|
case (!needUpdateRecord && !(approvalRecord.node.config.actions ?? []).includes(status)):
|
|
73
|
-
return
|
|
73
|
+
return ctx.throw(400, import_error_code.ERROR_CODE_MAP["not_need_update"]);
|
|
74
74
|
default:
|
|
75
75
|
break;
|
|
76
76
|
}
|
|
@@ -81,13 +81,13 @@ const approvalRecords = {
|
|
|
81
81
|
summary: approvalRecord.approval.summary,
|
|
82
82
|
collectionName: approvalRecord.approval.collectionName
|
|
83
83
|
});
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
ctx.body = approvalRecord.get();
|
|
85
|
+
ctx.status = 202;
|
|
86
86
|
await next();
|
|
87
87
|
approvalRecord.execution.workflow = approvalRecord.workflow;
|
|
88
88
|
approvalRecord.job.execution = approvalRecord.execution;
|
|
89
89
|
approvalRecord.job.latestUserJob = approvalRecord.get();
|
|
90
|
-
const workflow =
|
|
90
|
+
const workflow = ctx.tego.pm.get(import_module_workflow.PluginWorkflow);
|
|
91
91
|
const processor = workflow.createProcessor(approvalRecord.execution);
|
|
92
92
|
processor.logger.info(
|
|
93
93
|
`approval node (${approvalRecord.nodeId}) action trigger execution (${approvalRecord.execution.id}) to resume`
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare const approvals: {
|
|
2
|
-
create(
|
|
3
|
-
update(
|
|
4
|
-
destroy(
|
|
5
|
-
withdraw(
|
|
6
|
-
listCentralized(
|
|
7
|
-
reminder(
|
|
2
|
+
create(ctx: any, next: any): Promise<any>;
|
|
3
|
+
update(ctx: any, next: any): Promise<void>;
|
|
4
|
+
destroy(ctx: any, next: any): Promise<any>;
|
|
5
|
+
withdraw(ctx: any, next: any): Promise<any>;
|
|
6
|
+
listCentralized(ctx: any, next: any): Promise<void>;
|
|
7
|
+
reminder(ctx: any, next: any): Promise<any>;
|
|
8
8
|
};
|
|
@@ -26,69 +26,48 @@ var import_constants = require("../../common/constants");
|
|
|
26
26
|
var import_status = require("../constants/status");
|
|
27
27
|
var import_tools = require("../tools");
|
|
28
28
|
const approvals = {
|
|
29
|
-
async create(
|
|
30
|
-
const { status, collectionName, data, workflowId, workflowKey } =
|
|
29
|
+
async create(ctx, next) {
|
|
30
|
+
const { status, collectionName, data, workflowId, workflowKey } = ctx.action.params.values ?? {};
|
|
31
31
|
const [dataSourceName, cName] = (0, import_server.parseCollectionName)(collectionName);
|
|
32
|
-
const dataSource =
|
|
32
|
+
const dataSource = ctx.tego.dataSourceManager.dataSources.get(dataSourceName);
|
|
33
33
|
if (!dataSource) {
|
|
34
|
-
return
|
|
34
|
+
return ctx.throw(400, `Data source "${dataSourceName}" not found`);
|
|
35
35
|
}
|
|
36
36
|
const collection = dataSource.collectionManager.getCollection(cName);
|
|
37
37
|
if (!collection) {
|
|
38
|
-
return
|
|
38
|
+
return ctx.throw(400, `Collection "${cName}" not found`);
|
|
39
39
|
}
|
|
40
40
|
let workflow;
|
|
41
41
|
if (workflowKey) {
|
|
42
|
-
workflow = await
|
|
42
|
+
workflow = await ctx.db.getRepository("workflows").findOne({
|
|
43
43
|
filter: {
|
|
44
44
|
key: workflowKey,
|
|
45
45
|
enabled: true
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
} else {
|
|
49
|
-
workflow = await
|
|
49
|
+
workflow = await ctx.db.getRepository("workflows").findOne({
|
|
50
50
|
filterByTk: workflowId
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
if (!workflow) {
|
|
54
|
-
return
|
|
54
|
+
return ctx.throw(400, "Current workflow not found or disabled, please refresh and try again");
|
|
55
55
|
}
|
|
56
56
|
if (status !== import_status.APPROVAL_STATUS.DRAFT) {
|
|
57
|
-
|
|
57
|
+
ctx.action.mergeParams({
|
|
58
58
|
values: {
|
|
59
59
|
status: import_status.APPROVAL_STATUS.SUBMITTED
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
const { repository, model } = collection;
|
|
64
|
-
let dataToCreate = (0, import_server.traverseJSON)(data, { collection });
|
|
65
|
-
if (workflowKey) {
|
|
66
|
-
Object.values(collection.model.associations || {}).forEach((assocUnknown) => {
|
|
67
|
-
var _a, _b;
|
|
68
|
-
const assoc = assocUnknown;
|
|
69
|
-
if (assoc.foreignKey && Object.prototype.hasOwnProperty.call(dataToCreate, assoc.foreignKey)) {
|
|
70
|
-
delete dataToCreate[assoc.foreignKey];
|
|
71
|
-
}
|
|
72
|
-
if (assoc.associationType === "BelongsToMany" && assoc.as && Array.isArray(dataToCreate[assoc.as])) {
|
|
73
|
-
const targetKey = assoc.targetKey && typeof assoc.targetKey === "string" ? assoc.targetKey : (
|
|
74
|
-
// fallback: 一般为 target model 的主键
|
|
75
|
-
((_a = assoc.target) == null ? void 0 : _a.primaryKeyAttribute) || ((_b = assoc.target) == null ? void 0 : _b.primaryKey) || "id"
|
|
76
|
-
);
|
|
77
|
-
dataToCreate[assoc.as].forEach((item) => {
|
|
78
|
-
if (item && typeof item === "object" && Object.prototype.hasOwnProperty.call(item, targetKey)) {
|
|
79
|
-
delete item[targetKey];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
64
|
const values = await repository.create({
|
|
86
65
|
values: {
|
|
87
|
-
...
|
|
88
|
-
createdBy:
|
|
89
|
-
updatedBy:
|
|
66
|
+
...(0, import_server.traverseJSON)(data, { collection }),
|
|
67
|
+
createdBy: ctx.state.currentUser.id,
|
|
68
|
+
updatedBy: ctx.state.currentUser.id
|
|
90
69
|
},
|
|
91
|
-
context
|
|
70
|
+
context: ctx
|
|
92
71
|
});
|
|
93
72
|
const instance = values.get();
|
|
94
73
|
const summary = (0, import_tools.getSummary)({
|
|
@@ -98,28 +77,28 @@ const approvals = {
|
|
|
98
77
|
...data
|
|
99
78
|
},
|
|
100
79
|
collection,
|
|
101
|
-
app:
|
|
80
|
+
app: ctx.tego
|
|
102
81
|
});
|
|
103
82
|
Object.keys(model.associations).forEach((key) => {
|
|
104
83
|
delete instance[key];
|
|
105
84
|
});
|
|
106
|
-
|
|
85
|
+
ctx.action.mergeParams({
|
|
107
86
|
values: {
|
|
108
87
|
collectionName,
|
|
109
88
|
data: instance,
|
|
110
89
|
dataKey: values[collection.filterTargetKey],
|
|
111
90
|
workflowKey: workflow.key,
|
|
112
91
|
workflowId: workflow.id,
|
|
113
|
-
applicantRoleName:
|
|
92
|
+
applicantRoleName: ctx.state.currentRole,
|
|
114
93
|
summary
|
|
115
94
|
}
|
|
116
95
|
});
|
|
117
|
-
return import_server.actions.create(
|
|
96
|
+
return import_server.actions.create(ctx, next);
|
|
118
97
|
},
|
|
119
|
-
async update(
|
|
120
|
-
const { collectionName, data, status, updateAssociationValues, summaryConfig } =
|
|
98
|
+
async update(ctx, next) {
|
|
99
|
+
const { collectionName, data, status, updateAssociationValues, summaryConfig } = ctx.action.params.values ?? {};
|
|
121
100
|
const [dataSourceName, cName] = (0, import_server.parseCollectionName)(collectionName);
|
|
122
|
-
const dataSource =
|
|
101
|
+
const dataSource = ctx.tego.dataSourceManager.dataSources.get(dataSourceName);
|
|
123
102
|
const collection = dataSource.collectionManager.getCollection(cName);
|
|
124
103
|
const [target] = await collection.repository.update({
|
|
125
104
|
filterByTk: data[collection.filterTargetKey],
|
|
@@ -130,55 +109,55 @@ const approvals = {
|
|
|
130
109
|
summaryConfig,
|
|
131
110
|
data,
|
|
132
111
|
collection,
|
|
133
|
-
app:
|
|
112
|
+
app: ctx.tego
|
|
134
113
|
});
|
|
135
|
-
|
|
114
|
+
ctx.action.mergeParams({
|
|
136
115
|
values: {
|
|
137
116
|
status: status ?? import_status.APPROVAL_STATUS.SUBMITTED,
|
|
138
117
|
data,
|
|
139
|
-
applicantRoleName:
|
|
118
|
+
applicantRoleName: ctx.state.currentRole,
|
|
140
119
|
summary
|
|
141
120
|
}
|
|
142
121
|
});
|
|
143
|
-
return import_server.actions.update(
|
|
122
|
+
return import_server.actions.update(ctx, next);
|
|
144
123
|
},
|
|
145
|
-
async destroy(
|
|
124
|
+
async destroy(ctx, next) {
|
|
146
125
|
const {
|
|
147
126
|
filterByTk,
|
|
148
127
|
values: { status }
|
|
149
|
-
} =
|
|
128
|
+
} = ctx.action.params ?? {};
|
|
150
129
|
if (status !== import_status.APPROVAL_STATUS.DRAFT) {
|
|
151
|
-
return
|
|
130
|
+
return ctx.throw(400);
|
|
152
131
|
}
|
|
153
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
132
|
+
const repository = import_server.utils.getRepositoryFromParams(ctx);
|
|
154
133
|
const approval = await repository.findOne({
|
|
155
134
|
filterByTk,
|
|
156
135
|
filter: {
|
|
157
|
-
createdById:
|
|
136
|
+
createdById: ctx.state.currentUser.id
|
|
158
137
|
}
|
|
159
138
|
});
|
|
160
139
|
if (!approval) {
|
|
161
|
-
return
|
|
140
|
+
return ctx.throw(404);
|
|
162
141
|
}
|
|
163
|
-
return import_server.actions.destroy(
|
|
142
|
+
return import_server.actions.destroy(ctx, next);
|
|
164
143
|
},
|
|
165
|
-
async withdraw(
|
|
144
|
+
async withdraw(ctx, next) {
|
|
166
145
|
var _a, _b;
|
|
167
|
-
const { filterByTk } =
|
|
168
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
146
|
+
const { filterByTk } = ctx.action.params;
|
|
147
|
+
const repository = import_server.utils.getRepositoryFromParams(ctx);
|
|
169
148
|
const approval = await repository.findOne({
|
|
170
149
|
filterByTk,
|
|
171
150
|
appends: ["workflow"],
|
|
172
151
|
except: ["workflow.options"]
|
|
173
152
|
});
|
|
174
153
|
if (!approval) {
|
|
175
|
-
return
|
|
154
|
+
return ctx.throw(404);
|
|
176
155
|
}
|
|
177
|
-
if (approval.createdById !== ((_a =
|
|
178
|
-
return
|
|
156
|
+
if (approval.createdById !== ((_a = ctx.state.currentUser) == null ? void 0 : _a.id)) {
|
|
157
|
+
return ctx.throw(403);
|
|
179
158
|
}
|
|
180
159
|
if (approval.status !== import_status.APPROVAL_STATUS.SUBMITTED || !approval.workflow.config.withdrawable) {
|
|
181
|
-
return
|
|
160
|
+
return ctx.throw(400);
|
|
182
161
|
}
|
|
183
162
|
const [execution] = await approval.getExecutions({
|
|
184
163
|
where: {
|
|
@@ -187,10 +166,10 @@ const approvals = {
|
|
|
187
166
|
limit: 1
|
|
188
167
|
});
|
|
189
168
|
if (!execution) {
|
|
190
|
-
return
|
|
169
|
+
return ctx.throw(404, "Execution not found! Please contact the administrator.");
|
|
191
170
|
}
|
|
192
171
|
if (!approval.workflow.enabled && ((_b = approval.workflow) == null ? void 0 : _b.key)) {
|
|
193
|
-
const latestWorkflow = await
|
|
172
|
+
const latestWorkflow = await ctx.db.getRepository("workflows").findOne({
|
|
194
173
|
filter: {
|
|
195
174
|
key: approval.workflow.key,
|
|
196
175
|
enabled: true
|
|
@@ -204,13 +183,13 @@ const approvals = {
|
|
|
204
183
|
workflowId: latestWorkflow.id
|
|
205
184
|
},
|
|
206
185
|
{
|
|
207
|
-
transaction:
|
|
186
|
+
transaction: ctx.transaction
|
|
208
187
|
}
|
|
209
188
|
);
|
|
210
189
|
}
|
|
211
190
|
}
|
|
212
191
|
execution.workflow = approval.workflow;
|
|
213
|
-
await
|
|
192
|
+
await ctx.db.sequelize.transaction(async (transaction) => {
|
|
214
193
|
const records = await approval.getRecords({
|
|
215
194
|
where: {
|
|
216
195
|
executionId: execution.id
|
|
@@ -226,7 +205,7 @@ const approvals = {
|
|
|
226
205
|
],
|
|
227
206
|
transaction
|
|
228
207
|
});
|
|
229
|
-
await
|
|
208
|
+
await ctx.db.getRepository("approvalRecords").destroy({
|
|
230
209
|
filter: {
|
|
231
210
|
id: records.map((record) => record.id)
|
|
232
211
|
},
|
|
@@ -243,52 +222,52 @@ const approvals = {
|
|
|
243
222
|
}, /* @__PURE__ */ new Map());
|
|
244
223
|
return Array.from(jobsMap.values());
|
|
245
224
|
});
|
|
246
|
-
|
|
247
|
-
|
|
225
|
+
ctx.body = approval;
|
|
226
|
+
ctx.status = 202;
|
|
248
227
|
await next();
|
|
249
228
|
await execution.update({
|
|
250
229
|
status: import_module_workflow.EXECUTION_STATUS.CANCELED
|
|
251
230
|
});
|
|
252
231
|
},
|
|
253
|
-
async listCentralized(
|
|
254
|
-
const centralizedApprovalFlow = await
|
|
232
|
+
async listCentralized(ctx, next) {
|
|
233
|
+
const centralizedApprovalFlow = await ctx.db.getRepository("workflows").find({
|
|
255
234
|
filter: {
|
|
256
235
|
type: "approval",
|
|
257
236
|
"config.centralized": true
|
|
258
237
|
},
|
|
259
238
|
fields: ["id"]
|
|
260
239
|
});
|
|
261
|
-
|
|
240
|
+
ctx.action.mergeParams({
|
|
262
241
|
filter: {
|
|
263
242
|
workflowId: centralizedApprovalFlow.map((item) => item.id)
|
|
264
243
|
}
|
|
265
244
|
});
|
|
266
|
-
return await import_server.actions.list(
|
|
245
|
+
return await import_server.actions.list(ctx, next);
|
|
267
246
|
},
|
|
268
|
-
async reminder(
|
|
247
|
+
async reminder(ctx, next) {
|
|
269
248
|
var _a, _b, _c;
|
|
270
|
-
const { filterByTk } =
|
|
271
|
-
const repository = import_server.utils.getRepositoryFromParams(
|
|
249
|
+
const { filterByTk } = ctx.action.params;
|
|
250
|
+
const repository = import_server.utils.getRepositoryFromParams(ctx);
|
|
272
251
|
const approval = await repository.findOne({
|
|
273
252
|
filterByTk,
|
|
274
253
|
appends: ["records", "workflow", "createdBy.nickname"]
|
|
275
254
|
});
|
|
276
255
|
if (!approval) {
|
|
277
|
-
return
|
|
256
|
+
return ctx.throw(404);
|
|
278
257
|
}
|
|
279
|
-
if (approval.createdById !== ((_a =
|
|
280
|
-
return
|
|
258
|
+
if (approval.createdById !== ((_a = ctx.state.currentUser) == null ? void 0 : _a.id)) {
|
|
259
|
+
return ctx.throw(403);
|
|
281
260
|
}
|
|
282
261
|
if ([import_status.APPROVAL_STATUS.APPROVED, import_status.APPROVAL_STATUS.REJECTED, import_status.APPROVAL_STATUS.ERROR].includes(approval.status)) {
|
|
283
|
-
return
|
|
262
|
+
return ctx.throw(400);
|
|
284
263
|
}
|
|
285
264
|
if (((_b = approval.records) == null ? void 0 : _b.length) === 0) {
|
|
286
|
-
return
|
|
265
|
+
return ctx.throw(400);
|
|
287
266
|
}
|
|
288
267
|
const assignees = approval.records.map((record) => record.userId);
|
|
289
268
|
for (const userId of assignees) {
|
|
290
269
|
const [dataSourceName] = (0, import_server.parseCollectionName)(approval.collectionName);
|
|
291
|
-
const collection =
|
|
270
|
+
const collection = ctx.tego.dataSourceManager.dataSources.get(dataSourceName).collectionManager.getCollection(approval.collectionName);
|
|
292
271
|
const message = {
|
|
293
272
|
userId,
|
|
294
273
|
title: `{{t("Approval", { ns: '${import_constants.NAMESPACE}' })}}`,
|
|
@@ -298,11 +277,11 @@ const approvals = {
|
|
|
298
277
|
schemaName: (_c = approval.workflow) == null ? void 0 : _c.config.applyDetail,
|
|
299
278
|
dataKey: approval.data[collection.filterTargetKey]
|
|
300
279
|
};
|
|
301
|
-
|
|
280
|
+
ctx.tego.messageManager.sendMessage(+userId, message);
|
|
302
281
|
}
|
|
303
282
|
await next();
|
|
304
|
-
|
|
305
|
-
|
|
283
|
+
ctx.status = 200;
|
|
284
|
+
ctx.body = {
|
|
306
285
|
message: "reminder sent",
|
|
307
286
|
success: true
|
|
308
287
|
};
|
|
@@ -35,7 +35,7 @@ function make(name, mod) {
|
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
37
|
function init({ app }) {
|
|
38
|
-
app.
|
|
38
|
+
app.resourcer.registerActions({
|
|
39
39
|
...make("workflows", import_workflows.workflows),
|
|
40
40
|
...make("approvals", import_approvals.approvals),
|
|
41
41
|
...make("approvalRecords", import_approvalRecords.approvalRecords),
|
|
@@ -22,15 +22,15 @@ __export(workflows_exports, {
|
|
|
22
22
|
module.exports = __toCommonJS(workflows_exports);
|
|
23
23
|
var import_server = require("@tego/server");
|
|
24
24
|
const workflows = {
|
|
25
|
-
async listApprovalFlows(
|
|
26
|
-
|
|
25
|
+
async listApprovalFlows(ctx, next) {
|
|
26
|
+
ctx.action.mergeParams({
|
|
27
27
|
filter: {
|
|
28
28
|
type: "approval",
|
|
29
29
|
enabled: true
|
|
30
30
|
// TODO: 仅显示当前用户有权限的流程
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
|
-
return import_server.actions.list(
|
|
33
|
+
return import_server.actions.list(ctx, next);
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/server/plugin.js
CHANGED
|
@@ -62,9 +62,6 @@ class PluginWorkflowApproval extends import_server.Plugin {
|
|
|
62
62
|
plugin: this
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
|
-
await db.import({
|
|
66
|
-
directory: import_node_path.default.resolve(__dirname, "collections")
|
|
67
|
-
});
|
|
68
65
|
(0, import_actions.init)(this);
|
|
69
66
|
this.app.acl.allow("workflows", ["listApprovalFlows"], "loggedIn");
|
|
70
67
|
this.app.acl.allow("approvals", "*", "loggedIn");
|
|
@@ -11,10 +11,10 @@ export default class ApprovalTrigger extends Trigger {
|
|
|
11
11
|
onExecutionUpdate: (execution: any, { transaction }: {
|
|
12
12
|
transaction: any;
|
|
13
13
|
}) => Promise<void>;
|
|
14
|
-
middleware: (
|
|
14
|
+
middleware: (ctx: any, next: any) => Promise<any>;
|
|
15
15
|
constructor(workflow: any);
|
|
16
|
-
workflowTriggerAction(
|
|
17
|
-
collectionTriggerAction(
|
|
16
|
+
workflowTriggerAction(ctx: any, next: any): Promise<any>;
|
|
17
|
+
collectionTriggerAction(ctx: any, workflowList: any): Promise<void>;
|
|
18
18
|
on(workflow: any): void;
|
|
19
19
|
off(workflow: any): void;
|
|
20
20
|
duplicateConfig(workflow: any, { transaction }: {
|