-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsys-approval-request.object.ts
More file actions
401 lines (375 loc) · 14.7 KB
/
Copy pathsys-approval-request.object.ts
File metadata and controls
401 lines (375 loc) · 14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { ObjectSchema, Field } from '@objectstack/spec/data';
/**
* sys_approval_request — Live approval instance.
*
* ADR-0019: opened by a flow's **Approval node** when the run reaches it; the
* run suspends until a decision is recorded. The row's lifecycle:
*
* `pending` → (per-approver decisions) → `approved` | `rejected`
* `pending` → recalled by submitter → `recalled`
*
* `flow_run_id` / `flow_node_id` tie the request back to the suspended run so a
* decision can resume it; `current_step` mirrors the node id. `node_config_json`
* snapshots the Approval node config (approvers / behaviour) the request was
* opened with.
*
* `payload_json` captures a snapshot of the target record at submission
* time — used by notifications so they can render before the record is
* locked or changed.
*
* @namespace sys
*/
export const SysApprovalRequest = ObjectSchema.create({
name: 'sys_approval_request',
label: 'Approval Request',
pluralLabel: 'Approval Requests',
icon: 'inbox',
isSystem: true,
managedBy: 'system',
description: 'Live approval instance tracked per submission',
displayNameField: 'id',
nameField: 'id', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField)
titleFormat: '{process_name} · {record_id}',
highlightFields: ['process_name', 'object_name', 'record_id', 'status', 'current_step', 'submitter_id', 'updated_at'],
// Curated built-in list views — render as segmented tabs in the console.
// Filters use {current_user_id} substitution wired by the console.
listViews: {
my_pending: {
type: 'grid',
name: 'my_pending',
label: 'My Pending',
data: { provider: 'object', object: 'sys_approval_request' },
columns: ['process_name', 'object_name', 'record_id', 'current_step', 'submitter_id', 'updated_at'],
filter: [
{ field: 'status', operator: 'equals', value: 'pending' },
{ field: 'pending_approvers', operator: 'contains', value: '{current_user_id}' },
],
sort: [{ field: 'updated_at', order: 'desc' }],
pagination: { pageSize: 25 },
emptyState: { title: 'No pending approvals', message: 'You\'re all caught up.' },
},
submitted_by_me: {
type: 'grid',
name: 'submitted_by_me',
label: 'I Submitted',
data: { provider: 'object', object: 'sys_approval_request' },
columns: ['process_name', 'object_name', 'record_id', 'status', 'current_step', 'updated_at'],
filter: [{ field: 'submitter_id', operator: 'equals', value: '{current_user_id}' }],
sort: [{ field: 'updated_at', order: 'desc' }],
pagination: { pageSize: 25 },
},
completed: {
type: 'grid',
name: 'completed',
label: 'Completed',
data: { provider: 'object', object: 'sys_approval_request' },
columns: ['process_name', 'object_name', 'record_id', 'status', 'submitter_id', 'completed_at'],
filter: [{ field: 'status', operator: 'in', value: ['approved', 'rejected', 'recalled'] }],
sort: [{ field: 'completed_at', order: 'desc' }],
pagination: { pageSize: 25 },
},
all_requests: {
type: 'grid',
name: 'all_requests',
label: 'All',
data: { provider: 'object', object: 'sys_approval_request' },
columns: ['process_name', 'object_name', 'record_id', 'status', 'current_step', 'submitter_id', 'updated_at'],
sort: [{ field: 'updated_at', order: 'desc' }],
pagination: { pageSize: 50 },
},
},
fields: {
id: Field.text({ label: 'Request ID', required: true, readonly: true, group: 'System' }),
organization_id: Field.lookup('sys_organization', {
label: 'Organization',
required: false,
group: 'System',
description: 'Tenant that owns this approval request (propagated from submitter context)',
}),
process_name: Field.text({
label: 'Source',
required: true,
maxLength: 100,
description: 'Origin of the request — `flow:<flowName|nodeId>` for node-driven approvals',
group: 'Target',
}),
object_name: Field.text({
label: 'Object',
required: true,
maxLength: 100,
group: 'Target',
}),
record_id: Field.text({
label: 'Record ID',
required: true,
maxLength: 100,
group: 'Target',
}),
submitter_id: Field.lookup('sys_user', {
label: 'Submitter',
required: false,
group: 'Target',
}),
submitter_comment: Field.textarea({
label: 'Submitter Comment',
required: false,
group: 'Target',
}),
status: Field.select(
// Keep in sync with `ApprovalStatus` (spec/contracts). `returned` =
// sent back for revision (ADR-0044) — terminal for this round.
['pending', 'approved', 'rejected', 'recalled', 'returned'],
{
label: 'Status',
required: true,
defaultValue: 'pending',
description: 'Lifecycle state of the request',
group: 'State',
},
),
current_step: Field.text({
label: 'Current Step',
required: false,
maxLength: 100,
description: 'Machine name of the step awaiting approval',
group: 'State',
}),
current_step_index: Field.number({
label: 'Current Step Index',
required: false,
defaultValue: 0,
group: 'State',
}),
pending_approvers: Field.textarea({
label: 'Pending Approvers',
required: false,
description: 'Comma-separated user ids who can act on the current step',
group: 'State',
}),
payload_json: Field.textarea({
label: 'Snapshot',
required: false,
description: 'Record snapshot at submission time',
group: 'State',
}),
// ── ADR-0019: approval-as-flow-node correlation ──────────────────
// When a request is opened by an Approval *node* (rather than a standalone
// process), these tie it back to the suspended flow run so a decision can
// resume it. Null for legacy process-driven requests.
flow_run_id: Field.text({
label: 'Flow Run',
required: false,
maxLength: 100,
readonly: true,
description: 'Suspended automation run id this request gates (ADR-0019). The decision resumes it.',
group: 'State',
}),
flow_node_id: Field.text({
label: 'Flow Node',
required: false,
maxLength: 100,
readonly: true,
description: 'Approval node id within the flow that opened this request (ADR-0019).',
group: 'State',
}),
node_config_json: Field.textarea({
label: 'Node Config',
required: false,
readonly: true,
description: 'Snapshot of the Approval node config (approvers/behavior) for node-driven requests (ADR-0019).',
group: 'State',
}),
completed_at: Field.datetime({
label: 'Completed At',
required: false,
group: 'State',
}),
created_at: Field.datetime({
label: 'Created At',
required: true,
defaultValue: 'NOW()',
readonly: true,
group: 'System',
}),
updated_at: Field.datetime({ label: 'Updated At', required: false, group: 'System' }),
},
indexes: [
// Look up "is there a pending request for this record?" — common
// guard on submit and on edit-while-locked checks.
{ fields: ['object_name', 'record_id'] },
{ fields: ['status', 'object_name'] },
// Status-windowed listings (escalation sweep, "All" tab ordering).
// "My approvals" matching no longer scans this table: the service keeps
// a normalized per-approver index in `sys_approval_approver` (#1745) and
// resolves approver filters there; `pending_approvers` stays the
// human-readable CSV source of truth only.
{ fields: ['status', 'updated_at'] },
{ fields: ['submitter_id', 'status'] },
],
// Server-declared decision actions (objectui#2678 P2-4). The console's
// generic action runtime renders and executes these wherever this object is
// surfaced — the approvals inbox included — so new decision capabilities
// (and their params) ship as metadata, not as hand-written buttons. Each
// targets the existing approvals REST route; `{id}` resolves from the row
// and `actorId` defaults to the caller server-side. The service remains the
// authority on who may act; `visible` gates on the server-computed
// per-viewer block (#3310): approver actions on `record.viewer.can_act`
// (the caller is a current pending approver — same check the service
// authorizes a decision with, so position/team approvers resolve correctly),
// submitter actions on `record.viewer.is_submitter`. `viewer` is attached by
// getRequest/listRequests; where it is absent the predicate fails closed.
actions: [
{
name: 'approval_approve',
label: 'Approve',
icon: 'check-circle',
type: 'api',
method: 'POST',
target: '/api/v1/approvals/requests/{id}/approve',
params: [
{ name: 'comment', label: 'Comment', type: 'textarea', required: false },
// Decision attachments (#3266). The console renders `type:'file'` params
// through the shared upload widget and POSTs the resolved `attachments:
// string[]`; the decision route persists them on `sys_approval_action`.
{ name: 'attachments', label: 'Attachments', type: 'file', multiple: true, required: false },
],
visible: 'record.viewer.can_act',
locations: ['record_section', 'list_item'],
successMessage: 'Approved.',
refreshAfter: true,
},
{
name: 'approval_reject',
label: 'Reject',
icon: 'x-circle',
type: 'api',
method: 'POST',
target: '/api/v1/approvals/requests/{id}/reject',
params: [
{ name: 'comment', label: 'Comment', type: 'textarea', required: false },
{ name: 'attachments', label: 'Attachments', type: 'file', multiple: true, required: false },
],
visible: 'record.viewer.can_act',
confirmText: 'Reject this request? A rejection is final for every approver.',
locations: ['record_section', 'list_item'],
successMessage: 'Rejected.',
refreshAfter: true,
},
{
name: 'approval_reassign',
label: 'Reassign',
icon: 'arrow-right-left',
type: 'api',
method: 'POST',
target: '/api/v1/approvals/requests/{id}/reassign',
params: [
// Field-backed on `submitter_id` (the object's only `sys_user` lookup):
// the console resolves its lookup config (`reference_to: sys_user`) so the
// dialog renders a real user picker, while `name: 'to'` overrides the
// request-body key to the `to` the reassign route expects. This is a
// config-borrow, not a submitter pre-fill (`defaultFromRow` stays off).
{ field: 'submitter_id', name: 'to', label: 'New approver', required: true, helpText: 'User to hand this step to' },
{ name: 'comment', label: 'Comment', type: 'textarea', required: false },
],
visible: 'record.viewer.can_act',
locations: ['record_section'],
successMessage: 'Reassigned.',
refreshAfter: true,
},
// ── Approver secondary decisions ────────────────────────────────
// Send back for revision / request more info (ADR-0044). Both are approver
// actions, so `visible` gates on `record.viewer.can_act` (a current pending
// approver) — same as approve/reject. The service stays the authority.
{
name: 'approval_send_back',
label: 'Send back',
icon: 'corner-up-left',
type: 'api',
method: 'POST',
target: '/api/v1/approvals/requests/{id}/revise',
params: [
{ name: 'comment', label: 'Reason', type: 'textarea', required: false },
],
visible: 'record.viewer.can_act',
locations: ['record_section'],
successMessage: 'Sent back for revision.',
refreshAfter: true,
},
{
name: 'approval_request_info',
label: 'Request info',
icon: 'help-circle',
type: 'api',
method: 'POST',
target: '/api/v1/approvals/requests/{id}/request-info',
params: [
{ name: 'comment', label: 'What do you need?', type: 'textarea', required: true },
],
visible: 'record.viewer.can_act',
locations: ['record_section'],
successMessage: 'Information requested.',
refreshAfter: true,
},
// ── Submitter continuity actions ────────────────────────────────
// Remind / recall (pending) and resubmit / recall (returned). These are the
// submitter's own levers, so `visible` gates on `record.viewer.is_submitter`
// (server-computed on the current viewer). The service re-checks ownership;
// the predicate keeps a non-submitter from ever seeing a button they cannot
// use.
{
name: 'approval_remind',
label: 'Send reminder',
icon: 'bell-ring',
type: 'api',
method: 'POST',
target: '/api/v1/approvals/requests/{id}/remind',
params: [
{ name: 'comment', label: 'Note', type: 'textarea', required: false },
],
visible: 'record.status == "pending" && record.viewer.is_submitter',
locations: ['record_section'],
successMessage: 'Reminder sent.',
refreshAfter: true,
},
{
name: 'approval_recall',
label: 'Recall',
icon: 'undo-2',
type: 'api',
method: 'POST',
target: '/api/v1/approvals/requests/{id}/recall',
params: [
{ name: 'comment', label: 'Comment', type: 'textarea', required: false },
],
// Recall applies while the request is live for the submitter — pending
// (withdraw) or returned (abandon the revision instead of resubmitting).
visible: '(record.status == "pending" || record.status == "returned") && record.viewer.is_submitter',
confirmText: 'Recall this request? Approvers can no longer act on it and the record is unlocked.',
locations: ['record_section'],
successMessage: 'Recalled.',
refreshAfter: true,
},
{
name: 'approval_resubmit',
label: 'Resubmit',
icon: 'refresh-cw',
type: 'api',
method: 'POST',
target: '/api/v1/approvals/requests/{id}/resubmit',
params: [
{ name: 'comment', label: 'What changed?', type: 'textarea', required: false },
],
visible: 'record.status == "returned" && record.viewer.is_submitter',
locations: ['record_section'],
successMessage: 'Resubmitted.',
refreshAfter: true,
},
],
enable: {
// [ADR-0103] Engine-owned: the approval engine owns the request lifecycle
// (SYSTEM_CTX); users act via domain actions (Submit/Approve/Recall), never
// generic CRUD. Reads stay open.
apiMethods: ['get', 'list'],
},
});