@steedos/process 2.2.51-beta.1 → 2.2.51-beta.5

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/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@steedos/process",
3
- "version": "2.2.51-beta.1",
3
+ "version": "2.2.51-beta.5",
4
4
  "main": "lib/index.js",
5
5
  "repository": "https://github.com/steedos/steedos-platform.git",
6
6
  "scripts": {
7
- "compile": "tsc",
8
- "prepare": "tsc"
7
+ "build": "tsc"
9
8
  },
10
9
  "author": "",
11
10
  "license": "ISC",
@@ -17,8 +16,8 @@
17
16
  "typescript": "3.5.3"
18
17
  },
19
18
  "dependencies": {
20
- "@steedos/auth": "2.2.51-beta.1",
21
- "@steedos/objectql": "2.2.51-beta.1"
19
+ "@steedos/auth": "2.2.51-beta.5",
20
+ "@steedos/objectql": "2.2.51-beta.5"
22
21
  },
23
- "gitHead": "edeb1c70d34159e3caac697f9e207c2ca98d8d00"
22
+ "gitHead": "2adac588e1f9672862bf5ebd78035c48e11febfb"
24
23
  }
package/lib/approve.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import * as express from 'express';
2
- import * as core from "express-serve-static-core";
3
- interface Request extends core.Request {
4
- user: any;
5
- }
6
- export declare const approve: (req: Request, res: express.Response) => Promise<any>;
7
- export {};
@@ -1 +0,0 @@
1
- export declare const processExpress: any;
package/lib/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export { processExpress } from "./express-middleware";
@@ -1,5 +0,0 @@
1
- export declare const sendNotifications: (from: string, to: string, { instanceHistory, instance, status }: {
2
- instanceHistory?: any;
3
- instance?: any;
4
- status: any;
5
- }) => Promise<void>;
@@ -1,9 +0,0 @@
1
- import * as express from 'express';
2
- import * as core from "express-serve-static-core";
3
- interface Request extends core.Request {
4
- user: any;
5
- }
6
- export declare const allowRecallByProcessInstance: (req: Request, res: express.Response) => Promise<express.Response<any, Record<string, any>>>;
7
- export declare const allowApproverByInstanceHistoryId: (req: Request, res: express.Response) => Promise<express.Response<any, Record<string, any>>>;
8
- export declare const allowObjectSubmit: (req: Request, res: express.Response) => Promise<express.Response<any, Record<string, any>>>;
9
- export {};
@@ -1,8 +0,0 @@
1
- export declare const allowSubmit: (objectName: string, recordId: string, userSession: any) => Promise<boolean>;
2
- export declare const allowRecall: (processInstanceId: string, userSession: any) => Promise<boolean>;
3
- /**
4
- * 包括 批准、拒绝、重新分配
5
- * TODO 代理
6
- * TODO 对象管理员(对象权限为修改所有)可以处理所有的待审核请求
7
- */
8
- export declare const allowApprover: (instanceHistoryId: string, userSession: any) => Promise<boolean>;
@@ -1,2 +0,0 @@
1
- export declare const runProcessNodeAction: (processNodeId: string, when: string, recordId: string, userSession: any) => Promise<void>;
2
- export declare const runProcessAction: (processId: string, when: string, recordId: string, userSession: any) => Promise<void>;
@@ -1,8 +0,0 @@
1
- export declare const getObjectProcessDefinition: (objectName: string, recordId: string, userSession: any) => Promise<any>;
2
- export declare const recordSubmit: (processDefinitionId: string, objectName: string, recordId: any, userSession: any, comment: string, chooseApprover: any) => Promise<void>;
3
- export declare const getReocrdProcessInstance: (objectName: string, recordId: string, status: string, userSession: any) => Promise<any>;
4
- export declare const getProcessInstanceWorkitem: (instanceHistoryId: string, userSession: any) => Promise<any>;
5
- export declare const processInstanceWorkitemApprove: (instanceHistoryId: string, userSession: any, comment: string, chooseApprover?: string) => Promise<void>;
6
- export declare const processInstanceWorkitemReject: (instanceHistoryId: string, userSession: any, comment: string) => Promise<void>;
7
- export declare const processInstanceWorkitemReassign: (instanceHistoryId: string, userSession: any, comment: string, chooseApprover: string) => Promise<void>;
8
- export declare const processInstanceWorkitemRemovebyInstance: (instanceId: string, userSession: any, comment: string) => Promise<void>;
package/lib/reassign.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import * as express from 'express';
2
- import * as core from "express-serve-static-core";
3
- interface Request extends core.Request {
4
- user: any;
5
- }
6
- export declare const reassign: (req: Request, res: express.Response) => Promise<any>;
7
- export {};
package/lib/recall.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import * as express from 'express';
2
- import * as core from "express-serve-static-core";
3
- interface Request extends core.Request {
4
- user: any;
5
- }
6
- export declare const recall: (req: Request, res: express.Response) => Promise<any>;
7
- export {};
package/lib/reject.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import * as express from 'express';
2
- import * as core from "express-serve-static-core";
3
- interface Request extends core.Request {
4
- user: any;
5
- }
6
- export declare const reject: (req: Request, res: express.Response) => Promise<any>;
7
- export {};
package/lib/submit.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import * as express from 'express';
2
- import * as core from "express-serve-static-core";
3
- interface Request extends core.Request {
4
- user: any;
5
- }
6
- export declare const submit: (req: Request, res: express.Response) => Promise<any>;
7
- export {};
package/src/approve.ts DELETED
@@ -1,30 +0,0 @@
1
- import * as express from 'express';
2
- import { getProcessInstanceWorkitem, processInstanceWorkitemApprove } from './process_manager'
3
- import { allowApprover } from './permission_manager';
4
- import * as core from "express-serve-static-core";
5
- import { SteedosError, sendError } from '@steedos/objectql'
6
-
7
- interface Request extends core.Request {
8
- user: any;
9
- }
10
-
11
- export const approve = async (req: Request, res: express.Response) => {
12
- try {
13
- const urlParams = req.params;
14
- // const objectName = urlParams.objectName;
15
- const instanceHistoryId = urlParams.record;
16
- const userSession = req.user;
17
- const body = req.body;
18
- const comment = body.comment;
19
- const approver = body.approver;
20
- if(await allowApprover(instanceHistoryId, userSession)){
21
- const workitem = await getProcessInstanceWorkitem(instanceHistoryId, userSession);
22
- await processInstanceWorkitemApprove(workitem._id, userSession, comment, approver);
23
- return res.status(200).send({state: 'SUCCESS'});
24
- }
25
- throw new SteedosError("process_approval_error_NoApproval");
26
- } catch (error) {
27
- console.log(error);
28
- return sendError(res, error, 200);
29
- }
30
- }
@@ -1,30 +0,0 @@
1
- import { requireAuthentication } from '@steedos/auth';
2
-
3
- import { submit } from './submit';
4
- import { approve } from './approve';
5
- import { reject } from './reject';
6
- import { reassign } from './reassign';
7
- import { recall } from './recall';
8
- import { allowObjectSubmit, allowRecallByProcessInstance, allowApproverByInstanceHistoryId } from './permission'
9
- const express = require('express');
10
-
11
-
12
- export const processExpress = express.Router();
13
-
14
- processExpress.post('/api/v4/process/submit/:objectName/:record', requireAuthentication, submit);
15
-
16
- processExpress.post('/api/v4/process/approve/:objectName/:record', requireAuthentication, approve);
17
-
18
- processExpress.post('/api/v4/process/reject/:objectName/:record', requireAuthentication, reject);
19
-
20
- processExpress.post('/api/v4/process/reassign/:objectName/:record', requireAuthentication, reassign);
21
-
22
- // processExpress.post('/api/v4/process/recall/:objectName/:record', requireAuthentication, recall);
23
-
24
- processExpress.post('/api/v4/process/recall/:objectName/:record', requireAuthentication, recall);
25
-
26
- processExpress.get('/api/v4/process/permission/recall/:objectName/:record', requireAuthentication, allowRecallByProcessInstance);
27
-
28
- processExpress.get('/api/v4/process/permission/approver/:objectName/:record', requireAuthentication, allowApproverByInstanceHistoryId);
29
-
30
- processExpress.get('/api/v4/process/permission/submit/:objectName/:record', requireAuthentication, allowObjectSubmit);
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export { processExpress } from "./express-middleware";
@@ -1,46 +0,0 @@
1
- const objectql = require('@steedos/objectql');
2
- import { getUserLocale } from '@steedos/objectql';
3
- const Fiber = require('fibers');
4
- declare var Creator;
5
- declare var TAPi18n;
6
-
7
- export const sendNotifications = async (from: string, to: string, {instanceHistory = null, instance = null, status})=>{
8
- if(!to){
9
- return;
10
- }
11
- if(!instance){
12
- instance = await objectql.getObject("process_instance").findOne(instanceHistory.process_instance);
13
- }
14
- var fromUser = await objectql.getObject("users").findOne(from);
15
- const targetObjectName = instance.target_object.o;
16
- const targetObject = objectql.getObject(targetObjectName);
17
- var relatedDoc = await targetObject.findOne(instance.target_object.ids[0]);
18
- let relatedDocName = relatedDoc.name; //TODO
19
- const lng = getUserLocale(fromUser);
20
- var notificationTitle = TAPi18n.__(`process_notification_${status}_title`, {submitter: fromUser.name, recordName: relatedDocName}, lng);
21
- var notificationBody = targetObject.label;
22
- let linkToObjectName, linkToId;
23
- if(["approved", "rejected"].indexOf(status) > -1){
24
- linkToObjectName = targetObjectName;
25
- linkToId = relatedDoc._id;
26
- }
27
- else{
28
- linkToObjectName = "process_instance_history";
29
- linkToId = instanceHistory._id
30
- }
31
- var notificationDoc = {
32
- name: notificationTitle,
33
- body: notificationBody,
34
- related_to: {
35
- o: linkToObjectName,
36
- ids: [linkToId]
37
- },
38
- related_name: relatedDocName,
39
- from: `Process ${status}`,
40
- space: instance.space
41
- };
42
-
43
- Fiber(function () {
44
- Creator.addNotifications(notificationDoc, null, [to]);
45
- }).run();
46
- }
package/src/permission.ts DELETED
@@ -1,59 +0,0 @@
1
- import * as express from 'express';
2
- import { getReocrdProcessInstance } from './process_manager'
3
- import * as core from "express-serve-static-core";
4
- import { allowRecall, allowApprover, allowSubmit } from './permission_manager';
5
-
6
- interface Request extends core.Request {
7
- user: any;
8
- }
9
-
10
- export const allowRecallByProcessInstance = async (req: Request, res: express.Response) => {
11
- try {
12
- const urlParams = req.params;
13
- const objectName = urlParams.objectName;
14
- const recordId = urlParams.record;
15
- const userSession = req.user;
16
- const pendingInstances = await getReocrdProcessInstance(objectName, recordId, 'pending', userSession);
17
- if(pendingInstances.length > 0){
18
- const instanceId = pendingInstances[0]._id;
19
- if(await allowRecall(instanceId, userSession)){
20
- return res.status(200).send({allowRecall: true});
21
- }
22
- }
23
- return res.status(200).send({allowRecall: false});
24
- } catch (error) {
25
- return res.status(200).send({allowRecall: false});
26
- }
27
- }
28
-
29
- export const allowApproverByInstanceHistoryId = async (req: Request, res: express.Response) => {
30
- try {
31
- const urlParams = req.params;
32
- // const objectName = urlParams.objectName;
33
- const instanceHistoryId = urlParams.record;
34
- const userSession = req.user;
35
- if(await allowApprover(instanceHistoryId, userSession)){
36
- return res.status(200).send({allowApprover: true});
37
- }
38
- return res.status(200).send({allowApprover: false});
39
- } catch (error) {
40
- console.log(error);
41
- return res.status(200).send({allowApprover: false});
42
- }
43
- }
44
-
45
- export const allowObjectSubmit = async(req: Request, res: express.Response)=>{
46
- try {
47
- const urlParams = req.params;
48
- const objectName = urlParams.objectName;
49
- const recordId = urlParams.record;
50
- const userSession = req.user;
51
- if(await allowSubmit(objectName, recordId, userSession)){
52
- return res.status(200).send({allowSubmit: true});
53
- }
54
- return res.status(200).send({allowSubmit: false});
55
- } catch (error) {
56
- console.log('error', error);
57
- return res.status(200).send({allowSubmit: false});
58
- }
59
- }
@@ -1,62 +0,0 @@
1
- import { getProcessInstanceWorkitem, getReocrdProcessInstance, getObjectProcessDefinition } from './process_manager'
2
- const objectql = require('@steedos/objectql');
3
-
4
-
5
- export const allowSubmit = async (objectName: string, recordId: string, userSession: any)=>{
6
- const pendingInstances = await getReocrdProcessInstance(objectName, recordId, 'pending', userSession);
7
- if(pendingInstances.length > 0){
8
- return false;
9
- }else{
10
- const processDefinition = await getObjectProcessDefinition(objectName, recordId, userSession)
11
- if(processDefinition){
12
- //TODO 提交权限 https://help.salesforce.com/articleView?err=1&id=approvals_create_submitters.htm&type=5
13
- return true;
14
- }
15
- }
16
-
17
- return false;
18
- }
19
-
20
- //调回:对象管理员或者提交者
21
- export const allowRecall = async (processInstanceId: string, userSession: any)=>{
22
- const processInstance = await objectql.getObject("process_instance").findOne(processInstanceId);
23
-
24
- const objectPermission = await objectql.getObject(processInstance.target_object.o).getUserObjectPermission(userSession);
25
-
26
- if(objectPermission.modifyAllRecords){
27
- return true;
28
- }
29
-
30
- if(processInstance.submitted_by != userSession.userId){
31
- return false;
32
- }
33
-
34
- const processDefinition = await objectql.getObject("process_definition").findOne(processInstance.process_definition);
35
-
36
- if(processDefinition.allow_recall){
37
- return true;
38
- }
39
-
40
- return false;
41
- }
42
-
43
- /**
44
- * 包括 批准、拒绝、重新分配
45
- * TODO 代理
46
- * TODO 对象管理员(对象权限为修改所有)可以处理所有的待审核请求
47
- */
48
- export const allowApprover = async (instanceHistoryId: string, userSession: any)=>{
49
- const workitem = await getProcessInstanceWorkitem(instanceHistoryId, userSession);
50
- if(workitem && workitem._id){
51
- return true;
52
- }else{
53
- return false;
54
- }
55
- }
56
-
57
- // export const allowEditRecord = async (objectName, recordId, userSession: any)=>{
58
- // let processInstance = await objectql.getObject("process_instance").count({filters: [['target_object.o', '=', objectName],['target_object.ids', '=', recordId]]});
59
- // if(processInstance < 1){
60
- // return true;
61
- // }
62
- // }
@@ -1,95 +0,0 @@
1
- import { SteedosError } from '@steedos/objectql'
2
- const objectql = require('@steedos/objectql');
3
- const _ = require("underscore");
4
-
5
- export const runProcessNodeAction = async (processNodeId: string, when: string, recordId: string, userSession: any)=>{
6
- const processNode = await objectql.getObject("process_node").findOne(processNodeId);
7
- const filters = [];
8
- const wnfilters = [];
9
- switch (when) {
10
- case 'approval':
11
- if(!_.isEmpty(processNode.approval_updates_field_actions) && _.isArray(processNode.approval_updates_field_actions)){
12
- filters.push(['name', 'in', processNode.approval_updates_field_actions])
13
- }
14
- if(!_.isEmpty(processNode.approval_workflow_notifications_actions) && _.isArray(processNode.approval_workflow_notifications_actions)){
15
- wnfilters.push(['name', 'in', processNode.approval_workflow_notifications_actions])
16
- }
17
- break;
18
- case 'rejection':
19
- if(!_.isEmpty(processNode.rejection_updates_field_actions) && _.isArray(processNode.rejection_updates_field_actions)){
20
- filters.push(['name', 'in', processNode.rejection_updates_field_actions])
21
- }
22
- if(!_.isEmpty(processNode.rejection_workflow_notifications_actions) && _.isArray(processNode.rejection_workflow_notifications_actions)){
23
- wnfilters.push(['name', 'in', processNode.rejection_workflow_notifications_actions])
24
- }
25
- break;
26
- default:
27
- throw new SteedosError(`无效的参数when: ${when}`, );
28
- }
29
- if(!_.isEmpty(filters)){
30
- const actions = await objectql.getObject("action_field_updates").find({filters: filters})
31
- for (const action of actions) {
32
- await objectql.runFieldUpdateAction(action, recordId, userSession)
33
- }
34
- }
35
- if(!_.isEmpty(wnfilters)){
36
- const notifications = await objectql.getObject("workflow_notifications").find({filters: wnfilters})
37
- for (const wn of notifications) {
38
- await objectql.runWorkflowNotifyAction(wn, recordId, userSession)
39
- }
40
- }
41
- }
42
-
43
- export const runProcessAction = async (processId: string, when: string, recordId: string, userSession: any)=>{
44
- const process = await objectql.getObject("process_definition").findOne(processId);
45
- const filters = [];
46
- const wnfilters = [];
47
- switch (when) {
48
- case 'initial_submission':
49
- if(!_.isEmpty(process.initial_submission_updates_field_actions) && _.isArray(process.initial_submission_updates_field_actions)){
50
- filters.push(['name', 'in', process.initial_submission_updates_field_actions])
51
- }
52
- if(!_.isEmpty(process.initial_submission_workflow_notifications_actions) && _.isArray(process.initial_submission_workflow_notifications_actions)){
53
- wnfilters.push(['name', 'in', process.initial_submission_workflow_notifications_actions])
54
- }
55
- break;
56
- case 'final_approval':
57
- if(!_.isEmpty(process.final_approval_updates_field_actions) && _.isArray(process.final_approval_updates_field_actions)){
58
- filters.push(['name', 'in', process.final_approval_updates_field_actions])
59
- }
60
- if(!_.isEmpty(process.final_approval_workflow_notifications_actions) && _.isArray(process.final_approval_workflow_notifications_actions)){
61
- wnfilters.push(['name', 'in', process.final_approval_workflow_notifications_actions])
62
- }
63
- break;
64
- case 'final_rejection':
65
- if(!_.isEmpty(process.final_rejection_updates_field_actions) && _.isArray(process.final_rejection_updates_field_actions)){
66
- filters.push(['name', 'in', process.final_rejection_updates_field_actions])
67
- }
68
- if(!_.isEmpty(process.final_rejection_workflow_notifications_actions) && _.isArray(process.final_rejection_workflow_notifications_actions)){
69
- wnfilters.push(['name', 'in', process.final_rejection_workflow_notifications_actions])
70
- }
71
- break;
72
- case 'recall':
73
- if(!_.isEmpty(process.recall_updates_field_actions) && _.isArray(process.recall_updates_field_actions)){
74
- filters.push(['name', 'in', process.recall_updates_field_actions])
75
- }
76
- if(!_.isEmpty(process.recall_workflow_notifications_actions) && _.isArray(process.recall_workflow_notifications_actions)){
77
- wnfilters.push(['name', 'in', process.recall_workflow_notifications_actions])
78
- }
79
- break;
80
- default:
81
- throw new SteedosError(`无效的参数when: ${when}`, );
82
- }
83
- if(!_.isEmpty(filters)){
84
- const actions = await objectql.getObject("action_field_updates").find({filters: filters})
85
- for (const action of actions) {
86
- await objectql.runFieldUpdateAction(action, recordId, userSession)
87
- }
88
- }
89
- if(!_.isEmpty(wnfilters)){
90
- const notifications = await objectql.getObject("workflow_notifications").find({filters: wnfilters})
91
- for (const wn of notifications) {
92
- await objectql.runWorkflowNotifyAction(wn, recordId, userSession)
93
- }
94
- }
95
- }
@@ -1,550 +0,0 @@
1
- import {runProcessAction, runProcessNodeAction} from './platform_action_manager';
2
- import { sendNotifications } from './notifications';
3
- import { SteedosError } from '@steedos/objectql'
4
-
5
- const objectql = require('@steedos/objectql');
6
- const Fiber = require('fibers');
7
- const _ = require("underscore");
8
-
9
- declare var getHandlersManager;
10
-
11
- const lockObjectRecord = async (objectName, reocrdId)=>{
12
- await objectql.getObject(objectName).directUpdate(reocrdId, {locked: true});
13
- }
14
-
15
- const unlockObjectRecord = async (objectName, reocrdId)=>{
16
- await objectql.getObject(objectName).directUpdate(reocrdId, {locked: false});
17
- }
18
-
19
- const getProcessNodeApprover = async (instanceId: string, processNode: any, userSession: any, chooseApprover: any , isBack: boolean, record?:any)=>{
20
- let nodeApprover = [];
21
-
22
- if(isBack){
23
- const processInstanceNodes = await objectql.getObject("process_instance_node").find({filters: [['process_instance', '=', instanceId], ['process_node', '=', processNode._id]], sort: "created desc"});
24
- if(!_.isEmpty(processInstanceNodes)){
25
- const lastProcessInstanceNode = processInstanceNodes[0];
26
- const nodeHistroy = await objectql.getObject("process_instance_history").find({filters: ['process_instance_node', '=', lastProcessInstanceNode._id]})
27
- _.each(nodeHistroy, function(item){
28
- nodeApprover.push(item.original_actor);
29
- })
30
- }
31
- }else{
32
- let approver = processNode.approver;
33
- if(approver === 'auto_assign'){
34
-
35
- if(!_.isEmpty(processNode.assigned_approver_users)){
36
- nodeApprover = nodeApprover.concat(processNode.assigned_approver_users)
37
- }
38
-
39
- if (!_.isEmpty(processNode.assigned_approver_roles)) {
40
- for (const roleId of processNode.assigned_approver_roles) {
41
- let dbRoles = await objectql.getObject("roles").find({filters: ['api_name', '=', roleId]});
42
- if (dbRoles && dbRoles.length>0 && !_.isEmpty(dbRoles[0].users)) {
43
- nodeApprover = nodeApprover.concat(dbRoles[0].users);
44
- }else{
45
- let role = await objectql.getObject('roles').findOne(roleId);
46
- if (role && !_.isEmpty(role.users)) {
47
- nodeApprover = nodeApprover.concat(role.users);
48
- }
49
- }
50
- }
51
- }
52
-
53
- if (!_.isEmpty(processNode.assigned_approver_flow_roles)) {
54
- let submitted_by = userSession.userId;
55
- let spaceId = userSession.spaceId;
56
- if (instanceId) {
57
- let processInstance = await objectql.getObject("process_instance").findOne(instanceId);
58
- submitted_by = processInstance.submitted_by;
59
- }
60
- let assigned_approver_flow_role_ids = [];
61
- let flowRoleKeys = processNode.assigned_approver_flow_roles;
62
- for(let flowRoleKey of flowRoleKeys){
63
- let dbFlowRole;
64
- let dbFlowRoles = await objectql.getObject("flow_roles").find({filters: ['api_name', '=', flowRoleKey]});
65
- if(dbFlowRoles && dbFlowRoles.length == 1){
66
- dbFlowRole = dbFlowRoles[0]
67
- }else{
68
- dbFlowRole = await objectql.getObject("flow_roles").findOne(flowRoleKey);
69
- }
70
- assigned_approver_flow_role_ids.push(dbFlowRole._id);
71
- }
72
-
73
- let handlers = await new Promise((resolve, reject) => {
74
- Fiber(function () {
75
- try {
76
- let handlers = getHandlersManager.getHandlersByUserAndRoles(submitted_by, assigned_approver_flow_role_ids, spaceId);
77
- resolve(handlers);
78
- } catch (error) {
79
- reject(error)
80
- }
81
- }).run()
82
- });
83
- nodeApprover = nodeApprover.concat(handlers);
84
- }
85
-
86
- if(!_.isEmpty(processNode.assigned_approver_user_field)){
87
- if(instanceId){
88
- const processInstance = await objectql.getObject("process_instance").findOne(instanceId);
89
- record = await objectql.getObject(processInstance.target_object.o).findOne(processInstance.target_object.ids[0]);
90
- }
91
- if(record){
92
- _.each(processNode.assigned_approver_user_field, function(fieldName){
93
- let fieldValue = record[fieldName];
94
- if(_.isString(fieldValue)){
95
- fieldValue = [fieldValue]
96
- }
97
- if(_.isArray(fieldValue)){
98
- nodeApprover = nodeApprover.concat(fieldValue);
99
- }
100
- })
101
- }
102
- }
103
-
104
- }else if(approver === 'submitter_choose'){
105
- if(chooseApprover){
106
- if(_.isString(chooseApprover)){
107
- return [chooseApprover];
108
- }else if(_.isArray(chooseApprover)){
109
- return _.uniq(_.compact(chooseApprover));
110
- }else{
111
- throw new SteedosError('process_approval_error_invalidChooseApprover');
112
- }
113
- }else{
114
- throw new SteedosError('process_approval_error_needToChooseApprover');
115
- }
116
- }
117
- }
118
- return _.uniq(_.compact(nodeApprover));
119
- }
120
-
121
- const getProcessNodes = async (processDefinitionId: string, spaceId: string)=>{
122
- return await objectql.getObject('process_node').find({filters: [['process_definition', '=', processDefinitionId], ['space', '=', spaceId]], sort: "order asc"});
123
- }
124
-
125
- const addInstanceHistory = async (spaceId: string, instanceId: string, status: string, comment: string, options: any, userSession)=>{
126
- let instance = await objectql.getObject("process_instance").findOne(instanceId);
127
- let name = '';
128
- if(options.nodeId){
129
- const node = await objectql.getObject("process_node").findOne(options.nodeId);
130
- if(node){
131
- name = node.label;
132
- }
133
- }
134
-
135
- let instanceHistory = await objectql.getObject("process_instance_history").insert({
136
- name: name,
137
- process_instance: instanceId,
138
- target_object: instance.target_object,
139
- step_status: status,
140
- original_actor: options.originalActor || options.actor, //TODO 根据规则处理
141
- actor: options.actor, //TODO 根据规则处理
142
- comments: comment,
143
- step_node: options.nodeId,
144
- process_instance_node: options.instanceNodeId,
145
- space: spaceId,
146
- created_by: userSession.userId
147
- });
148
-
149
- if(status === 'approved' || status === 'rejected'){
150
- await handleProcessInstance(instanceHistory.process_instance, status, userSession);
151
- }
152
-
153
- if(status === 'pending'){
154
- await sendNotifications(instance.created_by, options.actor, {instanceHistory, status, instance});
155
- }
156
- }
157
-
158
- const addInstanceNode = async (instanceId: string, node: any, userSession: any, nodeApprover: any)=>{
159
- let nodeId = node._id;
160
- let nodeName = node.label;
161
- // const nodeApprover = await getProcessNodeApprover(instanceId, node, userSession, isBack);
162
- const instanceNode = await objectql.getObject("process_instance_node").insert({
163
- process_instance: instanceId,
164
- process_node: nodeId,
165
- process_node_name: nodeName,
166
- node_status: 'pending',
167
- space: userSession.spaceId,
168
- created_by: userSession.userId
169
- })
170
- for (const actor of nodeApprover) {
171
- await addInstanceHistory(userSession.spaceId, instanceId, 'pending', null, {nodeId: nodeId, actor: actor, originalActor: actor, submitted_by: userSession.userId, instanceNodeId: instanceNode._id}, userSession);
172
- }
173
- }
174
-
175
- const getNextNode = async (nodes: any, index: number = 0, objectName: string, recordId: string, userSession: any)=>{
176
- let spaceId = userSession.spaceId;
177
- let currentUserId = userSession.userId;
178
- let node = nodes[index];
179
- if(node){
180
- if(node.filtrad){
181
- return node;
182
- }else{
183
- const canEntry = await objectql.computeFormula(node.entry_criteria, objectName, recordId, currentUserId, spaceId);
184
- if(canEntry){
185
- return node;
186
- }else{
187
- if(node.if_criteria_not_met === 'skip'){
188
- return await getNextNode(nodes, index + 1, objectName, recordId, userSession)
189
- }else if(node.if_criteria_not_met === 'reject'){
190
- return {to_final_rejection: true}
191
- }else if(node.if_criteria_not_met === 'approve'){
192
- return {to_final_approval: true}
193
- }
194
- }
195
- }
196
- }
197
- }
198
-
199
- const toNextNode = async (instanceId: string, node: any, nextApprovers: any, userSession: any)=>{
200
- if(node){
201
- await addInstanceNode(instanceId, node, userSession, nextApprovers);
202
- }
203
- }
204
-
205
- //TODO nextApprovers
206
- // const toNextNode = async (instanceId: string, comment: string, nodes: any, index: number = 0, objectName: string, recordId: string, userSession: any, nextApprovers?)=>{
207
- // let spaceId = userSession.spaceId;
208
- // let currentUserId = userSession.userId;
209
- // let node = nodes[index];
210
- // if(node){
211
- // if(node.filtrad){
212
- // await addInstanceNode(instanceId, node, userSession);
213
- // }else{
214
- // const canEntry = await objectql.computeFormula(node.entry_criteria, objectName, recordId, currentUserId, spaceId);
215
- // if(canEntry){
216
- // await addInstanceNode(instanceId, node, userSession);
217
- // }else{
218
- // if(node.if_criteria_not_met === 'skip'){
219
- // await toNextNode(instanceId, comment, nodes, index + 1, objectName, recordId, userSession)
220
- // }else{
221
- // let options = {actor: currentUserId}
222
- // if(node.if_criteria_not_met === 'reject'){
223
- // await addInstanceHistory(userSession.spaceId, instanceId, "rejected", comment, options, userSession)
224
- // }else if(node.if_criteria_not_met === 'approve'){
225
- // // await addInstanceHistory(userSession.spaceId, instanceId, "approved", comment, options)
226
- // }
227
- // }
228
- // }
229
- // }
230
- // }
231
- // }
232
- const getPreviousNode = async (instanceId: string, currentNode: any, userSession: any)=>{
233
- const previousInstanceNodes = await objectql.getObject("process_instance_node").find({filters: [['process_instance', '=', instanceId], ['process_node', '!=', currentNode._id]], sort: 'created desc'});
234
- if(!_.isEmpty(previousInstanceNodes)){
235
- const previousInstanceNode = previousInstanceNodes[0];
236
- const previousNode = await objectql.getObject("process_node").findOne(previousInstanceNode.process_node);
237
- return previousNode;
238
- }else{
239
- throw new SteedosError('not find previous node')
240
- }
241
- }
242
-
243
- // const toPreviousNode = async (instanceId: string, currentNode: any, userSession: any)=>{
244
- // const previousInstanceNodes = await objectql.getObject("process_instance_node").find({filters: [['process_instance', '=', instanceId], ['process_node', '!=', currentNode._id]], sort: 'created desc'});
245
- // if(!_.isEmpty(previousInstanceNodes)){
246
- // const previousInstanceNode = previousInstanceNodes[0];
247
- // const previousNode = await objectql.getObject("process_node").findOne(previousInstanceNode.process_node)
248
- // await addInstanceNode(instanceId, previousNode, userSession, true);
249
- // }else{
250
- // throw new SteedosError('not find previous node')
251
- // }
252
- // }
253
-
254
- //TODO 处理提交权限
255
- export const getObjectProcessDefinition = async (objectName: string, recordId: string, userSession: any)=>{
256
- let spaceId = userSession.spaceId;
257
- let currentUserId = userSession.userId;
258
- let processes = await objectql.getObject('process_definition').find({filters: [['object_name', '=', objectName], ['space', '=', spaceId], ['active', '=', true]], sort: "order asc"})
259
- if(processes.length < 1){
260
- return null;
261
- }
262
- let process = null;
263
- //计算符合条件的process_definition
264
- for (const _process of processes) {
265
- const canEntry = await objectql.computeFormula(_process.entry_criteria, objectName, recordId, currentUserId, spaceId);
266
- if(canEntry){
267
- process = _process
268
- break;
269
- }
270
- }
271
- return process;
272
- }
273
-
274
- export const recordSubmit = async (processDefinitionId: string, objectName: string, recordId, userSession: any, comment: string, chooseApprover: any)=>{
275
-
276
- const pendingInstanceCount = await objectql.getObject("process_instance").count({filters: [['target_object.o', '=', objectName],['target_object.ids', '=', recordId],['status', '=', 'pending']]});
277
- if(pendingInstanceCount > 0){
278
- throw new SteedosError('process_approval_error_processInstancePending');
279
- }
280
-
281
- const nodes = await getProcessNodes(processDefinitionId, userSession.spaceId);
282
-
283
- const nextNode = await getNextNode(nodes, 0, objectName, recordId, userSession);
284
-
285
- let to_final_rejection = false;
286
- let to_final_approval = false;
287
-
288
- if(nextNode.to_final_rejection){
289
- to_final_rejection = true;
290
- }else if(nextNode.to_final_approval){
291
- to_final_approval = true;
292
- }
293
-
294
- let approver = null;
295
-
296
- if(!to_final_rejection && !to_final_rejection){
297
- const record = await objectql.getObject(objectName).findOne(recordId);
298
- approver = await getProcessNodeApprover(null, nextNode, userSession, chooseApprover, false, record);
299
- }
300
-
301
- let instance = await objectql.getObject("process_instance").insert({
302
- process_definition: processDefinitionId,
303
- target_object: {
304
- "o" : objectName,
305
- "ids" : [recordId]
306
- },
307
- status: "pending",
308
- space: userSession.spaceId,
309
- submitted_by: userSession.userId,
310
- created_by: userSession.userId
311
- });
312
-
313
- await lockObjectRecord(objectName, recordId);
314
-
315
- await runProcessAction(processDefinitionId, 'initial_submission', recordId, userSession);
316
-
317
- await addInstanceHistory(userSession.spaceId, instance._id, "started", comment, {actor: userSession.userId}, userSession);
318
-
319
- if(to_final_rejection){
320
- let options = {actor: userSession.userId};
321
- await addInstanceHistory(userSession.spaceId, instance._id, "rejected", comment, options, userSession)
322
- }else if(to_final_approval){
323
- let options = {actor: userSession.userId};
324
- await addInstanceHistory(userSession.spaceId, instance._id, "approved", comment, options, userSession)
325
- }else{
326
- await toNextNode(instance._id, nextNode, approver, userSession);
327
- }
328
- }
329
-
330
- export const getReocrdProcessInstance = async(objectName: string, recordId: string, status: string, userSession: any)=>{
331
- let spaceId = userSession.spaceId;
332
- return await objectql.getObject("process_instance").find({filters: [['space', '=', spaceId], ['status', '=', status], ['target_object.o', '=', objectName], ['target_object.ids', '=', recordId]]});
333
- }
334
-
335
- export const getProcessInstanceWorkitem = async (instanceHistoryId: string, userSession: any)=>{
336
- let spaceId = userSession.spaceId;
337
- let userId = userSession.userId; //TODO 代理
338
- const workitme = await objectql.getObject("process_instance_history").find({filters: [['_id', '=', instanceHistoryId], ['step_status', '=', 'pending'], ['actor', '=', userId], ['space', '=', spaceId]]})
339
- if(workitme.length > 0){
340
- return workitme[0];
341
- }
342
- }
343
-
344
- const getProcessActionWhenByStatus = (processStatus: string)=>{
345
- let when = '';
346
- if(processStatus === 'approved'){
347
- when = 'final_approval';
348
- }else if(processStatus === 'rejected'){
349
- when = 'final_rejection';
350
- }else if(processStatus === 'removed'){
351
- when = 'recall';
352
- }
353
- return when;
354
- }
355
-
356
- const getProcessNodeActionWhenByStatus = (processStatus: string)=>{
357
- let when = '';
358
- if(processStatus === 'approved'){
359
- when = 'approval';
360
- }else if(processStatus === 'rejected'){
361
- when = 'rejection';
362
- }
363
- return when;
364
- }
365
-
366
- // export const getProcessInstanceWorkitem = async (objectName: string, recordId: string, userSession: any)=>{
367
- // let spaceId = userSession.spaceId;
368
- // let userId = userSession.userId; //TODO 代理
369
- // const instances = await objectql.getObject("process_instance").find({filters: [['space', '=', spaceId], ['status', '=', 'pending'], ['target_object.o', '=', objectName], ['target_object.ids', '=', recordId]]});
370
- // if(instances.length < 1){
371
- // return
372
- // }
373
- // const instance = instances[0];
374
- // const workitme = await objectql.getObject("process_instance_history").find({filters: [['process_instance', '=', instance._id], ['step_status', '=', 'pending'], ['actor', '=', userId]]})
375
- // if(workitme.length > 0){
376
- // return workitme[0];
377
- // }
378
- // }
379
-
380
- //TODO 编写trigger 处理elapsed_time
381
- const handleProcessInstance = async(instanceId: string, processStatus: string, userSession: any)=>{
382
- let otherPendingInstanceNodeCount = await objectql.getObject("process_instance_node").count({filters: [['process_instance', '=', instanceId], ['node_status', '=', 'pending']]});
383
- if(otherPendingInstanceNodeCount === 0){
384
- const pInstance = await objectql.getObject("process_instance").update(instanceId, {status: processStatus, completed_date: new Date(), last_actor: userSession.userId});
385
- if(processStatus === 'removed'){
386
- await unlockObjectRecord(pInstance.target_object.o, pInstance.target_object.ids[0]);
387
- }else{
388
- let process = await objectql.getObject("process_definition").findOne(pInstance.process_definition);
389
- if(processStatus === 'approved'){
390
- if(process.final_approval_record_lock === 'unlock'){
391
- await unlockObjectRecord(pInstance.target_object.o, pInstance.target_object.ids[0]);
392
- }else{
393
- await lockObjectRecord(pInstance.target_object.o, pInstance.target_object.ids[0]);
394
- }
395
-
396
- }else if(processStatus === 'rejected'){
397
- if(process.final_rejection_record_lock === 'unlock'){
398
- await unlockObjectRecord(pInstance.target_object.o, pInstance.target_object.ids[0]);
399
- }else{
400
- await lockObjectRecord(pInstance.target_object.o, pInstance.target_object.ids[0]);
401
- }
402
- }
403
- }
404
- let when = getProcessActionWhenByStatus(processStatus);
405
- if(when){
406
- await runProcessAction(pInstance.process_definition, when, pInstance.target_object.ids[0], userSession);
407
- }
408
- if(['approved', 'rejected'].indexOf(processStatus) > -1){
409
- await sendNotifications(pInstance.created_by, pInstance.created_by, { status: processStatus, instance: pInstance});
410
- }
411
- }
412
- }
413
-
414
- const getCurrentInstanceNode = async(instanceId)=>{
415
- const pendingNodes = await objectql.getObject("process_instance_node").find({filters: [['process_instance', '=', instanceId], ['node_status', '=', 'pending']]});
416
- let currentNode = null;
417
- if(pendingNodes.length > 0){
418
- currentNode = pendingNodes[0];
419
- }
420
- return currentNode;
421
- }
422
-
423
- const getProcessInstance = async (instanceId)=>{
424
- return await objectql.getObject("process_instance").findOne(instanceId);
425
- }
426
-
427
- const getProcessNode = async(processNodeId: string)=>{
428
- return await objectql.getObject("process_node").findOne(processNodeId);
429
- }
430
-
431
- //TODO 编写trigger 处理elapsed_time
432
- const handleProcessInstanceNode = async(instanceId: string, currentInstanceNode, processStatus: string, nextNodeOptions: any, userSession: any)=>{
433
- let otherPendingInstanceHistoryCount = await objectql.getObject("process_instance_history").count({filters: [['process_instance', '=', instanceId], ['step_status', '=', 'pending']]})
434
- if(otherPendingInstanceHistoryCount === 0){
435
- let finalProcessStatus = processStatus;
436
- await objectql.getObject("process_instance_node").updateMany([['process_instance', '=', instanceId], ['node_status', '=', 'pending']], {node_status: processStatus, completed_date: new Date(), last_actor: userSession.userId})
437
- let when = getProcessNodeActionWhenByStatus(processStatus);
438
- if(when){
439
- const instance = await objectql.getObject("process_instance").findOne(instanceId);
440
- await runProcessNodeAction(currentInstanceNode.process_node, when, instance.target_object.ids[0], userSession);
441
- }
442
-
443
- if(nextNodeOptions){
444
- let to_final_rejection = false;
445
- let to_final_approval = false;
446
- if(nextNodeOptions.node.to_final_rejection){
447
- to_final_rejection = true;
448
- finalProcessStatus = 'rejected';
449
- }else if(nextNodeOptions.node.to_final_approval){
450
- to_final_approval = true;
451
- finalProcessStatus = 'approved';
452
- }
453
- if(to_final_rejection){
454
- }else if(to_final_approval){
455
- }else{
456
- await toNextNode(instanceId, nextNodeOptions.node, nextNodeOptions.approve, userSession);
457
- }
458
- }
459
-
460
- await handleProcessInstance(instanceId, finalProcessStatus, userSession);
461
- }
462
- }
463
-
464
- const getInstanceHistory = async(instanceHistoryId)=>{
465
- return await objectql.getObject("process_instance_history").findOne(instanceHistoryId)
466
- }
467
-
468
- const getPendingInstanceHistoryCount = async (instanceId: string)=>{
469
- return await objectql.getObject("process_instance_history").count({filters: [['process_instance', '=', instanceId], ['step_status', '=', 'pending']]});
470
- }
471
-
472
- const handleProcessInstanceWorkitem = async (currentInstanceNode, processStatus: string, instanceHistoryId: string, userSession: any, comment: string, nextNodeOptions?: string)=>{
473
- let instanceHistory = await getInstanceHistory(instanceHistoryId);
474
- if(processStatus === 'rejected' || processStatus === 'approved'){
475
- await objectql.getObject("process_instance_history").update(instanceHistoryId, {step_status: processStatus, comments: comment, actor: userSession.userId});
476
- let when_multiple_approvers = 'first_response';
477
- if(instanceHistory.step_node){
478
- let processNode = await objectql.getObject("process_node").findOne(instanceHistory.step_node);
479
- if(processNode && processNode.when_multiple_approvers){
480
- when_multiple_approvers = processNode.when_multiple_approvers;
481
- }
482
- }
483
- if(when_multiple_approvers === 'first_response' || (when_multiple_approvers === 'unanimous' && processStatus === 'rejected')){
484
- await objectql.getObject("process_instance_history").updateMany([['_id', '!=', instanceHistory._id], ['process_instance', '=', instanceHistory.process_instance], ['step_status', '=', 'pending']], {step_status: 'no_response'})
485
- }
486
- }
487
-
488
- await handleProcessInstanceNode(instanceHistory.process_instance, currentInstanceNode, processStatus, nextNodeOptions, userSession);
489
- }
490
-
491
- export const processInstanceWorkitemApprove = async (instanceHistoryId: string, userSession: any, comment: string, chooseApprover?: string)=>{
492
- let nextNodeOptions = null;
493
- let instanceHistory = await getInstanceHistory(instanceHistoryId);
494
- let instanceId = instanceHistory.process_instance;
495
- let currentInstanceNode = await getCurrentInstanceNode(instanceId);
496
- let instance = await getProcessInstance(instanceId);
497
- let currentProcessNode = await getProcessNode(instanceHistory.step_node);
498
- const nodes = await getProcessNodes(instance.process_definition, userSession.spaceId);
499
- const index = _.findIndex(nodes, function(item){return item._id === currentInstanceNode.process_node});
500
- if(currentProcessNode.when_multiple_approvers === 'first_response' || (await getPendingInstanceHistoryCount(instanceId)) < 2){
501
- let nextNode = await getNextNode(nodes, index + 1, instance.target_object.o, instance.target_object.ids[0], userSession);
502
-
503
- if(nextNode){
504
- nextNodeOptions = {}
505
- nextNodeOptions.node = nextNode;
506
- nextNodeOptions.approve = await getProcessNodeApprover(instanceId, nextNodeOptions.node, userSession, chooseApprover, false);
507
- }
508
- }
509
- await handleProcessInstanceWorkitem(currentInstanceNode, 'approved', instanceHistoryId, userSession, comment, nextNodeOptions);
510
- }
511
-
512
- export const processInstanceWorkitemReject = async (instanceHistoryId: string, userSession: any, comment: string)=>{
513
- let nextNodeOptions = null;
514
- let instanceHistory = await getInstanceHistory(instanceHistoryId);
515
- let instanceId = instanceHistory.process_instance;
516
- let currentInstanceNode = await getCurrentInstanceNode(instanceId);
517
- let currentProcessNode = await getProcessNode(instanceHistory.step_node);
518
-
519
- if(currentProcessNode.reject_behavior === 'back_to_previous'){
520
- nextNodeOptions = {}
521
- nextNodeOptions.node = await getPreviousNode(instanceId, currentProcessNode, userSession)
522
- nextNodeOptions.approve = await getProcessNodeApprover(instanceId, nextNodeOptions.node, userSession, null, true);
523
- }
524
-
525
- await handleProcessInstanceWorkitem(currentInstanceNode, 'rejected', instanceHistoryId, userSession, comment, nextNodeOptions);
526
- }
527
-
528
- export const processInstanceWorkitemReassign = async (instanceHistoryId: string, userSession: any, comment: string, chooseApprover: string)=>{
529
- if(_.isEmpty(chooseApprover)){
530
- throw new SteedosError('process_approval_error_reassign_approver_notFind');
531
- }
532
- if(!_.isString(chooseApprover)){
533
- throw new SteedosError('process_approval_error_reassign_approver_mustBeString');
534
- }
535
-
536
- const history = await objectql.getObject("process_instance_history").update(instanceHistoryId, {
537
- step_status: "reassigned",
538
- actor: chooseApprover,
539
- comments: comment
540
- })
541
-
542
- await addInstanceHistory(userSession.spaceId, history.process_instance, 'pending', null, {nodeId: history.step_node, actor: chooseApprover, originalActor: history.original_actor, submitted_by: userSession.userId}, userSession);
543
- }
544
-
545
-
546
- export const processInstanceWorkitemRemovebyInstance = async (instanceId: string, userSession: any, comment: string)=>{
547
- const processStatus = 'removed';
548
- await objectql.getObject("process_instance_history").updateMany([['process_instance', '=', instanceId], ['step_status', '=', 'pending']], {step_status: processStatus, comments: comment});
549
- await handleProcessInstanceNode(instanceId, null, processStatus, null, userSession);
550
- }
package/src/reassign.ts DELETED
@@ -1,30 +0,0 @@
1
- import * as express from 'express';
2
- import { getProcessInstanceWorkitem, processInstanceWorkitemReassign } from './process_manager'
3
- import { allowApprover } from './permission_manager';
4
- import * as core from "express-serve-static-core";
5
- import { SteedosError, sendError } from '@steedos/objectql'
6
-
7
- interface Request extends core.Request {
8
- user: any;
9
- }
10
-
11
- export const reassign = async (req: Request, res: express.Response) => {
12
-
13
- try {
14
- const urlParams = req.params;
15
- // const objectName = urlParams.objectName;
16
- const instanceHistoryId = urlParams.record;
17
- const userSession = req.user;
18
- const body = req.body;
19
- const comment = body.comment;
20
- const approver = body.approver;
21
- if(await allowApprover(instanceHistoryId, userSession)){
22
- const workitem = await getProcessInstanceWorkitem(instanceHistoryId, userSession);
23
- await processInstanceWorkitemReassign(workitem._id, userSession, comment, approver);
24
- return res.status(200).send({state: 'SUCCESS'});
25
- }
26
- throw new SteedosError("process_approval_error_NoApproval");
27
- } catch (error) {
28
- return sendError(res, error, 200);
29
- }
30
- }
package/src/recall.ts DELETED
@@ -1,36 +0,0 @@
1
- import * as express from 'express';
2
- import { processInstanceWorkitemRemovebyInstance, getReocrdProcessInstance } from './process_manager'
3
- import * as core from "express-serve-static-core";
4
- import { allowRecall } from './permission_manager';
5
- import { SteedosError, sendError } from '@steedos/objectql'
6
- interface Request extends core.Request {
7
- user: any;
8
- }
9
-
10
- export const recall = async (req: Request, res: express.Response) => {
11
- try {
12
- const urlParams = req.params;
13
- const objectName = urlParams.objectName;
14
- const recordId = urlParams.record;
15
- const userSession = req.user;
16
- const body = req.body;
17
- const comment = body.comment;
18
- const pendingInstances = await getReocrdProcessInstance(objectName, recordId, 'pending', userSession);
19
- //TODO 权限处理:如果支持取回,则发起人可以取回;否则只有对象管理员(有编辑所有的权限)可以取回 ,考虑company级权限?
20
- if(pendingInstances.length > 0){
21
- const instanceId = pendingInstances[0]._id;
22
- if(await allowRecall(instanceId, userSession)){
23
- await processInstanceWorkitemRemovebyInstance(instanceId, userSession, comment);
24
- return res.status(200).send({state: 'SUCCESS'});
25
- }else{
26
- throw new SteedosError("process_approval_error_recall_NoPermission");
27
- }
28
- }else{
29
- throw new SteedosError("process_approval_error_NoApproval")
30
- }
31
-
32
- } catch (error) {
33
- return sendError(res, error, 200);
34
- }
35
- }
36
-
package/src/reject.ts DELETED
@@ -1,27 +0,0 @@
1
- import * as express from 'express';
2
- import { getProcessInstanceWorkitem, processInstanceWorkitemReject } from './process_manager'
3
- import { allowApprover } from './permission_manager';
4
- import * as core from "express-serve-static-core";
5
- import { SteedosError, sendError } from '@steedos/objectql'
6
- interface Request extends core.Request {
7
- user: any;
8
- }
9
-
10
- export const reject = async (req: Request, res: express.Response) => {
11
- try {
12
- const urlParams = req.params;
13
- // const objectName = urlParams.objectName;
14
- const instanceHistoryId = urlParams.record;
15
- const userSession = req.user;
16
- const body = req.body;
17
- const comment = body.comment;
18
- if(await allowApprover(instanceHistoryId, userSession)){
19
- const workitem = await getProcessInstanceWorkitem(instanceHistoryId, userSession);
20
- await processInstanceWorkitemReject(workitem._id, userSession, comment);
21
- return res.status(200).send({state: 'SUCCESS'});
22
- }
23
- throw new SteedosError("process_approval_error_NoApproval");
24
- } catch (error) {
25
- return sendError(res, error, 200)
26
- }
27
- }
package/src/submit.ts DELETED
@@ -1,28 +0,0 @@
1
- import * as express from 'express';
2
- import { getObjectProcessDefinition, recordSubmit } from './process_manager'
3
- import * as core from "express-serve-static-core";
4
- import { SteedosError, sendError } from '@steedos/objectql'
5
- interface Request extends core.Request {
6
- user: any;
7
- }
8
-
9
- export const submit = async (req: Request, res: express.Response) => {
10
- try {
11
- const urlParams = req.params;
12
- const objectName = urlParams.objectName;
13
- const recordId = urlParams.record;
14
- const userSession = req.user;
15
- const body = req.body;
16
- const comment = body.comment;
17
- const approver = body.approver;
18
-
19
- const processDefinition = await getObjectProcessDefinition(objectName, recordId, userSession);
20
- if(!processDefinition){
21
- throw new SteedosError('process_approval_error_notFindProcessDefinition');
22
- }
23
- await recordSubmit(processDefinition._id, objectName, recordId, userSession, comment, approver);
24
- return res.status(200).send({state: 'SUCCESS'});
25
- } catch (error) {
26
- return sendError(res, error, 200)
27
- }
28
- }
package/tsconfig.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "extends": "../../node_modules/@salesforce/dev-config/tsconfig-strict",
3
- "compilerOptions": {
4
- "outDir": "./lib",
5
- "strict": false,
6
- "noUnusedLocals": true,
7
- "emitDecoratorMetadata": true,
8
- "experimentalDecorators": true,
9
- "sourceMap": true,
10
- "resolveJsonModule": true,
11
- "skipLibCheck": true,
12
- "lib": [
13
- "es5",
14
- "es6",
15
- "dom",
16
- "es2015",
17
- "es2016",
18
- "es2017",
19
- "esnext"
20
- ],
21
- },
22
- "include": [
23
- "./src/**/*"
24
- ]
25
- }