diff --git a/.changeset/35719-approvals-reject-route-requires-reason.md b/.changeset/35719-approvals-reject-route-requires-reason.md new file mode 100644 index 00000000000..312a00335e9 --- /dev/null +++ b/.changeset/35719-approvals-reject-route-requires-reason.md @@ -0,0 +1,16 @@ +--- +'@objectstack/plugin-approvals': patch +--- + +fix(approvals): a reject through the approvals route or `IApprovalService.decide` requires a reason + +Clause-②: no (narrowing) +Metadata-protocol: none + + + +**BREAKING** for a caller of `POST /api/v1/approvals/requests/:id/reject`, or of `IApprovalService.decide()` with `decision: 'reject'`, that sends no `comment`, an empty or whitespace-only one, or one that is not a string: the call used to reject the request and is now refused before anything is read or written. It ships `patch` because it is a non-protocol breaking change (AGENTS.md Post-Task Checklist step 3): nothing a metadata author writes changes, so `Metadata-protocol` is `none`. + +The refusal is the one the `approval_reject` action door gives, judged by the same rules over the same `textarea` param: `400 VALIDATION_ERROR` with `Invalid action params: Action param "comment" is required` for an absent, `null`, empty or whitespace-only value, and `Invalid action params: Action param "comment" (textarea): …` for a value that is not a string (a number, a boolean, an array or an object). The request stays pending. A reject with a reason runs as before, and an approve keeps its comment optional. The platform's own rejects keep working: the SLA escalation's `auto_reject` and the revision-limit auto-reject do not pass through `decide()`, and the email action link records its fixed text. The email action link still records no reason the approver typed; that is a separate follow-up. + +Fix for a caller: send the reason as `comment` in the reject body (`{ "comment": "Over budget." }`). diff --git a/.changeset/35719-client-approvals-reject-requires-comment.md b/.changeset/35719-client-approvals-reject-requires-comment.md new file mode 100644 index 00000000000..75752bcd21f --- /dev/null +++ b/.changeset/35719-client-approvals-reject-requires-comment.md @@ -0,0 +1,14 @@ +--- +'@objectstack/client': patch +--- + +fix(client): `client.approvals.reject` requires the decision and its `comment` + +Clause-②: no (narrowing) +Metadata-protocol: none + + + +**BREAKING** for TypeScript callers of `client.approvals.reject(requestId)` or `client.approvals.reject(requestId, { actorId })`: the decision argument and its `comment` are now required, so those calls no longer compile. At runtime the approvals route refuses a reject without a non-blank reason with `400 VALIDATION_ERROR`. It ships `patch` because it is a non-protocol breaking change (AGENTS.md Post-Task Checklist step 3). `client.approvals.approve` is unchanged; its comment stays optional. + +Fix for a caller: pass the reason, `client.approvals.reject(requestId, { comment: 'Over budget.' })`. diff --git a/examples/app-showcase/test/expense-approval-write-back.test.ts b/examples/app-showcase/test/expense-approval-write-back.test.ts index a30c48fa19e..c9a08b2bb4b 100644 --- a/examples/app-showcase/test/expense-approval-write-back.test.ts +++ b/examples/app-showcase/test/expense-approval-write-back.test.ts @@ -132,7 +132,8 @@ async function statusOf(booted: Booted, id: string): Promise { } async function decide(booted: Booted, requestId: string, decision: 'approve' | 'reject', actorId: string) { - return booted.approvals.decide(requestId, { decision, actorId }, SYSTEM_CTX); + // A reject carries its reason: `decide()` refuses one without it. + return booted.approvals.decide(requestId, { decision, actorId, ...(decision === 'reject' ? { comment: 'Over budget.' } : {}) }, SYSTEM_CTX); } /** The pre-fix shape: the outcome arms go straight to bare `end` nodes. */ diff --git a/packages/client/src/client.test.ts b/packages/client/src/client.test.ts index af763700eb1..e7e7f02b721 100644 --- a/packages/client/src/client.test.ts +++ b/packages/client/src/client.test.ts @@ -768,6 +768,15 @@ describe('Approvals namespace (ADR-0019)', () => { const [url, opts] = fetchMock.mock.calls[0]; expect(url).toContain('/api/v1/approvals/requests/req-1/reject'); expect(opts.method).toBe('POST'); + expect(JSON.parse(opts.body).comment).toBe('Missing fields'); + // A reject carries its reason: the decision and its `comment` are required. + const typeOnly = () => { + // @ts-expect-error — no decision, so no reason + void client.approvals.reject('req-1'); + // @ts-expect-error — a decision without its reason + void client.approvals.reject('req-1', { actorId: 'user-1' }); + }; + void typeOnly; }); it('should list the action audit trail', async () => { diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index 8d67a2db7ea..7b49fb64fe0 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -7059,9 +7059,10 @@ export class ObjectStackClient { /** * Record a reject decision on a request. Resumes the owning flow run down - * the `reject` edge. + * the `reject` edge. A reject carries its reason: `comment` is required, + * and a blank one is refused with `400 VALIDATION_ERROR`. */ - reject: async (requestId: string, decision?: { actorId?: string; comment?: string; attachments?: string[] }): Promise => { + reject: async (requestId: string, decision: { actorId?: string; comment: string; attachments?: string[] }): Promise => { const route = this.getRoute('approvals'); const res = await this.fetch(`${this.baseUrl}${route}/requests/${encodeURIComponent(requestId)}/reject`, { method: 'POST', diff --git a/packages/plugins/plugin-approvals/src/approval-decision-outcome-notification.integration.test.ts b/packages/plugins/plugin-approvals/src/approval-decision-outcome-notification.integration.test.ts index 84937e5ddce..378b94f6985 100644 --- a/packages/plugins/plugin-approvals/src/approval-decision-outcome-notification.integration.test.ts +++ b/packages/plugins/plugin-approvals/src/approval-decision-outcome-notification.integration.test.ts @@ -310,7 +310,7 @@ describe('the decision that ends an approval tells its submitter (approval.appro it('a rejection at the first step ends the process, so it tells the submitter', async () => { const step1 = await submit('deal_ladder', 'vetoed', 5000); - await svc.decide(step1.id, { decision: 'reject', actorId: 'u_mgr' }, asUser('u_mgr')); + await svc.decide(step1.id, { decision: 'reject', comment: 'Over budget.', actorId: 'u_mgr' }, asUser('u_mgr')); expect(await pendingOn('D_vetoed')).toBeUndefined(); expect(outcomesAbout(step1.id).map((e) => [e.topic, e.audience])).toEqual([['approval.rejected', ['u_sub']]]); }); diff --git a/packages/plugins/plugin-approvals/src/approval-node.test.ts b/packages/plugins/plugin-approvals/src/approval-node.test.ts index 3ebacc81651..ca517d4e805 100644 --- a/packages/plugins/plugin-approvals/src/approval-node.test.ts +++ b/packages/plugins/plugin-approvals/src/approval-node.test.ts @@ -215,7 +215,7 @@ describe('Approval node bridge (ADR-0019)', () => { await automation.execute('deal_approval', { object: 'crm_deal', record: { id: 'd1' } }); const request = (await fake.find('sys_approval_request', { where: { status: 'pending' } }))[0]; - const out = await service.decide(request.id, { decision: 'reject', actorId: 'u1' }, SYSTEM_CTX); + const out = await service.decide(request.id, { decision: 'reject', comment: 'Over budget.', actorId: 'u1' }, SYSTEM_CTX); expect(out).toMatchObject({ finalized: true, decision: 'reject', resumed: true }); expect(marks).toEqual(['on_rejected']); diff --git a/packages/plugins/plugin-approvals/src/approval-service.test.ts b/packages/plugins/plugin-approvals/src/approval-service.test.ts index 5226d8efec7..d09dca8ac63 100644 --- a/packages/plugins/plugin-approvals/src/approval-service.test.ts +++ b/packages/plugins/plugin-approvals/src/approval-service.test.ts @@ -1415,11 +1415,50 @@ describe('ApprovalService (node era)', () => { it('decide: finalizes even when no automation is attached (resumed=false)', async () => { const req = await svc.openNodeRequest(openInput(['u9']), CTX); - const out = await svc.decide(req.id, { decision: 'reject', actorId: 'u9' }, SYS); + const out = await svc.decide(req.id, { decision: 'reject', actorId: 'u9', comment: 'Over budget.' }, SYS); expect(out.finalized).toBe(true); expect(out.resumed).toBe(false); }); + // ── a reject carries its reason ───────────────────────────────── + // + // The `approval_reject` action door's refusal, at the member every human + // door reaches: the same code, status and sentence, nothing read or written. + + it('decide: refuses a reject whose comment is missing, empty, blank, null or not a string, and leaves the request pending', async () => { + const resumed: any[] = []; + svc.attachAutomation({ async resume(runId) { resumed.push(runId); } }); + const req: any = await svc.openNodeRequest(openInput(['u9']), CTX); + for (const comment of [undefined, '', ' ', null]) { + const err: any = await svc.decide(req.id, { decision: 'reject', actorId: 'u9', comment } as any, SYS) + .then(() => undefined, (e) => e); + expect([err?.status, err?.code], String(comment)).toEqual([400, 'VALIDATION_ERROR']); + expect(err.message).toBe('Invalid action params: Action param "comment" is required'); + } + // Not a string is no reason either: the door's `textarea` value shape refuses it. + for (const [comment, received] of [[0, 'number'], [false, 'boolean'], [[], 'array'], [{}, 'object']] as const) { + const err: any = await svc.decide(req.id, { decision: 'reject', actorId: 'u9', comment } as any, SYS) + .then(() => undefined, (e) => e); + expect([err?.status, err?.code], JSON.stringify(comment)).toEqual([400, 'VALIDATION_ERROR']); + expect(err.message).toBe( + `Invalid action params: Action param "comment" (textarea): Invalid input: expected string, received ${received}`, + ); + } + const [row] = await engine.find('sys_approval_request', { where: { id: req.id } }); + expect(row.status).toBe('pending'); + expect((engine._tables['sys_approval_action'] ?? []).filter((a: any) => a.request_id === req.id && a.action === 'reject')).toEqual([]); + expect(resumed).toEqual([]); + }); + + // An approve keeps its comment optional: the resume test above approves with none. + it('decide: CONTROL — a reject with its reason is recorded with it', async () => { + const req: any = await svc.openNodeRequest(openInput(['u9']), CTX); + const out = await svc.decide(req.id, { decision: 'reject', actorId: 'u9', comment: 'Over budget.' }, SYS); + expect([out.finalized, out.request.status]).toEqual([true, 'rejected']); + expect((engine._tables['sys_approval_action'] ?? []).find((a: any) => a.request_id === req.id && a.action === 'reject')?.comment) + .toBe('Over budget.'); + }); + // ── #4420: a REPORTED resume failure is a failure ──────────────── // // The engine answers a lost run with `{ success: false }` rather than by @@ -1726,7 +1765,7 @@ describe('ApprovalService (node era)', () => { it('reject: names the record, the way the inbox row\'s inline Reject does', async () => { const id = await openRequestId(openInput(['u9']), CTX); - const out = await svc.decide(id, { decision: 'reject', actorId: 'u9' }, SYS); + const out = await svc.decide(id, { decision: 'reject', comment: 'Over budget.', actorId: 'u9' }, SYS); expect(out.request.status).toBe('rejected'); expect(named('approval_reject', out)).toBe('Rejected "Acme Renewal"'); }); @@ -2799,7 +2838,7 @@ describe('ApprovalService — admin override (#3424)', () => { it('a platform admin can reject a stuck request', async () => { const req = await svc.openNodeRequest(stuckInput(), CTX); - const out = await svc.decide(req.id, { decision: 'reject', actorId: 'root' }, PLATFORM_ADMIN); + const out = await svc.decide(req.id, { decision: 'reject', comment: 'Over budget.', actorId: 'root' }, PLATFORM_ADMIN); expect(out.finalized).toBe(true); expect(out.request.status).toBe('rejected'); }); @@ -6603,7 +6642,7 @@ describe('in-band transitions finalise before they resume (#3456 invariant)', () it('decide(reject) finalises before resuming', async () => { const req = await open(); - await svc.decide(req.id, { decision: 'reject', actorId: 'u9' }, SYS); + await svc.decide(req.id, { decision: 'reject', comment: 'Over budget.', actorId: 'u9' }, SYS); expectCleanHandoffs(); }); diff --git a/packages/plugins/plugin-approvals/src/approval-service.ts b/packages/plugins/plugin-approvals/src/approval-service.ts index 49197f7925d..4c675f1e351 100644 --- a/packages/plugins/plugin-approvals/src/approval-service.ts +++ b/packages/plugins/plugin-approvals/src/approval-service.ts @@ -68,6 +68,7 @@ import { canServeApiOperation, isFileIdToken, referenceTargetOf, SINGLE_OPTION_TYPES, MULTI_OPTION_TYPES, } from '@objectstack/spec/data'; import type { EnableLike, ObjectCapabilitiesParsed } from '@objectstack/spec/data'; +import { validateActionParams } from '@objectstack/spec/ui'; // [#11993] The SANCTIONED renderer for OPERATION-level refusal copy. The // Operation Message Catalog is the ONE seat for these sentences — its own // header bars both a package-local string table and a second rendering @@ -6481,12 +6482,31 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega * [#24753] A decision that ends the approval process tells the submitter its * outcome (`approval.approved` / `approval.rejected`, * {@link ApprovalService.notifyDecisionOutcome}). + * + * A reject carries its reason: a missing or blank `comment`, or one that is + * not a string, is refused before anything is read or written — + * `400 VALIDATION_ERROR` with the sentence the `approval_reject` action door + * answers, judged by the same rules (`validateActionParams` over the + * `textarea` param that action declares). Every human door reaches this + * member (the REST route, the SDK, the action door that forwards to the + * route, the action link with its fixed text). The SLA sweep's auto-reject + * calls `decideAndResume` and the revision-limit reject writes its own row, + * so neither passes through here. An approve keeps its comment optional. */ async decide( requestId: string, input: ApprovalDecisionInput, context: ExecutionContext, ): Promise { + if (input?.decision === 'reject') { + const issues = validateActionParams([{ name: 'comment', required: true, type: 'textarea' }], { comment: input.comment }); + if (issues.length > 0) { + throw Object.assign( + new Error(`Invalid action params: ${issues.map((i) => i.message).join('; ')}`), + { status: 400, code: 'VALIDATION_ERROR' }, + ); + } + } return this.decideAndResume(requestId, input, context, 'outcome'); } diff --git a/packages/plugins/plugin-approvals/src/approval-tenant-positions-name-authority.test.ts b/packages/plugins/plugin-approvals/src/approval-tenant-positions-name-authority.test.ts index 67d6fdc8949..386272f94a4 100644 --- a/packages/plugins/plugin-approvals/src/approval-tenant-positions-name-authority.test.ts +++ b/packages/plugins/plugin-approvals/src/approval-tenant-positions-name-authority.test.ts @@ -513,7 +513,7 @@ describe('[ADR-0131 D1] under a walled posture, a request with no organization i try { switch (door) { case 'approve': await svc.decide(id, { decision: 'approve', actorId } as any, ctx); break; - case 'reject': await svc.decide(id, { decision: 'reject', actorId } as any, ctx); break; + case 'reject': await svc.decide(id, { decision: 'reject', comment: 'Over budget.', actorId } as any, ctx); break; case 'recall': await svc.recall(id, { actorId } as any, ctx); break; case 'reassign': await svc.reassign(id, { actorId, to: 'usr_target' }, ctx); break; case 'sendBack': await svc.sendBack(id, { actorId, comment: 'please revise' } as any, ctx); break; diff --git a/packages/plugins/plugin-approvals/src/batch-item-recall-resumes-batch.test.ts b/packages/plugins/plugin-approvals/src/batch-item-recall-resumes-batch.test.ts index b28b12eacfb..1dc3796ad05 100644 --- a/packages/plugins/plugin-approvals/src/batch-item-recall-resumes-batch.test.ts +++ b/packages/plugins/plugin-approvals/src/batch-item-recall-resumes-batch.test.ts @@ -295,7 +295,7 @@ describe('a revise-window recall on a batch item resumes the batch (#28183)', () await service.sendBack(first.id, { actorId: 'u1' }, asUser('u1')); await service.resubmit(first.id, { actorId: 'submitter' }, asUser('submitter')); const round2 = await requestFor('t1', 'pending'); - await service.decide(round2.id, { decision: 'reject', actorId: 'u1' }, SYSTEM_CTX); + await service.decide(round2.id, { decision: 'reject', comment: 'Over budget.', actorId: 'u1' }, SYSTEM_CTX); const second = await requestFor('t2', 'pending'); await service.decide(second.id, { decision: 'approve', actorId: 'u1' }, SYSTEM_CTX); diff --git a/packages/plugins/plugin-approvals/src/decision-strand-envelope.test.ts b/packages/plugins/plugin-approvals/src/decision-strand-envelope.test.ts index 6d22839bae7..a6981d6afbf 100644 --- a/packages/plugins/plugin-approvals/src/decision-strand-envelope.test.ts +++ b/packages/plugins/plugin-approvals/src/decision-strand-envelope.test.ts @@ -254,7 +254,7 @@ describe('#13807 — a stranded decision publishes its facts, and keeps its stat const req = await park(automation); const out = await service.decide( - req.id, { decision: 'reject', actorId: 'u1' }, SYSTEM_CTX, + req.id, { decision: 'reject', comment: 'Over budget.', actorId: 'u1' }, SYSTEM_CTX, ); expect(out.finalized).toBe(true); @@ -289,7 +289,7 @@ describe('#13807 — a stranded decision publishes its facts, and keeps its stat }; const err = await service - .decide(req.id, { decision: 'reject', actorId: 'u1' }, SYSTEM_CTX) + .decide(req.id, { decision: 'reject', comment: 'Over budget.', actorId: 'u1' }, SYSTEM_CTX) .then(() => null, (e: Error) => e); expect(seen.length).toBe(1); @@ -348,7 +348,7 @@ describe('#13807 — a stranded decision publishes its facts, and keeps its stat const runId = req.flow_run_id; const err = await service - .decide(req.id, { decision: 'reject', actorId: 'u1' }, SYSTEM_CTX) + .decide(req.id, { decision: 'reject', comment: 'Over budget.', actorId: 'u1' }, SYSTEM_CTX) .then(() => null, (e: Error) => e); // The door still throws and the decision still stands — this card moves diff --git a/packages/plugins/plugin-approvals/src/exclude-submitter.integration.test.ts b/packages/plugins/plugin-approvals/src/exclude-submitter.integration.test.ts index 8ec30eb4a98..1d189e495a2 100644 --- a/packages/plugins/plugin-approvals/src/exclude-submitter.integration.test.ts +++ b/packages/plugins/plugin-approvals/src/exclude-submitter.integration.test.ts @@ -304,7 +304,7 @@ describe('[#25573] excludeSubmitter keeps the submitter from approving their own await expect(svc.decide(row.id, { decision: 'approve', actorId: 'u_sub' } as any, SUB)) .rejects.toThrow(/^FORBIDDEN: 'u_sub' submitted this request, and its approval step sets excludeSubmitter/); expect((await actionsOf(row.id)).map((a) => a.action)).toEqual(['submit']); - const out = await svc.decide(row.id, { decision: 'reject', actorId: 'u_sub' } as any, SUB); + const out = await svc.decide(row.id, { decision: 'reject', comment: 'Over budget.', actorId: 'u_sub' } as any, SUB); expect(out.request.status).toBe('rejected'); }); diff --git a/packages/plugins/plugin-approvals/src/platform-admin-approver-34218.test.ts b/packages/plugins/plugin-approvals/src/platform-admin-approver-34218.test.ts index 6340bbda9e4..e2a8d620648 100644 --- a/packages/plugins/plugin-approvals/src/platform-admin-approver-34218.test.ts +++ b/packages/plugins/plugin-approvals/src/platform-admin-approver-34218.test.ts @@ -305,7 +305,7 @@ describe('platform_admin approver: one slot the platform administrators decide u const row = await open('owner', 'host_review', PLATFORM); expect(await inbox(as('u_owner_cfg'))).toContain(row.id); // Naming the slot is admitted for the owner as well as the default actor. - const out = await svc.decide(row.id, { decision: 'reject', actorId: SLOT } as any, as('u_owner_cfg')); + const out = await svc.decide(row.id, { decision: 'reject', comment: 'Over budget.', actorId: SLOT } as any, as('u_owner_cfg')); expect(out.request.status).toBe('rejected'); const decision = (await actionsOf(row.id)).find((a) => a.action === 'reject'); expect(decision).toMatchObject({ actor_id: 'u_owner_cfg', acted_as: SLOT }); diff --git a/packages/plugins/plugin-approvals/src/record-reader-opt-in.integration.test.ts b/packages/plugins/plugin-approvals/src/record-reader-opt-in.integration.test.ts index e4964e4f172..0446aea19ca 100644 --- a/packages/plugins/plugin-approvals/src/record-reader-opt-in.integration.test.ts +++ b/packages/plugins/plugin-approvals/src/record-reader-opt-in.integration.test.ts @@ -297,7 +297,7 @@ describe('an object that declares enable.approvalsVisibleToReaders, with the hos // Accepted: `FORBIDDEN:` is the code this service's refusals carry, the // prefix the REST layer parses into a 403. await expect(rig.svc.decide(requestA, { decision: 'approve', actorId: READER }, ctx)).rejects.toThrow(/^FORBIDDEN:/); - await expect(rig.svc.decide(requestA, { decision: 'reject', actorId: READER }, ctx)).rejects.toThrow(/^FORBIDDEN:/); + await expect(rig.svc.decide(requestA, { decision: 'reject', comment: 'Over budget.', actorId: READER }, ctx)).rejects.toThrow(/^FORBIDDEN:/); await expect(rig.svc.reassign(requestA, { actorId: READER, to: READER }, ctx)).rejects.toThrow(/^FORBIDDEN:/); await expect(rig.svc.comment(requestA, { actorId: READER, comment: 'hi' }, ctx)).rejects.toThrow(/^FORBIDDEN:/); await expect(rig.svc.recall(requestA, { actorId: READER }, ctx)).rejects.toThrow(/^FORBIDDEN:/); diff --git a/packages/plugins/plugin-approvals/src/record-reader-visibility.test.ts b/packages/plugins/plugin-approvals/src/record-reader-visibility.test.ts index 7d8df158adb..34e7e8bbd58 100644 --- a/packages/plugins/plugin-approvals/src/record-reader-visibility.test.ts +++ b/packages/plugins/plugin-approvals/src/record-reader-visibility.test.ts @@ -364,7 +364,7 @@ describe('record-reader approval visibility (#8652)', () => { // request is not a licence to decide it. await expect(svc.decide(REQUEST, { decision: 'approve', actorId: LEDGER_ROLE }, ctx)) .rejects.toThrow(/^FORBIDDEN/); - await expect(svc.decide(REQUEST, { decision: 'reject', actorId: LEDGER_ROLE }, ctx)) + await expect(svc.decide(REQUEST, { decision: 'reject', comment: 'Over budget.', actorId: LEDGER_ROLE }, ctx)) .rejects.toThrow(/^FORBIDDEN/); await expect(svc.reassign(REQUEST, { actorId: LEDGER_ROLE, to: LEDGER_ROLE }, ctx)) .rejects.toThrow(/^FORBIDDEN/); diff --git a/packages/plugins/plugin-approvals/src/restored-approval-continuation.test.ts b/packages/plugins/plugin-approvals/src/restored-approval-continuation.test.ts index 71deabd583e..948036ecdd8 100644 --- a/packages/plugins/plugin-approvals/src/restored-approval-continuation.test.ts +++ b/packages/plugins/plugin-approvals/src/restored-approval-continuation.test.ts @@ -281,7 +281,7 @@ describe('#15389 — a restored approval suspension has an issuer again', () => // ── The approvals doors: all guard on `pending`, and the row is terminal. const decideAgain = await service - .decide(req.id, { decision: 'reject', actorId: 'u1' }, SYSTEM_CTX) + .decide(req.id, { decision: 'reject', comment: 'Over budget.', actorId: 'u1' }, SYSTEM_CTX) .then(() => null, (e: Error) => e); expect(decideAgain?.message).toBe('INVALID_STATE: request is rejected'); @@ -674,7 +674,7 @@ describe('#15389 — a restored approval suspension has an issuer again', () => // (a) A healthy decision. The run completed; there is nothing to continue, // and this must NOT re-run the branch a second time. const healthy = await park(automation); - await service.decide(healthy.id, { decision: 'reject', actorId: 'u1' }, SYSTEM_CTX); + await service.decide(healthy.id, { decision: 'reject', comment: 'Over budget.', actorId: 'u1' }, SYSTEM_CTX); expect(marks).toEqual(['mark_rejected']); const noPause = await service.continueRestoredRun(healthy.id).then(() => null, (e: Error) => e); expect(noPause?.message).toMatch(/is not suspended/); @@ -685,7 +685,7 @@ describe('#15389 — a restored approval suspension has an issuer again', () => // refusal has to name the step they missed rather than fail obscurely. rejectBranchThrows = DOWNSTREAM_FAILURE; const stranded = await park(automation); - await service.decide(stranded.id, { decision: 'reject', actorId: 'u1' }, SYSTEM_CTX) + await service.decide(stranded.id, { decision: 'reject', comment: 'Over budget.', actorId: 'u1' }, SYSTEM_CTX) .then(() => null, () => null); const notRestored = await service.continueRestoredRun(stranded.id) .then(() => null, (e: Error) => e); @@ -881,7 +881,7 @@ describe('#15389 — a restored approval suspension has an issuer again', () => const second = boot(); rejectBranchThrows = DOWNSTREAM_FAILURE; const amb = await park(second); - await service.decide(amb.id, { decision: 'reject', actorId: 'u1' }, SYSTEM_CTX) + await service.decide(amb.id, { decision: 'reject', comment: 'Over budget.', actorId: 'u1' }, SYSTEM_CTX) .then(() => null, () => null); await second.restoreConsumedSuspension(amb.flow_run_id); const ambRow = await rowOf(amb.id); diff --git a/packages/plugins/plugin-approvals/src/status-mirror-envelope.integration.test.ts b/packages/plugins/plugin-approvals/src/status-mirror-envelope.integration.test.ts index 7783e3046e4..eb4ced5dff3 100644 --- a/packages/plugins/plugin-approvals/src/status-mirror-envelope.integration.test.ts +++ b/packages/plugins/plugin-approvals/src/status-mirror-envelope.integration.test.ts @@ -313,7 +313,7 @@ describe("the status mirror hands a runAs:'user' cascade the person's own reques await seedDeal('d_reject'); const requestId = await openNode('d_reject', 'submitter', ['approver']); const before = mark(); - await svc.decide(requestId, { decision: 'reject', actorId: 'approver' } as any, asPerson('approver')); + await svc.decide(requestId, { decision: 'reject', comment: 'Over budget.', actorId: 'approver' } as any, asPerson('approver')); const { hook } = await expectPersonInOrg(await cascade(before), 'approver', ORG_A); expect(hook.permissions).toContain(EXTRA_SET); }); diff --git a/packages/plugins/plugin-approvals/src/stranded-run-repairability.test.ts b/packages/plugins/plugin-approvals/src/stranded-run-repairability.test.ts index f1ac2033bbf..e15a21cbdf4 100644 --- a/packages/plugins/plugin-approvals/src/stranded-run-repairability.test.ts +++ b/packages/plugins/plugin-approvals/src/stranded-run-repairability.test.ts @@ -421,7 +421,7 @@ describe('#15358 · #15222 — a cascade-failed ancestor, reported and now repai const decided = await pendingRequest(); const decidedRunId = decided.flow_run_id as string; const err = await service - .decide(decided.id, { decision: 'reject', actorId: 'u1' }, SYSTEM_CTX) + .decide(decided.id, { decision: 'reject', comment: 'Over budget.', actorId: 'u1' }, SYSTEM_CTX) .then(() => null, (e: Error) => e); expect(strandedDecisionDetails(err)).toEqual({ finalized: true, decision: 'reject', runId: decidedRunId, repairable: true, diff --git a/packages/qa/dogfood/test/approval-override-composite-pin.dogfood.test.ts b/packages/qa/dogfood/test/approval-override-composite-pin.dogfood.test.ts index f6f670f8a5d..053bbbaf57b 100644 --- a/packages/qa/dogfood/test/approval-override-composite-pin.dogfood.test.ts +++ b/packages/qa/dogfood/test/approval-override-composite-pin.dogfood.test.ts @@ -356,7 +356,7 @@ describe('the override never approves its actor\'s own request, through the appr it('leaves the submitter-administrator their reject and their recall', async () => { const rejected = await openRequest(adminToken, 'own reject'); - const reject = await call(adminToken, 'POST', `/approvals/requests/${rejected}/reject`, {}); + const reject = await call(adminToken, 'POST', `/approvals/requests/${rejected}/reject`, { comment: 'Filed in error.' }); expect(reject.status).toBe(200); expect((await requestRow(rejected)).status).toBe('rejected'); expect(await decisionsOn(rejected)).toMatchObject([{ action: 'reject', via_override: true }]); @@ -367,6 +367,34 @@ describe('the override never approves its actor\'s own request, through the appr expect((await requestRow(recalled)).status).toBe('recalled'); }, 60_000); + // [#35719] A reject carries its reason on the approvals route too, with the + // answer the `approval_reject` action door gives: 400 VALIDATION_ERROR naming + // `comment`, before anything is read or written. + it('refuses a reject with no reason, a blank one or one that is not a string, and leaves the request pending', async () => { + const id = await openRequest(memberToken, 'reasonless reject'); + for (const body of [{}, { comment: '' }, { comment: ' ' }, { comment: null }]) { + const reject = await call(adminToken, 'POST', `/approvals/requests/${id}/reject`, body); + expect([reject.status, reject.code], JSON.stringify(body)).toEqual([400, 'VALIDATION_ERROR']); + expect(JSON.stringify(reject.body)).toContain('Action param \\"comment\\" is required'); + } + // A comment that is not a string is no reason either (the door's `textarea` shape). + for (const body of [{ comment: 0 }, { comment: false }, { comment: [] }, { comment: {} }]) { + const reject = await call(adminToken, 'POST', `/approvals/requests/${id}/reject`, body); + expect([reject.status, reject.code], JSON.stringify(body)).toEqual([400, 'VALIDATION_ERROR']); + expect(JSON.stringify(reject.body)).toContain('Action param \\"comment\\" (textarea): '); + } + expect((await requestRow(id)).status).toBe('pending'); + expect(await decisionsOn(id)).toEqual([]); + }, 60_000); + + it('CONTROL: a reject with its reason is recorded with that reason', async () => { + const id = await openRequest(memberToken, 'reasoned reject'); + const reject = await call(adminToken, 'POST', `/approvals/requests/${id}/reject`, { comment: 'Over budget.' }); + expect(reject.status).toBe(200); + expect((await requestRow(id)).status).toBe('rejected'); + expect(await decisionsOn(id)).toMatchObject([{ action: 'reject', comment: 'Over budget.' }]); + }, 60_000); + it('CONTROL: an administrator who did not submit the request override-approves it, audited, and the slate\'s approver then reads 404', async () => { const id = await openRequest(memberToken, 'member approve'); const approve = await call(adminToken, 'POST', `/approvals/requests/${id}/approve`, {}); diff --git a/packages/qa/dogfood/test/approval-pending-approver-record-read.dogfood.test.ts b/packages/qa/dogfood/test/approval-pending-approver-record-read.dogfood.test.ts index cdd3ea9c6d7..f9cdabec527 100644 --- a/packages/qa/dogfood/test/approval-pending-approver-record-read.dogfood.test.ts +++ b/packages/qa/dogfood/test/approval-pending-approver-record-read.dogfood.test.ts @@ -161,7 +161,8 @@ describe('the approver a pending step waits on reads its record (#26180)', () => return (body.records ?? body.data ?? []).map((r) => String(r.id)).sort(); }; const decide = async (token: string, requestId: string, verb: 'approve' | 'reject') => { - const res = await stack.apiAs(token, 'POST', `/approvals/requests/${requestId}/${verb}`, {}); + // A reject carries its reason (the approvals route refuses one without it). + const res = await stack.apiAs(token, 'POST', `/approvals/requests/${requestId}/${verb}`, verb === 'reject' ? { comment: 'Over budget.' } : {}); expect(res.status, `${verb} ${requestId}: ${await res.clone().text()}`).toBe(200); }; diff --git a/ui/.changeset/35719-inbox-reject-requires-reason.md b/ui/.changeset/35719-inbox-reject-requires-reason.md new file mode 100644 index 00000000000..4cf3ceb5031 --- /dev/null +++ b/ui/.changeset/35719-inbox-reject-requires-reason.md @@ -0,0 +1,11 @@ +--- +"@object-ui/console": patch +"@object-ui/i18n": patch +--- + +Clause-②: no (narrowing) +Metadata-protocol: none + +fix(console): rejecting from the approvals inbox requires a reason (objectstack#35719) + +The approvals inbox's row Reject confirmation, its bulk Reject confirmation and the `r` key (which opens the row confirmation) keep Reject disabled until the reason box holds a non-blank reason; the box is no longer labelled optional, in all eleven locale packs (`approvalsInbox.comment`). The approvals route now refuses a reject without a reason, so before this an empty box answered an error per request. Approve is unchanged and takes no reason. diff --git a/ui/apps/console/src/pages/system/ApprovalsInboxPage.phoneWidth-29070.test.tsx b/ui/apps/console/src/pages/system/ApprovalsInboxPage.phoneWidth-29070.test.tsx index 38b380f13d6..f599ba1aacf 100644 --- a/ui/apps/console/src/pages/system/ApprovalsInboxPage.phoneWidth-29070.test.tsx +++ b/ui/apps/console/src/pages/system/ApprovalsInboxPage.phoneWidth-29070.test.tsx @@ -200,7 +200,7 @@ describe('the inline confirmation does not re-render the rows (objectstack#29070 fireEvent.click(within(card).getByRole('button', { name: 'Reject' })); const dialog = await screen.findByRole('alertdialog'); - const box = within(dialog).getByRole('textbox', { name: 'Comment (optional)' }); + const box = within(dialog).getByRole('textbox', { name: 'Comment' }); for (const value of ['O', 'Ov', 'Ove', 'Over the cap']) fireEvent.change(box, { target: { value } }); expect(box).toHaveValue('Over the cap'); expect(rowReads.count, 'opening the confirmation or typing the reason re-rendered the rows').toBe(before); diff --git a/ui/apps/console/src/pages/system/ApprovalsInboxPage.rejectReasonSelfSubmitted-27520.test.tsx b/ui/apps/console/src/pages/system/ApprovalsInboxPage.rejectReasonSelfSubmitted-27520.test.tsx index f176c704884..68588abed69 100644 --- a/ui/apps/console/src/pages/system/ApprovalsInboxPage.rejectReasonSelfSubmitted-27520.test.tsx +++ b/ui/apps/console/src/pages/system/ApprovalsInboxPage.rejectReasonSelfSubmitted-27520.test.tsx @@ -3,11 +3,11 @@ /** * objectstack#27520 row 12 — deciding from the queue. * - * - **Reject takes an optional reason.** The row's Reject confirmation, and the - * bulk one, offer a comment box; what the approver types reaches the reject - * call as `comment`, the field the approvals REST door already accepts and - * records on the request's timeline. Left empty, the call carries no - * `comment` at all, as before. + * - **Reject takes a reason.** The row's Reject confirmation, and the bulk one, + * offer a comment box; what the approver types reaches the reject call as + * `comment`, the field the approvals REST door requires and records on the + * request's timeline. While the box is empty or blank, Reject stays disabled + * and no call is made (objectstack#35719). * - **A request the viewer submitted says so.** The row reads the server's own * `viewer.is_submitter` (attached by the approvals list read) and marks the * requester "You submitted this". Who may decide is unchanged: the marker @@ -142,12 +142,12 @@ beforeEach(() => { }); afterEach(cleanup); -describe('Reject from the queue takes an optional reason (objectstack#27520 row 12)', () => { +describe('Reject from the queue takes a reason (objectstack#27520 row 12, objectstack#35719)', () => { it('the row confirmation sends what the approver typed as the comment', async () => { renderInbox(); fireEvent.click(within(await rowFor('Someone Else Invoice')).getByRole('button', { name: 'Reject' })); const dialog = await screen.findByRole('alertdialog'); - fireEvent.change(within(dialog).getByRole('textbox', { name: 'Comment (optional)' }), { + fireEvent.change(within(dialog).getByRole('textbox', { name: 'Comment' }), { target: { value: ' Missing the signed PO. ' }, }); fireEvent.click(within(dialog).getByRole('button', { name: 'Reject' })); @@ -155,21 +155,28 @@ describe('Reject from the queue takes an optional reason (objectstack#27520 row expect(approvalsApiStub.reject).toHaveBeenCalledWith('req_other', { actor_id: 'u_1', comment: 'Missing the signed PO.' }); }); - it('left empty, the reject carries no comment, and a reopened dialog starts empty', async () => { + it('Reject stays disabled while the reason is empty or blank, and a reopened dialog starts empty', async () => { renderInbox(); const row = await rowFor('Someone Else Invoice'); fireEvent.click(within(row).getByRole('button', { name: 'Reject' })); let dialog = await screen.findByRole('alertdialog'); - fireEvent.change(within(dialog).getByRole('textbox', { name: 'Comment (optional)' }), { target: { value: 'draft' } }); + const confirm = within(dialog).getByRole('button', { name: 'Reject' }); + expect(confirm).toBeDisabled(); + fireEvent.change(within(dialog).getByRole('textbox', { name: 'Comment' }), { target: { value: ' ' } }); + expect(confirm).toBeDisabled(); + fireEvent.click(confirm); + fireEvent.change(within(dialog).getByRole('textbox', { name: 'Comment' }), { target: { value: 'draft' } }); + expect(confirm).toBeEnabled(); fireEvent.click(within(dialog).getByRole('button', { name: 'Cancel' })); await waitFor(() => expect(screen.queryByRole('alertdialog')).toBeNull()); - fireEvent.click(within(await rowFor('Someone Else Invoice')).getByRole('button', { name: 'Reject' })); + // The r key opens the same confirmation, empty again. + fireEvent.keyDown(window, { key: 'j' }); + fireEvent.keyDown(window, { key: 'r' }); dialog = await screen.findByRole('alertdialog'); - expect(within(dialog).getByRole('textbox', { name: 'Comment (optional)' })).toHaveValue(''); - fireEvent.click(within(dialog).getByRole('button', { name: 'Reject' })); - await waitFor(() => expect(approvalsApiStub.reject).toHaveBeenCalledTimes(1)); - expect(approvalsApiStub.reject).toHaveBeenCalledWith('req_other', { actor_id: 'u_1' }); + expect(within(dialog).getByRole('textbox', { name: 'Comment' })).toHaveValue(''); + expect(within(dialog).getByRole('button', { name: 'Reject' })).toBeDisabled(); + expect(approvalsApiStub.reject).not.toHaveBeenCalled(); }); it('the bulk confirmation sends the same reason on every selected request', async () => { @@ -179,7 +186,10 @@ describe('Reject from the queue takes an optional reason (objectstack#27520 row } fireEvent.click(screen.getByRole('button', { name: 'Reject {{count}}' })); const dialog = await screen.findByRole('alertdialog'); - fireEvent.change(within(dialog).getByRole('textbox', { name: 'Comment (optional)' }), { + expect(within(dialog).getByRole('button', { name: 'Reject {{count}}' })).toBeDisabled(); + fireEvent.change(within(dialog).getByRole('textbox', { name: 'Comment' }), { target: { value: ' ' } }); + expect(within(dialog).getByRole('button', { name: 'Reject {{count}}' })).toBeDisabled(); + fireEvent.change(within(dialog).getByRole('textbox', { name: 'Comment' }), { target: { value: 'Budget frozen this quarter.' }, }); fireEvent.click(within(dialog).getByRole('button', { name: 'Reject {{count}}' })); diff --git a/ui/apps/console/src/pages/system/ApprovalsInboxPage.tsx b/ui/apps/console/src/pages/system/ApprovalsInboxPage.tsx index 3af04169adb..52f03970d58 100644 --- a/ui/apps/console/src/pages/system/ApprovalsInboxPage.tsx +++ b/ui/apps/console/src/pages/system/ApprovalsInboxPage.tsx @@ -428,14 +428,16 @@ function RequestCell({ r, tr }: { r: ApprovalRequestRow; tr: Translate }) { /** * The `comment` member of a decision body: the trimmed reason, or nothing when - * the approver left it empty, so an unexplained decision sends what it always did. + * there is none. A reject always has one — its confirmation stays disabled + * until the reason is non-blank, and the approvals door refuses a reject + * without it; an approve may leave it out. */ function decisionComment(comment: string | undefined): { comment?: string } { const text = (comment ?? '').trim(); return text ? { comment: text } : {}; } -/** The optional reason box a Reject confirmation carries. */ +/** The reason box a Reject confirmation carries; the reject waits on it. */ function RejectCommentField({ id, label, value, onChange }: { id: string; label: string; @@ -445,7 +447,7 @@ function RejectCommentField({ id, label, value, onChange }: { return (
-