Repository navigation
Expand file tree
/
Copy pathsys-approval-request.object.ts
More file actions
968 lines (933 loc) · 51.3 KB
/
Copy pathsys-approval-request.object.ts
File metadata and controls
968 lines (933 loc) · 51.3 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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { ObjectSchema, Field } from '@objectstack/spec/data';
import { F } from '@objectstack/spec';
import {
APPROVAL_STATUSES,
APPROVAL_STATUS_LABELS,
APPROVAL_CANCEL_REASONS,
APPROVAL_CANCEL_REASON_LABELS,
} from '@objectstack/spec/contracts';
/**
* 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`
* `pending` → its record was deleted → `cancelled` + `cancel_reason`
*
* `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.
* It is retained as **audit evidence of what was actually submitted**, so the
* column stays whole AT REST; it is served **redacted per reader** — the
* SUBJECT object's field-level read controls are applied at serve time from
* the security service's `getReadableFields`, on the approvals-inbox door and
* on the generic data door alike (#11039).
*
* ⛔ Notifications are NOT a consumer of this snapshot, and the audit-evidence
* sentence above — not "notifications need it" — is why the column holds a
* full row. See the note on the field itself.
*
* @namespace sys
*/
export const SysApprovalRequest = ObjectSchema.create({
name: 'sys_approval_request',
label: 'Approval Request',
pluralLabel: 'Approval Requests',
icon: 'inbox',
isSystem: true,
managedBy: 'engine-owned',
description: 'Live approval instance tracked per submission',
// [decision 6840464379, as amended by ruling 6849636735 (1B, #32442)] The
// member baseline (`member_default`) grants every member a read on this
// object, and the request read gate (`request-read-gate.ts`) narrows the rows
// to the requests the approvals door would serve that member. The metadata
// API answers an object the caller may not read as absent (ADR-0106, ruling
// record 6787890900); with the baseline read, every member is served this
// definition, projected by their field security. The delegate stays: it
// answers a caller whose permission sets do not carry that read (a deployment
// that withdraws it) with the callers its door serves a request to
// (`ApprovalService.authorizeSchemaRead`).
schemaReadDelegate: 'approvals',
// [ADR-0079, ADR-0085] The record title is the flow's label, `process_label`:
// a STORED column, so every door that serves the row serves its title. The
// approvals get (`rowFromRequest`) serves it by the display-label chain — the
// column, else the config snapshot's label, else the humanized machine name —
// so the request page reached through that get always has a title, and it is
// never `flow:NAME`. The pointer used to be `display_title`, a formula: a
// formula has no column, the approvals get served no value for it, and the
// page fell through to the since-retired `titleFormat`, the machine name and
// the raw subject record id.
//
// The title names no subject record. The request page names the subject on
// the card the `record_id` / `object_name` pair draws in the Details tab,
// which says so when the reader may not read the record or it was deleted;
// a title cannot, so a bare record id is never shown there.
//
// Where `process_label` is empty — a row written before the column, until the
// boot fill labels it (`display-label-backfill.ts`) — the retired
// `titleFormat` template `{process_name}` drew the machine source; it is gone
// (refused at save and by `os validate`), and `display_title` draws that same
// fallback. `sys-approval-display-title.test.ts` and
// `sys-approval-request-title.integration.test.ts` pin the title.
displayNameField: 'process_label',
nameField: 'process_label', // [ADR-0079] canonical primary-title pointer (mirrors deprecated displayNameField)
// [ADR-0085] The flow is named by its label, `process_label`, never by the
// machine source `process_name` (`flow:NAME`), and the step by its label,
// `current_step_label`, never by the node id `current_step`, as the request
// lists name them. The target object is not listed: `object_name` holds its
// API name, and the record page names it by its label on the card the
// `record_id` / `object_name` pair draws. The record page's highlights strip
// is this list minus `record_id`, and the page's bare `record:details` node
// draws this list minus the strip, so the two move together
// (`sys-approval-request.page.ts` says why).
highlightFields: ['process_label', 'record_id', 'status', 'current_step_label', 'submitter_id', 'updated_at'],
// [#24625] Free-text search (ADR-0061) scans the auto-default set minus the
// snapshot, `payload_json`. A query naming the snapshot is refused to every
// reader withheld any field of any object (`payload-predicate-guard.ts`),
// and a `$search` names every searched column. With the snapshot in the
// set, one field withheld anywhere — an organization administrator's mail
// bodies — turned that reader's list search here, and its whole global
// search sweep, into a 403. A structured filter on the snapshot is
// unchanged, for the readers the guard admits.
searchableFields: [
'process_name', 'process_package', 'process_label', 'object_name', 'record_id', 'submitter_comment', 'status',
'cancel_reason', 'current_step', 'current_step_label', 'pending_approvers', 'pending_approver_labels',
'flow_run_id', 'flow_node_id', 'node_config_json',
],
// Curated built-in list views — render as segmented tabs in the console.
// Filters use {current_user_id} substitution wired by the console.
//
// `all_requests` is declared FIRST, and that position is the contract: when
// a route names no view, the console opens an object's first declared list
// view (objectui `ObjectView`: URL view id, `?view=`, `isDefault`, then
// `views[0]`). A caller-scoped view (`my_pending`, `submitted_by_me`) in
// first place turned Setup → Approvals → Requests, and every bare-object door
// (the record page's object breadcrumb, the object switcher), into a list of
// the caller's own rows. A caller-scoped list view is never an object's
// first; an entry that wants one names it. The order decides which view
// opens, never which rows a caller may read.
//
// The display columns (`process_label`, `current_step_label`,
// `pending_approver_labels`) are ENGINE-WRITTEN snapshots, set by
// `ApprovalService` on the writes that change the facts they describe. A list
// reads them as stored and never re-derives a label from flow metadata or
// resolves an approver address itself; `process_name`, `current_step` and
// `pending_approvers` keep the machine values every query and decision reads.
// [#27041] A reader with a locale is served `process_label` and
// `current_step_label` from the app's language pack where it carries them,
// overlaid on the read and never stored (`reader-locale-labels-middleware.ts`).
//
// The target is the `record_id` column alone. It is the pointer's id half,
// so the console draws the target record (its object's icon and name) and
// fetches the type half `object_name` for that cell without a column
// (objectui#13036). An `object_name` column drew the stored API name as
// text; no list view shows a pointer's type half
// (`sys-approval-request-pointer-pair.test.ts`).
listViews: {
all_requests: {
type: 'grid',
name: 'all_requests',
label: 'All',
data: { provider: 'object', object: 'sys_approval_request' },
columns: ['process_label', 'record_id', 'status', 'current_step_label', 'pending_approver_labels', 'submitter_id', 'updated_at'],
sort: [{ field: 'updated_at', order: 'desc' }],
pagination: { pageSize: 50 },
},
my_pending: {
type: 'grid',
name: 'my_pending',
label: 'My Pending',
data: { provider: 'object', object: 'sys_approval_request' },
columns: ['process_label', 'record_id', 'current_step_label', 'pending_approver_labels', '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_label', 'record_id', 'status', 'current_step_label', '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_label', 'record_id', 'status', 'submitter_id', 'completed_at'],
// Every terminal state, `cancelled` included (#13568) — a platform-voided
// request is kept as audit evidence, and a terminal state absent from the
// only curated terminal view is evidence nobody can find.
filter: [{ field: 'status', operator: 'in', value: ['approved', 'rejected', 'recalled', 'cancelled'] }],
sort: [{ field: 'completed_at', order: 'desc' }],
pagination: { pageSize: 25 },
},
},
fields: {
id: Field.text({ label: 'Request ID', required: true, readonly: true, group: 'System' }),
// [ADR-0079] The title text the data API computes on read: the flow's
// label, `process_label`, else the machine source `process_name` (required)
// where no label is stored — the text the title ladder draws from
// `nameField` above, on every row the engine writes (a writer stores a
// label or null, never a blank). A formula has no stored column. It names
// no subject record, as the title does not.
//
// It is no longer the title pointer (the approvals get serves no formula
// value), and it stays declared because stored activity rows name it: the
// activity mirror records the title field each row's summary and record
// label were composed from (`text_sources`, plugin-audit), and the read
// side serves those texts only while every field they name is one the
// reader is served. Retiring the field would withhold the text of every
// activity row written while it was the title.
display_title: Field.formula({
label: 'Title',
returnType: 'text',
expression: F`record.process_label != null ? record.process_label : record.process_name`,
description: 'Record title: the label of the flow that opened this request, else its source (computed on read)',
group: 'Target',
}),
// [#10101, the cloud#1395 Option A ruling] The SUBJECT record's
// organization, with the acting context as fallback — resolved by the
// SHARED platform-row resolver (`resolveRecordOrganizationField`,
// `@objectstack/metadata-core`) in `openNodeRequest`, the row's only
// writer. The same `requestOrg` stamps `sys_approval_action` and the
// `sys_approval_approver` index, so all three move together.
//
// Why subject-first: an approval request is read through the organization
// wall by the approvals inbox, and the acting context is NULL on every
// schedule / time-relative / api triggered run (none carries a tenant, by
// construction). Stamped from the actor alone — the pre-#10101 behaviour,
// measured on cloud#1395 as 27 of 27 rows org-less on a walled HotCRM SaaS
// boot — such a request LOCKED the record it was about while being
// invisible in every inbox, its owner's included. Subject-first is also
// what `sys_audit_log`'s writer already did (commit 1408fe385 honouring #8287's
// ruling), so an approval row and an audit row about the same record now
// land behind the same wall instead of two.
//
// The `sys_api_key` divergence is deliberate and preserved: its
// `tenancy.organizationField: 'active_organization_id'` (stamp-only,
// commit 7901b2dd2) wins limb 0 of the shared resolver, while the credential table
// itself stays unwalled (`tenancy.enabled: false`) — who a row is ABOUT
// and what an object is WALLED by remain different questions.
organization_id: Field.lookup('sys_organization', {
label: 'Organization',
required: false,
group: 'System',
// Reworded with the #10101 write-side fix (was "Tenant that owns this
// approval request (propagated from submitter context)" — it claimed a
// propagation that measurably did not happen, and said "Tenant" where
// ADR-0120 §Terminology requires "organization"). Extracted into the
// generated i18n bundles as `help`; the four locales regenerate in the
// same pass.
description: 'Organization of the record this request is about (falls back to the acting context when the record has none)',
}),
process_name: Field.text({
label: 'Source',
required: true,
maxLength: 100,
description: 'Origin of the request — `flow:<flowName|nodeId>` for node-driven approvals',
group: 'Target',
}),
// [ADR-0150 D8 row R7] The package that holds the flow `process_name`
// names (`flow:NAME`), beside the name (ADR-0126 §4: two facts, two
// columns). Stamped when the request opens, from its run's own slot
// (#31696), and backfilled at boot on OPEN requests only (`pending`, and
// `returned`, whose run waits in the revise window) from the flow's one
// package holder (`stored-process-package-backfill.ts`); a decided
// request stays as written. Empty for an environment-authored flow and
// for a name no single package holds. The request's flow is read by it
// (`ApprovalService.requestFlow`) once two packages hold the name. Width:
// the package-id class (`sys_metadata.package_id`).
process_package: Field.text({
label: 'Source Package',
required: false,
readonly: true,
maxLength: 255,
description: 'The app the flow that opened this request comes from. Filled in by the platform; empty for flows created here.',
group: 'Target',
}),
// The flow's authored label when the request was opened — a snapshot the
// engine writes once, in `openNodeRequest`, from the label the flow engine
// seeds as `$flowLabel` (`FlowSchema.label`, required). A rename of the flow
// later does not rewrite it: the row records what the approver was asked
// under. An empty or absent authored label falls through to the humanized
// machine name (`display-labels.ts`, the chain the approvals door serves).
// Rows opened before this column are filled by the boot backfill
// (`display-label-backfill.ts`) by the same chain.
process_label: Field.text({
label: 'Flow',
required: false,
maxLength: 255,
readonly: true,
description: 'Label of the flow that opened this request, as it stood when the request was opened',
group: 'Target',
}),
object_name: Field.text({
label: 'Object',
required: true,
maxLength: 100,
group: 'Target',
}),
record_id: Field.text({
label: 'Record',
required: true,
maxLength: 100,
// [#11386] The id half of this object's pointer pair (ADR-0052 §5),
// adopting the #11339 carrier. VERIFIED for THIS object: the pair is not
// decoration but the key the approval machinery QUERIES ON —
// `approval-service.ts` finds a record's pending request with
// `where: { object_name, record_id, status: 'pending' }`, and
// `lifecycle-hooks.ts` holds the record LOCK on the same pair
// (single-record and `$in` batch forms). `submit()` writes it from
// `input.object` / `input.recordId`, so a stored value is always a
// record id of the object the sibling names.
//
// Consequence of declaring, sharper here than elsewhere: a seeded
// request whose `record_id` stayed a verbatim natural key locked
// NOTHING and appeared under no record — it looked like a pending
// approval while being invisible to both queries that give the row its
// meaning. That is now a loud seed-time refusal. Both halves are
// `required: true`, so the un-addressable case (id half authored, type
// half empty) is already unreachable on this object.
group: 'Target',
//
// ⚠️ ORDERING CONSTRAINT — this id half is `required: true`, and that
// makes it ORDER-DEPENDENT in seeds even though a pointer pair
// contributes no static ordering edge (commit 1cba33f16, measured against the real
// engine in `packages/objectql/src/engine-seed-required-deferral.test.ts`):
// the seed loader defers an unresolvable reference by DELETING the column
// from the pass-1 insert, required-validation rejects that row, and pass 2
// is then left with no row to back-fill. So the pass-2 healing that makes
// an OPTIONAL id half order-independent (`sys_audit_log`) does not reach
// this one. ⇒ SEED THE TARGET DATASET FIRST. The failure if you do not is
// loud in three places — a write error naming this column, a
// dropped-deferral error, and `success: false` — and since commit 1cba33f16 the
// loader also WARNS at load time, before the engine rejects the row.
referenceVia: 'object_name',
// A `cancelled` request whose `cancel_reason` is `record_deleted` names a
// record the platform deleted: a renderer draws that option's label, not a link.
referenceDeletedWhen: { field: 'cancel_reason', value: 'record_deleted' },
}),
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(
// Derived from the contract, not re-typed (#3786). `APPROVAL_STATUSES` is
// where the list and the reason for each entry live; `ApprovalStatus` is
// derived from it, so this column and the contract cannot disagree. The
// authored English label per entry lives beside it in
// `APPROVAL_STATUS_LABELS` (#8543) — mapped here, never re-typed, so the
// `en` bundle regenerates from the contract's own text.
APPROVAL_STATUSES.map((value) => ({ value, label: APPROVAL_STATUS_LABELS[value] })),
{
label: 'Status',
required: true,
defaultValue: 'pending',
description: 'Lifecycle state of the request',
group: 'State',
},
),
// [#13568] Why a `cancelled` request was cancelled — the machine-readable
// half of the maintainer's 2026-08-31 ruling ("状态转 cancelled + 机器可读
// 原因"). Derived from `APPROVAL_CANCEL_REASONS`, never re-typed, on the
// same #3786 rule the `status` column above follows.
//
// On the ROW rather than on the `sys_approval_action` audit entry, because
// the readers are the inbox and the tombstone presentation, which page the
// request table: making them join the append-only action log to learn why a
// row they already hold is cancelled buys nothing and would make the reason
// unavailable to a plain list view. The action row still records the event
// (`action: 'cancel'`); this column records the STATE.
//
// Null on every non-cancelled row, and on rows written before the column
// existed — "not recorded", never "cancelled for no reason".
cancel_reason: Field.select(
APPROVAL_CANCEL_REASONS.map((value) => ({ value, label: APPROVAL_CANCEL_REASON_LABELS[value] })),
{
label: 'Cancellation Reason',
required: false,
description: 'Why the platform voided this request (set only when the status is cancelled)',
group: 'State',
},
),
current_step: Field.text({
label: 'Current Step',
required: false,
maxLength: 100,
description: 'Machine name of the step awaiting approval',
group: 'State',
}),
// The Approval node's authored label (`FlowNodeSchema.label`, required),
// written with `current_step` when the request opens. The engine's fact at
// that moment: the console shows it as stored and never reads the flow to
// re-derive it. Same chain and same boot backfill as `process_label`.
current_step_label: Field.text({
label: 'Approval Step',
required: false,
maxLength: 255,
readonly: true,
description: 'Label of the step awaiting approval, as it stood when the request reached it',
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',
}),
// Whom a pending request waits on, for display: one label per slot of
// `pending_approvers`, in slate order, joined with ", ". The engine writes
// it on every write that sets the slate (open, a partial tally, reassign,
// SLA reassign) and clears it with the slate on every terminal write, so it
// never outlives the slate it describes. A slot that names a person (a user
// id, or an email an account carries) is labelled with that account's name
// by `resolveUserNames`, the resolver the approvals door serves
// `pending_approver_names` with; any other slot (a `position:` / `team:`
// literal, an address no account answers to) shows as its stored address.
//
// A snapshot, not a live read: a user renamed while the request is pending
// keeps the old name here until the slate is next written. Display only —
// no decision, filter or index reads it; `pending_approvers` stays the
// authority. Null on a non-pending row, and while a person slot's name
// could not be read (never a raw address in its place); the boot backfill
// (`display-label-backfill.ts`) fills pending rows written before this
// column, and retries a failed read.
pending_approver_labels: Field.textarea({
label: 'Waiting On',
required: false,
readonly: true,
description: 'Who the request is waiting on: the name of each pending approver, or the slot address when it names no person',
group: 'State',
}),
// The module docstring above used to justify this column with "used by
// notifications so they can render before the record is locked or
// changed". That consumer does not exist, and the claim was cited as the
// reason the column holds a FULL row before anyone checked it. Measured
// against every `this.notify(...)` call site in `approval-service.ts` —
// all 12 of them: each passes `{ title, message, actionUrl }` (two also
// `actions`), built from `object_name` / `record_id` and the caller's
// comment. None reads this column or the parsed `payload`. The real
// readers are the serve path (`rowFromRequest` -> `payload`, redacted per
// reader), the decide-time approver re-resolution and the org backfill,
// both under SYSTEM_CTX, and the free-text predicate.
//
// The `description` below is deliberately UNCHANGED: it is accurate, and
// it is extracted into the four generated i18n bundles as `help`. The
// false sentence lived only in the JSDoc above, which is not extracted —
// so this correction moves no translation leaf.
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. 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.',
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.',
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' }),
},
// [#22211 ruling A] The per-caller `viewer` block (#3310), declared as a read
// attachment: `ApprovalService.attachViewers` computes it from the CALLER's
// identity and sets it on every row `listRequests` / `getRequest` serve. It
// is not a field — no column, and never stored — so the rows the data engine
// itself returns (the generic data door, a record-change flow's `record`, a
// flow action's subject load) never carry it.
//
// Two readers hold this declaration to the truth:
// - the shared build validator judges the `visible` predicates below
// against it: `record.viewer` resolves, and `record.viewer.<leaf>` only
// to a leaf declared here (`sys-approval-request-attached-on-read.test.ts`);
// - the conformance test pins that the keys `attachViewers` emits, and the
// runtime type of each value, equal this block, for every caller shape it
// serves (`sys-approval-request-viewer.conformance.test.ts`). A leaf added
// to the service without this block, or here without the service, is red.
//
// [Maintainer ruling 2026-11-17, option B] `can_override_approve` is
// `can_override` minus an approval of the viewer's own request, which the
// override never grants: the Approve action reads it, the other override
// levers keep reading `can_override`.
attachedOnRead: {
viewer: {
can_act: 'boolean', can_override: 'boolean', can_override_approve: 'boolean', is_submitter: 'boolean',
},
},
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`. The four levers the
// #3424 override covers (approve/reject/reassign, and recall since #12716)
// additionally OR in `record.viewer.can_override`
// so a platform/tenant admin can rescue a request routed to an
// unstaffed position — otherwise undecidable, locking the record forever — by
// approving, rejecting, reassigning it to a real approver, or recalling it
// (the lever that releases the record without recording a decision nobody
// made). Approve's override arm reads `record.viewer.can_override_approve`
// instead: the same flag minus an approval of the viewer's own request, which
// the override never grants (maintainer ruling 2026-11-17, option B), so a
// submitter who is also an administrator is not offered an Approve the
// server refuses. `viewer` is
// attached by getRequest/listRequests; where it is absent the predicate fails
// closed. Its leaves are declared under `attachedOnRead` above, which is what
// the build validator judges these predicates against.
//
// Every predicate below is guarded for the SPARSE action face (#8990). This
// binding is a list row or a record read carrying only what the caller
// projected, and CEL aborts the whole expression at key resolution — so the
// unguarded `record.viewer.can_act` faulted (`No such key: viewer`) on any
// row without the block, and the button silently vanished, indistinguishable
// from "the gate said no". `materializeDeclaredFields`'s doc comment in
// `@objectstack/objectql` is the canonical statement of the guard rule; this
// file follows it and does not restate it.
//
// `viewer` is a NESTED block, which needs one measurement the canonical rule
// does not spell out. Measured against the `@objectstack/formula` CEL engine:
// `has(record.viewer) && record.viewer != null && record.viewer.can_act`
// still FAULTS on `{viewer: {}}` (`No such key: can_act`) and on
// `{viewer: {can_act: null}}` (`Logical operator requires bool operands`).
// Guarding the LEAF instead — `has(record.viewer) &&
// has(record.viewer.can_act) && record.viewer.can_act == true` — is total
// over every binding AND subsumes the parent `!= null` half, because `has()`
// on a path whose parent is null answers `false` rather than faulting. So the
// leaf `has()` plus the `== true` comparison is the MINIMAL safe form here,
// not a longer one: `== true` is load-bearing (a bare truthy read of a null
// leaf faults the logical operator), the parent `!= null` is not.
//
// [#32442, ruling A] The four approver decisions — approve, reject, reassign,
// send back — are exposed to AI (`ai.exposed`, ADR-0011), so an agent can
// decide for the approver it acts for over MCP `run_action`. Nothing here
// decides WHO may: each is a same-origin `type: 'api'` action, so the action
// door forwards the call to its approvals route under the caller's own
// identity, and `ApprovalService` admits only a current approver of the
// request (and, for approve/reject/reassign, the override holder) — the
// gate the console's buttons reach.
// `visible` is not that gate and the door does not read it. Each declares
// `requiresConfirmation: true`, ADR-0011's bucket C for a consequential,
// bounded act (`sys_user.ban_user` is the precedent), so `run_action`
// refuses until the call carries the confirmation.
//
// [#32993] The submitter's side of the same process: recall and resubmit
// are exposed the same way, so the submitter's agent can withdraw a request
// to fix the record and send a returned one back into review. Same door,
// same gate: `ApprovalService.recall` admits the submitter (and, on a
// pending request, the override holder) and refuses anyone else with
// `approval_recall_not_submitter`; `ApprovalService.resubmit` admits the
// submitter alone. Remind, request-info and the thread reply stay unexposed.
actions: [
{
name: 'approval_approve',
label: 'Approve',
// The param dialog's subtitle, phrased as the decision question the way
// `approval_reject` below is (top-level `description`, never
// `ai.description`). Whether one approval completes the step depends on
// the step's behavior (first response, unanimous, quorum, per group),
// hence "once this step has the approvals it requires".
description:
'Approve this request? Your approval is recorded, and the request moves on once this step has the approvals it requires.',
icon: 'check-circle',
// Primary decision — the console renders this filled/highlighted so it
// stands out from the secondary levers in the drawer's action bar,
// matching the mobile card hierarchy (objectui#2762 P1-5).
variant: 'primary',
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 },
],
// The override arm reads `can_override_approve`, not `can_override`: the
// override never approves a request its actor submitted (maintainer
// ruling 2026-11-17, option B), and the flag is `can_override` minus
// exactly that. The slot holder's arm is unchanged.
visible:
'has(record.viewer) && has(record.viewer.can_act) && record.viewer.can_act == true' +
' || has(record.viewer) && has(record.viewer.can_override_approve) && record.viewer.can_override_approve == true',
locations: ['record_section', 'list_item'],
// Names what was approved, in the inbox's inline Approve wording. The
// decide route answers `ApprovalDecisionResult`, whose `request` is the
// read-back row with its display enrichment, so `record_title` is the
// same title the inbox row shows (the target record's display field,
// else its payload snapshot). `{{ result.* }}` is the success copy's
// declared scope on a `type: 'api'` action: the route's own response.
// Every action below names the request the same way: each of their
// routes answers `{ request, … }` with that same read-back row.
successMessage: 'Approved "{{ result.request.record_title }}"',
refreshAfter: true,
// [#32442, ruling A] Exposed to AI for the request's current approvers.
// See the note above the actions array.
ai: {
exposed: true,
description:
'Approve a pending approval request (the record: a sys_approval_request id) on behalf of the user, with an optional comment. Only a current approver of the request, or an administrator who may override a stuck request they did not submit, may approve it; anyone else is refused and the request stays pending. Ask the human to confirm before calling.',
requiresConfirmation: true,
},
},
{
name: 'approval_reject',
label: 'Reject',
// The confirm question lives HERE, not in `confirmText`: this action
// collects params, so the console would otherwise chain a confirm dialog
// and then the param dialog for one decision — and the first one already
// reads as "the action ran" (#7278, maintainer ruling 2026-08-10). The
// param dialog renders this as its description, and nothing is POSTed
// until its own Confirm: one condition, one wording, one dialog.
// NB: the top-level action `description` (#7367), never `ai.description`
// — that one is the LLM-facing tool contract and is not shown to anyone.
description: 'Reject this request? A rejection is final for every approver.',
icon: 'x-circle',
// Destructive decision — rendered in the console's danger styling so it
// reads as the irreversible action it is (objectui#2762 P1-5).
variant: 'danger',
type: 'api',
method: 'POST',
target: '/api/v1/approvals/requests/{id}/reject',
// A reject through `approval_reject` always carries its reason
// (maintainer requirement on the record page's Reject). `required: true`
// is enforced by the declared param contract (ADR-0104 D2,
// `validateActionParams`), which counts a blank or whitespace-only
// string as missing: the action door, MCP `run_action` and the console's
// param dialog all refuse a reject without one, before the target route
// is called. The target route judges it again: `ApprovalService.decide()`
// refuses a reject without a non-blank string reason, so a caller that
// skips this action is held to the same rule.
params: [
{ name: 'comment', label: 'Comment', type: 'textarea', required: true },
{ name: 'attachments', label: 'Attachments', type: 'file', multiple: true, required: false },
],
visible:
'has(record.viewer) && has(record.viewer.can_act) && record.viewer.can_act == true' +
' || has(record.viewer) && has(record.viewer.can_override) && record.viewer.can_override == true',
locations: ['record_section', 'list_item'],
successMessage: 'Rejected "{{ result.request.record_title }}"',
refreshAfter: true,
ai: {
exposed: true,
description:
'Reject a pending approval request (the record: a sys_approval_request id) on behalf of the user. The param comment, the reason for the rejection, is required: a call without one, or with a blank one, is refused. A rejection is final for every approver. Only a current approver of the request, or an administrator who may override a stuck request, may decide it; anyone else is refused. Ask the human to confirm before calling.',
requiresConfirmation: 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:
'has(record.viewer) && has(record.viewer.can_act) && record.viewer.can_act == true' +
' || has(record.viewer) && has(record.viewer.can_override) && record.viewer.can_override == true',
locations: ['record_section'],
successMessage: 'Reassigned "{{ result.request.record_title }}"',
refreshAfter: true,
ai: {
exposed: true,
description:
'Hand the user\'s pending step on an approval request (the record: a sys_approval_request id) to another person (param: to, that person\'s user id), with an optional comment. Only a current approver of the request, or an administrator who may override a stuck request, may reassign it. Ask the human to confirm before calling.',
requiresConfirmation: true,
paramHints: {
to: { description: 'The user id of the person who takes over this approval step.' },
},
},
},
// ── 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: 'has(record.viewer) && has(record.viewer.can_act) && record.viewer.can_act == true',
locations: ['record_section'],
successMessage: 'Sent "{{ result.request.record_title }}" back for revision',
refreshAfter: true,
ai: {
exposed: true,
description:
'Send a pending approval request (the record: a sys_approval_request id) back to its submitter for revision, with an optional reason. Only a current approver of the request may send it back. Ask the human to confirm before calling.',
requiresConfirmation: 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: 'has(record.viewer) && has(record.viewer.can_act) && record.viewer.can_act == true',
locations: ['record_section'],
successMessage: 'Information requested on "{{ result.request.record_title }}"',
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 plain non-submitter from ever seeing a button they
// cannot use.
//
// `recall` is the one exception, and it is not a widening: it ALSO ORs in
// the #3424 admin override (#12716), because an override admin is a caller
// `ApprovalService.recall` already authorises. Remind and resubmit keep no
// override arm.
{
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: 'has(record.status) && record.status == "pending" && has(record.viewer) && has(record.viewer.is_submitter) && record.viewer.is_submitter == true',
locations: ['record_section'],
successMessage: 'Reminder sent for "{{ result.request.record_title }}"',
refreshAfter: true,
},
{
name: 'approval_recall',
label: 'Recall',
// Confirm question as the param dialog's description, not `confirmText`
// — same one-decision-one-dialog rule as `approval_reject` above (#7278).
description: 'Recall this request? Approvers can no longer act on it and the record is unlocked.',
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).
//
// The second arm is the #3424 admin override, spelled byte-identically to
// reject's and reassign's above (#12716); approve's reads
// `can_override_approve` instead. `ApprovalService.recall`
// has admitted the override caller since #3424 — `isOverrideActor`'s own
// doc block names recall as one of the four levers — so until this arm
// landed, recall was the one authorised capability with no button: an
// admin could approve or reject their way out of a stuck request (writing
// a decision that did not happen) or reassign it, but could not withdraw.
//
// The override arm carries no status test of its own, on purpose, because
// it does not need one and the siblings do not have one either: the flag
// is already status-scoped where it is COMPUTED. `attachViewers` in
// `approval-service.ts` sets
// `can_override: row.status === 'pending' && isOverrideActor(...)` —
// ANDed — so `record.viewer.can_override` can never be true off `pending`,
// and this arm is pending-only in effect however CEL groups the
// expression. Pinned in both directions in
// `action-predicate-sparse-face.test.ts`, with the flag's own scoping
// pinned against the real service in `approval-revise.test.ts`.
visible:
'has(record.status) && (record.status == "pending" || record.status == "returned")' +
' && has(record.viewer) && has(record.viewer.is_submitter) && record.viewer.is_submitter == true' +
' || has(record.viewer) && has(record.viewer.can_override) && record.viewer.can_override == true',
locations: ['record_section'],
successMessage: 'Recalled "{{ result.request.record_title }}"',
refreshAfter: true,
// [#32993] Exposed to AI for the request's submitter. See the note above
// the actions array. The tool description is its own text, never the
// dialog question in `description`.
ai: {
exposed: true,
description:
'Withdraw an approval request (the record: a sys_approval_request id) that the user submitted, with an optional comment, while it is pending or was sent back for revision. Approvers can no longer act on it and the record is unlocked for editing; a recalled request is closed, so sending the record for approval again goes through the app\'s own submit action. Only the submitter of the request, or an administrator who may override a stuck pending request, may recall it; anyone else is refused. Ask the human to confirm before calling.',
requiresConfirmation: 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: 'has(record.status) && record.status == "returned" && has(record.viewer) && has(record.viewer.is_submitter) && record.viewer.is_submitter == true',
locations: ['record_section'],
successMessage: 'Resubmitted "{{ result.request.record_title }}"',
refreshAfter: true,
// [#32993] Exposed to AI for the request's submitter. See the note above
// the actions array.
ai: {
exposed: true,
description:
'Send an approval request (the record: a sys_approval_request id) that an approver sent back for revision (status returned) into review again, after the user revised the record, with an optional note on what changed. It applies only to a returned request. Only the submitter of the request may resubmit it; anyone else is refused. Ask the human to confirm before calling.',
requiresConfirmation: true,
},
},
// ── Thread reply ────────────────────────────────────────────────
// A free-form reply on the request's thread, from either side of it. It
// moves nothing: `ApprovalService.comment` stores one `sys_approval_action`
// row with action `comment` (the comment, and any attachments) and
// notifies the other side, and the request page's Timeline lists that row.
//
// `visible` is the route's own admission, spelled over the viewer block.
// `ApprovalService.comment` loads the request with `loadPendingRow` (it
// refuses any status but `pending`) and admits the submitter, or a caller
// who takes one of the pending slots (`takenSlot` → `heldSlot`):
//
// - the first arm is `can_act`, which `attachViewers` computes as
// `status === 'pending'` AND `heldSlot(...)` for the default actor — the
// slot test itself, so it is already pending-scoped;
// - the second arm is `is_submitter`, which `attachViewers` computes with
// NO status test, so this predicate adds the `pending` test the route's
// `loadPendingRow` applies.
//
// There is deliberately no `can_override` arm: the route has none. An
// override admin who holds no slot and did not submit is refused with
// FORBIDDEN, and a button for them would be a lever that fails on use.
// The two admissions the predicate does not reach are both NARROWER, never
// wider: a system context (the route lets it through; its viewer block is
// all-false) and a caller naming another identity in `actorId` (this
// action posts no actor, so the route acts as the caller).
{
name: 'approval_comment',
label: 'Reply',
icon: 'message-square',
type: 'api',
method: 'POST',
target: '/api/v1/approvals/requests/{id}/comment',
params: [
{ name: 'comment', label: 'Comment', type: 'textarea', required: true },
// The same decision-attachment param approve/reject declare: the
// console uploads through the shared widget and POSTs `attachments:
// string[]`, which the comment route persists on the action row.
{ name: 'attachments', label: 'Attachments', type: 'file', multiple: true, required: false },
],
visible:
'has(record.viewer) && has(record.viewer.can_act) && record.viewer.can_act == true' +
' || has(record.status) && record.status == "pending"' +
' && has(record.viewer) && has(record.viewer.is_submitter) && record.viewer.is_submitter == true',
locations: ['record_section'],
successMessage: 'Reply posted on "{{ result.request.record_title }}"',
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, and serve each caller only the requests
// the approvals door would (#22559, `request-read-gate.ts`).
apiMethods: ['get', 'list'],
// [#32442, ruling A] An approver's agent reads the requests waiting on
// them with the MCP record tools (list, describe, query, get one,
// aggregate), as the console's My Pending list does. Read only: every gate
// above still decides the rows and their values (the caller's permissions,
// `request-read-gate.ts`, the payload redaction), and no MCP write tool
// opens this object; a decision goes through the decide actions, which
// declare their own `ai.exposed`. `sys_approval_action` declares nothing:
// an approver lists and decides without reading the decision trail.
aiReadable: true,
},
});