@steedos-labs/content-compliance 0.7.11 → 0.7.13

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.
@@ -1 +1 @@
1
- {"version":3,"file":"empty.js","sourceRoot":"","sources":["../../../../src/methods/__tests__/__mocks__/empty.ts"],"names":[],"mappings":";;AACA,kBAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"empty.js","sourceRoot":"","sources":["../../../../src/methods/__tests__/__mocks__/empty.ts"],"names":[],"mappings":";;AAAA,kBAAe,EAAE,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ var approval_engine_1 = require("../approval_engine");
5
+ var consts_1 = require("../consts");
6
+ var baseApproval = {
7
+ _id: 'approval-1',
8
+ owner: 'owner-1',
9
+ space: 'space-1',
10
+ name: '测试审批单',
11
+ current_step: consts_1.Step.departmental_review,
12
+ ca_reviewer: ['reviewer-1'],
13
+ kids_reviewer: 'reviewer-1',
14
+ handler_ca: ['reviewer-1'],
15
+ handler_kids: ['reviewer-1'],
16
+ ca_approval_status: false,
17
+ kids_approval_status: false
18
+ };
19
+ describe('postpone review department resolution', function () {
20
+ it('uses CA when the same user is both CA and Kids and Kids is the latest process', function () {
21
+ var departmentType = (0, approval_engine_1.getPostponeReviewDepartmentType)(baseApproval, [
22
+ { type: consts_1.ProcessApprovalType.Kids },
23
+ { type: consts_1.ProcessApprovalType.CA }
24
+ ]);
25
+ expect(departmentType).toBe(consts_1.ProcessApprovalType.CA);
26
+ });
27
+ it('still blocks users who only have a Kids approval role', function () {
28
+ expect(function () { return (0, approval_engine_1.getPostponeReviewDepartmentType)(tslib_1.__assign(tslib_1.__assign({}, baseApproval), { ca_approval_status: '', handler_ca: [] }), [
29
+ { type: consts_1.ProcessApprovalType.Kids }
30
+ ], 'reviewer-1'); }).toThrow('Kids审核人不支持延后审核操作');
31
+ });
32
+ it('falls back to handler fields when process history only exposes Kids', function () {
33
+ var departmentType = (0, approval_engine_1.getPostponeReviewDepartmentType)(baseApproval, [
34
+ { type: consts_1.ProcessApprovalType.Kids }
35
+ ], 'reviewer-1');
36
+ expect(departmentType).toBe(consts_1.ProcessApprovalType.CA);
37
+ });
38
+ });
39
+ //# sourceMappingURL=postponeReview.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postponeReview.test.js","sourceRoot":"","sources":["../../../src/methods/__tests__/postponeReview.test.ts"],"names":[],"mappings":";;;AAAA,sDAAqE;AACrE,oCAAsD;AAEtD,IAAM,YAAY,GAAQ;IACtB,GAAG,EAAE,YAAY;IACjB,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,OAAO;IACb,YAAY,EAAE,aAAI,CAAC,mBAAmB;IACtC,WAAW,EAAE,CAAC,YAAY,CAAC;IAC3B,aAAa,EAAE,YAAY;IAC3B,UAAU,EAAE,CAAC,YAAY,CAAC;IAC1B,YAAY,EAAE,CAAC,YAAY,CAAC;IAC5B,kBAAkB,EAAE,KAAK;IACzB,oBAAoB,EAAE,KAAK;CAC9B,CAAC;AAEF,QAAQ,CAAC,uCAAuC,EAAE;IAC9C,EAAE,CAAC,+EAA+E,EAAE;QAChF,IAAM,cAAc,GAAG,IAAA,iDAA+B,EAAC,YAAY,EAAE;YACjE,EAAE,IAAI,EAAE,4BAAmB,CAAC,IAAI,EAAE;YAClC,EAAE,IAAI,EAAE,4BAAmB,CAAC,EAAE,EAAE;SACnC,CAAC,CAAC;QAEH,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,4BAAmB,CAAC,EAAE,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uDAAuD,EAAE;QACxD,MAAM,CAAC,cAAM,OAAA,IAAA,iDAA+B,wCACrC,YAAY,KACf,kBAAkB,EAAE,EAAE,EACtB,UAAU,EAAE,EAAE,KACf;YACC,EAAE,IAAI,EAAE,4BAAmB,CAAC,IAAI,EAAE;SACrC,EAAE,YAAY,CAAC,EANH,CAMG,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qEAAqE,EAAE;QACtE,IAAM,cAAc,GAAG,IAAA,iDAA+B,EAAC,YAAY,EAAE;YACjE,EAAE,IAAI,EAAE,4BAAmB,CAAC,IAAI,EAAE;SACrC,EAAE,YAAY,CAAC,CAAC;QAEjB,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,4BAAmB,CAAC,EAAE,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ var urgent_1 = require("../urgent");
5
+ var consts_1 = require("../consts");
6
+ var baseApproval = {
7
+ _id: 'approval-1',
8
+ owner: 'user-1',
9
+ space: 'space-1',
10
+ name: '测试审批单',
11
+ current_step: consts_1.Step.departmental_review,
12
+ review_postponed_users: [],
13
+ is_urgent: false,
14
+ urgent_times: 0,
15
+ person_pending_approve: []
16
+ };
17
+ var createCtx = function (_a) {
18
+ var _b = _a === void 0 ? {} : _a, _c = _b.approval, approval = _c === void 0 ? baseApproval : _c, _d = _b.quota, quota = _d === void 0 ? { _id: 'quota-1', h1_used: 0, h2_used: 0 } : _d;
19
+ var objects = {
20
+ pepsico_material_approval: {
21
+ findOne: jest.fn(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
22
+ return [2, approval];
23
+ }); }); }),
24
+ directUpdate: jest.fn()
25
+ },
26
+ pepsico_urgent_quota: {
27
+ findOne: jest.fn(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
28
+ return [2, quota];
29
+ }); }); }),
30
+ directUpdate: jest.fn(),
31
+ insert: jest.fn()
32
+ },
33
+ pepsico_urgent_log: {
34
+ insert: jest.fn()
35
+ },
36
+ space_users: {
37
+ findOne: jest.fn(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
38
+ return [2, ({ is_collaborator: false })];
39
+ }); }); }),
40
+ find: jest.fn(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
41
+ return [2, []];
42
+ }); }); })
43
+ }
44
+ };
45
+ return {
46
+ objects: objects,
47
+ ctx: {
48
+ getObject: jest.fn(function (name) { return objects[name]; }),
49
+ broker: {
50
+ call: jest.fn()
51
+ }
52
+ }
53
+ };
54
+ };
55
+ describe('urgent approval', function () {
56
+ beforeEach(function () {
57
+ jest.useFakeTimers().setSystemTime(new Date('2026-05-30T00:00:00.000Z'));
58
+ });
59
+ afterEach(function () {
60
+ jest.useRealTimers();
61
+ });
62
+ it('does not allow urgent approval when reviewers are postponed', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
63
+ var ctx;
64
+ return tslib_1.__generator(this, function (_a) {
65
+ switch (_a.label) {
66
+ case 0:
67
+ ctx = createCtx({
68
+ approval: tslib_1.__assign(tslib_1.__assign({}, baseApproval), { review_postponed_users: ['reviewer-1'] })
69
+ }).ctx;
70
+ return [4, expect((0, urgent_1.canUrgent)(ctx, 'approval-1', 'user-1')).resolves.toEqual({
71
+ canUrgent: false,
72
+ reason: '存在延后审核人,无法加急'
73
+ })];
74
+ case 1:
75
+ _a.sent();
76
+ return [2];
77
+ }
78
+ });
79
+ }); });
80
+ it('does not allow urgent approval when quota is not configured', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
81
+ var ctx;
82
+ return tslib_1.__generator(this, function (_a) {
83
+ switch (_a.label) {
84
+ case 0:
85
+ ctx = createCtx({ quota: null }).ctx;
86
+ return [4, expect((0, urgent_1.canUrgent)(ctx, 'approval-1', 'user-1')).resolves.toEqual({
87
+ canUrgent: false,
88
+ reason: '未配置加急次数',
89
+ quota: {
90
+ available: 0,
91
+ used: 0,
92
+ total: 0,
93
+ year: 2026,
94
+ half: 1,
95
+ configured: false
96
+ }
97
+ })];
98
+ case 1:
99
+ _a.sent();
100
+ return [2];
101
+ }
102
+ });
103
+ }); });
104
+ it('does not auto-create quota records when executing urgent approval without configuration', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
105
+ var _a, ctx, objects;
106
+ return tslib_1.__generator(this, function (_b) {
107
+ switch (_b.label) {
108
+ case 0:
109
+ _a = createCtx({ quota: null }), ctx = _a.ctx, objects = _a.objects;
110
+ return [4, expect((0, urgent_1.doUrgent)(ctx, 'approval-1', 'user-1')).rejects.toThrow('未配置加急次数')];
111
+ case 1:
112
+ _b.sent();
113
+ expect(objects.pepsico_urgent_quota.insert).not.toHaveBeenCalled();
114
+ expect(objects.pepsico_material_approval.directUpdate).not.toHaveBeenCalled();
115
+ expect(objects.pepsico_urgent_log.insert).not.toHaveBeenCalled();
116
+ return [2];
117
+ }
118
+ });
119
+ }); });
120
+ });
121
+ //# sourceMappingURL=urgent.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"urgent.test.js","sourceRoot":"","sources":["../../../src/methods/__tests__/urgent.test.ts"],"names":[],"mappings":";;;AAAA,oCAAgD;AAChD,oCAAiC;AAEjC,IAAM,YAAY,GAAQ;IACtB,GAAG,EAAE,YAAY;IACjB,KAAK,EAAE,QAAQ;IACf,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,OAAO;IACb,YAAY,EAAE,aAAI,CAAC,mBAAmB;IACtC,sBAAsB,EAAE,EAAE;IAC1B,SAAS,EAAE,KAAK;IAChB,YAAY,EAAE,CAAC;IACf,sBAAsB,EAAE,EAAE;CAC7B,CAAC;AAEF,IAAM,SAAS,GAAG,UAAC,EAAoF;QAApF,qBAAkF,EAAE,KAAA,EAAlF,gBAAuB,EAAvB,QAAQ,mBAAG,YA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AO,CAAC,SAAS,CAAC,EAAA;;oBAA9E,SAA8E,CAAC;oBAC/E,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;oBACnE,MAAM,CAAC,OAAO,CAAC,yBAAyB,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;oBAC9E,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;;;;SACpE,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
- import { MaterialApproval, ApprovalStatus } from "./consts";
1
+ import { MaterialApproval, ApprovalStatus, ProcessApprovalType } from "./consts";
2
2
  export declare const getDefApproverStepRule: (ctx: any) => Promise<any>;
3
3
  export declare const getApproverStepRule: (ctx: any, ruleId?: string) => Promise<any>;
4
4
  export declare const hasAnyPreReviewer: (materialApproval: MaterialApproval, approvalType: string) => boolean;
@@ -36,4 +36,5 @@ export declare const submitContent: (ctx: any, recordId: any, currentStepApprova
36
36
  data: {};
37
37
  }>;
38
38
  export declare const hasReviewed: (approvalStatus: any) => boolean;
39
+ export declare const getPostponeReviewDepartmentType: (record: MaterialApproval, userProcessRecords: any[], userId?: string) => ProcessApprovalType;
39
40
  export declare const postponeReview: (ctx: any, recordId: any, data: any) => Promise<{}>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
- var _a;
2
+ var _a, _b, _c;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.postponeReview = exports.hasReviewed = exports.submitContent = exports.submitPreReviewContent = exports.submitKidsContent = exports.rejectContent = exports.approvalContent = exports.postponeDeployment = exports.confirmDeployment = exports.terminate = exports.advanceApproval = exports.hasNonPreReviewDepartments = exports.getPreReviewStatuses = exports.getDeptEffectiveStatus = exports.isDeptReviewComplete = exports.hasAnyPreReviewer = exports.getApproverStepRule = exports.getDefApproverStepRule = void 0;
4
+ exports.postponeReview = exports.getPostponeReviewDepartmentType = exports.hasReviewed = exports.submitContent = exports.submitPreReviewContent = exports.submitKidsContent = exports.rejectContent = exports.approvalContent = exports.postponeDeployment = exports.confirmDeployment = exports.terminate = exports.advanceApproval = exports.hasNonPreReviewDepartments = exports.getPreReviewStatuses = exports.getDeptEffectiveStatus = exports.isDeptReviewComplete = exports.hasAnyPreReviewer = exports.getApproverStepRule = exports.getDefApproverStepRule = void 0;
5
5
  var tslib_1 = require("tslib");
6
6
  var consts_1 = require("./consts");
7
7
  var amis_formula_1 = require("amis-formula");
@@ -2063,9 +2063,86 @@ var TYPE_TO_REVIEWER_FIELD = (_a = {},
2063
2063
  _a[consts_1.ProcessApprovalType.PreCA] = 'pre_ca_reviewer',
2064
2064
  _a[consts_1.ProcessApprovalType.Preguding] = 'pre_reviewer',
2065
2065
  _a);
2066
+ var TYPE_TO_HANDLER_FIELD = (_b = {},
2067
+ _b[consts_1.ProcessApprovalType.NS] = 'handler_ns',
2068
+ _b[consts_1.ProcessApprovalType.Legal] = 'handler_legal',
2069
+ _b[consts_1.ProcessApprovalType.SRA] = 'handler_sra',
2070
+ _b[consts_1.ProcessApprovalType.CA] = 'handler_ca',
2071
+ _b[consts_1.ProcessApprovalType.guding] = 'handler_guding',
2072
+ _b[consts_1.ProcessApprovalType.Kids] = 'handler_kids',
2073
+ _b[consts_1.ProcessApprovalType.PreNS] = 'handler_prens',
2074
+ _b[consts_1.ProcessApprovalType.PreLegal] = 'handler_prelegal',
2075
+ _b[consts_1.ProcessApprovalType.PreSRA] = 'handler_presra',
2076
+ _b[consts_1.ProcessApprovalType.PreCA] = 'handler_preca',
2077
+ _b[consts_1.ProcessApprovalType.Preguding] = 'handler_preguding',
2078
+ _b);
2079
+ var TYPE_TO_STATUS_FIELD = (_c = {},
2080
+ _c[consts_1.ProcessApprovalType.NS] = 'ns_approval_status',
2081
+ _c[consts_1.ProcessApprovalType.Legal] = 'legal_approval_status',
2082
+ _c[consts_1.ProcessApprovalType.SRA] = 'sra_approval_status',
2083
+ _c[consts_1.ProcessApprovalType.CA] = 'ca_approval_status',
2084
+ _c[consts_1.ProcessApprovalType.guding] = 'approval_status',
2085
+ _c[consts_1.ProcessApprovalType.Kids] = 'kids_approval_status',
2086
+ _c[consts_1.ProcessApprovalType.PreNS] = 'pre_ns_approval_status',
2087
+ _c[consts_1.ProcessApprovalType.PreLegal] = 'pre_legal_approval_status',
2088
+ _c[consts_1.ProcessApprovalType.PreSRA] = 'pre_sra_approval_status',
2089
+ _c[consts_1.ProcessApprovalType.PreCA] = 'pre_ca_approval_status',
2090
+ _c[consts_1.ProcessApprovalType.Preguding] = 'pre_approval_status',
2091
+ _c);
2092
+ var POSTPONE_REVIEW_TYPE_PRIORITY = [
2093
+ consts_1.ProcessApprovalType.CA,
2094
+ consts_1.ProcessApprovalType.SRA,
2095
+ consts_1.ProcessApprovalType.NS,
2096
+ consts_1.ProcessApprovalType.Legal,
2097
+ consts_1.ProcessApprovalType.guding,
2098
+ consts_1.ProcessApprovalType.PreCA,
2099
+ consts_1.ProcessApprovalType.PreSRA,
2100
+ consts_1.ProcessApprovalType.PreNS,
2101
+ consts_1.ProcessApprovalType.PreLegal,
2102
+ consts_1.ProcessApprovalType.Preguding
2103
+ ];
2104
+ var getUsersValue = function (val) {
2105
+ if (!val)
2106
+ return [];
2107
+ return Array.isArray(val) ? val : [val];
2108
+ };
2109
+ var isUserInRecordType = function (record, type, userId) {
2110
+ var handlerField = TYPE_TO_HANDLER_FIELD[type];
2111
+ var reviewerField = TYPE_TO_REVIEWER_FIELD[type];
2112
+ var handlerUsers = handlerField ? getUsersValue(record[handlerField]) : [];
2113
+ var reviewerUsers = reviewerField ? getUsersValue(record[reviewerField]) : [];
2114
+ var candidateUsers = handlerUsers.length > 0 ? handlerUsers : reviewerUsers;
2115
+ return (0, lodash_1.includes)(candidateUsers, userId);
2116
+ };
2117
+ var getPostponeReviewDepartmentType = function (record, userProcessRecords, userId) {
2118
+ var processTypes = (0, lodash_1.compact)((0, lodash_1.uniq)((0, lodash_1.map)(userProcessRecords || [], 'type')));
2119
+ var eligibleProcessType = processTypes.find(function (type) {
2120
+ if (type === consts_1.ProcessApprovalType.Kids)
2121
+ return false;
2122
+ var statusField = TYPE_TO_STATUS_FIELD[type];
2123
+ return !!statusField && record[statusField] === false;
2124
+ });
2125
+ if (eligibleProcessType) {
2126
+ return eligibleProcessType;
2127
+ }
2128
+ if (userId) {
2129
+ var eligibleRecordType = POSTPONE_REVIEW_TYPE_PRIORITY.find(function (type) {
2130
+ var statusField = TYPE_TO_STATUS_FIELD[type];
2131
+ return !!statusField && record[statusField] === false && isUserInRecordType(record, type, userId);
2132
+ });
2133
+ if (eligibleRecordType) {
2134
+ return eligibleRecordType;
2135
+ }
2136
+ }
2137
+ if (processTypes.includes(consts_1.ProcessApprovalType.Kids) || (userId && isUserInRecordType(record, consts_1.ProcessApprovalType.Kids, userId))) {
2138
+ throw new Error('Kids审核人不支持延后审核操作');
2139
+ }
2140
+ throw new Error('仅驳回审批单后可以延后审核');
2141
+ };
2142
+ exports.getPostponeReviewDepartmentType = getPostponeReviewDepartmentType;
2066
2143
  var postponeReview = function (ctx, recordId, data) {
2067
2144
  return tslib_1.__awaiter(this, void 0, void 0, function () {
2068
- var user, record, progessRecords, userProcessRecords, departmentType, reviewerField, deptUserIds, val, now, unactivatedMarkers, latestMarker, _a, _b, marker, e_13_1, visibleAfter, markersToActivate, markersToActivate_1, markersToActivate_1_1, marker, e_14_1, currentRecord, currentPostponed, newPostponed;
2145
+ var user, record, reviewSteps, progessRecords, userProcessRecords, departmentType, statusField, reviewerField, handlerField, deptUserIds, now, unactivatedMarkers, latestMarker, _a, _b, marker, e_13_1, currentMarkerUsers, newMarkerUsers, visibleAfter, markersToActivate, markersToActivate_1, markersToActivate_1_1, marker, e_14_1, currentRecord, currentPostponed, newPostponed;
2069
2146
  var e_13, _c, e_14, _d;
2070
2147
  return tslib_1.__generator(this, function (_e) {
2071
2148
  switch (_e.label) {
@@ -2074,9 +2151,13 @@ var postponeReview = function (ctx, recordId, data) {
2074
2151
  return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
2075
2152
  case 1:
2076
2153
  record = _e.sent();
2077
- if (record.current_step !== consts_1.Step.departmental_review && record.current_step !== consts_1.Step.personnel_review) {
2154
+ reviewSteps = [consts_1.Step.departmental_review, consts_1.Step.personnel_review];
2155
+ if (!reviewSteps.includes(record.current_step) && record.current_step !== consts_1.Step.submitter_revisions) {
2078
2156
  throw new Error('当前步骤不支持延后审核操作');
2079
2157
  }
2158
+ if (record.is_urgent) {
2159
+ throw new Error('加急审批单不允许延后审核');
2160
+ }
2080
2161
  if (!(0, lodash_1.includes)(record.person_approved, user.userId)) {
2081
2162
  throw new Error('您不在当前已审批人列表中');
2082
2163
  }
@@ -2100,22 +2181,28 @@ var postponeReview = function (ctx, recordId, data) {
2100
2181
  ['space', '=', record.space]
2101
2182
  ],
2102
2183
  sort: 'created desc',
2103
- top: 1
2104
2184
  })];
2105
2185
  case 3:
2106
2186
  userProcessRecords = _e.sent();
2107
2187
  if (!userProcessRecords || userProcessRecords.length === 0) {
2108
2188
  throw new Error('未找到您的审核记录');
2109
2189
  }
2110
- departmentType = userProcessRecords[0].type;
2190
+ departmentType = (0, exports.getPostponeReviewDepartmentType)(record, userProcessRecords, user.userId);
2111
2191
  if (!departmentType) {
2112
2192
  throw new Error('无法确定您所在的审核部门');
2113
2193
  }
2194
+ statusField = TYPE_TO_STATUS_FIELD[departmentType];
2195
+ if (!statusField || record[statusField] !== false) {
2196
+ throw new Error('仅驳回审批单后可以延后审核');
2197
+ }
2114
2198
  reviewerField = TYPE_TO_REVIEWER_FIELD[departmentType];
2199
+ handlerField = TYPE_TO_HANDLER_FIELD[departmentType];
2115
2200
  deptUserIds = [];
2116
- if (reviewerField && record[reviewerField]) {
2117
- val = record[reviewerField];
2118
- deptUserIds = Array.isArray(val) ? val : [val];
2201
+ if (handlerField && record[handlerField]) {
2202
+ deptUserIds = getUsersValue(record[handlerField]);
2203
+ }
2204
+ else if (reviewerField && record[reviewerField]) {
2205
+ deptUserIds = getUsersValue(record[reviewerField]);
2119
2206
  }
2120
2207
  if (deptUserIds.length === 0) {
2121
2208
  deptUserIds = [user.userId];
@@ -2199,6 +2286,16 @@ var postponeReview = function (ctx, recordId, data) {
2199
2286
  _e.label = 16;
2200
2287
  case 16:
2201
2288
  console.log("[postponeReview] recordId=".concat(recordId, ", departmentType=").concat(departmentType, ", deptUserIds=").concat(deptUserIds, ", markedForNextRound=true"));
2289
+ if (!(record.current_step === consts_1.Step.submitter_revisions)) return [3, 18];
2290
+ currentMarkerUsers = record.postpone_marker_users || [];
2291
+ newMarkerUsers = (0, lodash_1.compact)((0, lodash_1.uniq)((0, lodash_1.concat)(currentMarkerUsers, deptUserIds)));
2292
+ return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
2293
+ postpone_marker_users: newMarkerUsers
2294
+ })];
2295
+ case 17:
2296
+ _e.sent();
2297
+ return [2, {}];
2298
+ case 18:
2202
2299
  visibleAfter = new Date(now.getTime() + 3 * 24 * 60 * 60 * 1000);
2203
2300
  return [4, ctx.getObject('pepsico_review_postpone').directFind({
2204
2301
  filters: [
@@ -2208,15 +2305,15 @@ var postponeReview = function (ctx, recordId, data) {
2208
2305
  ['space', '=', record.space]
2209
2306
  ]
2210
2307
  })];
2211
- case 17:
2308
+ case 19:
2212
2309
  markersToActivate = _e.sent();
2213
- _e.label = 18;
2214
- case 18:
2215
- _e.trys.push([18, 23, 24, 25]);
2310
+ _e.label = 20;
2311
+ case 20:
2312
+ _e.trys.push([20, 25, 26, 27]);
2216
2313
  markersToActivate_1 = tslib_1.__values(markersToActivate), markersToActivate_1_1 = markersToActivate_1.next();
2217
- _e.label = 19;
2218
- case 19:
2219
- if (!!markersToActivate_1_1.done) return [3, 22];
2314
+ _e.label = 21;
2315
+ case 21:
2316
+ if (!!markersToActivate_1_1.done) return [3, 24];
2220
2317
  marker = markersToActivate_1_1.value;
2221
2318
  return [4, ctx.getObject('pepsico_review_postpone').directUpdate(marker._id, {
2222
2319
  is_marker: false,
@@ -2226,32 +2323,32 @@ var postponeReview = function (ctx, recordId, data) {
2226
2323
  modified: now,
2227
2324
  modified_by: user.userId
2228
2325
  })];
2229
- case 20:
2326
+ case 22:
2230
2327
  _e.sent();
2231
- _e.label = 21;
2232
- case 21:
2233
- markersToActivate_1_1 = markersToActivate_1.next();
2234
- return [3, 19];
2235
- case 22: return [3, 25];
2328
+ _e.label = 23;
2236
2329
  case 23:
2330
+ markersToActivate_1_1 = markersToActivate_1.next();
2331
+ return [3, 21];
2332
+ case 24: return [3, 27];
2333
+ case 25:
2237
2334
  e_14_1 = _e.sent();
2238
2335
  e_14 = { error: e_14_1 };
2239
- return [3, 25];
2240
- case 24:
2336
+ return [3, 27];
2337
+ case 26:
2241
2338
  try {
2242
2339
  if (markersToActivate_1_1 && !markersToActivate_1_1.done && (_d = markersToActivate_1.return)) _d.call(markersToActivate_1);
2243
2340
  }
2244
2341
  finally { if (e_14) throw e_14.error; }
2245
2342
  return [7];
2246
- case 25: return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
2247
- case 26:
2343
+ case 27: return [4, ctx.getObject('pepsico_material_approval').findOne(recordId)];
2344
+ case 28:
2248
2345
  currentRecord = _e.sent();
2249
2346
  currentPostponed = currentRecord.review_postponed_users || [];
2250
2347
  newPostponed = (0, lodash_1.compact)((0, lodash_1.uniq)((0, lodash_1.concat)(currentPostponed, deptUserIds)));
2251
2348
  return [4, ctx.getObject('pepsico_material_approval').directUpdate(recordId, {
2252
2349
  review_postponed_users: newPostponed
2253
2350
  })];
2254
- case 27:
2351
+ case 29:
2255
2352
  _e.sent();
2256
2353
  console.log("[postponeReview] \u7ACB\u5373\u6FC0\u6D3B\u5EF6\u540E: recordId=".concat(recordId, ", deptUserIds=").concat(deptUserIds, ", visibleAfter=").concat(visibleAfter));
2257
2354
  return [2, {}];