Skip to content

Commit e100a37

Browse files
fix(approvals): the approval e-mail link and the action page's inbox link open the Console under its mount (#36247)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1X8UqWLrzTYpuat8L5eLdf2c)_ Fixes #34862 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 审批人点开审批邮件里的「打开审批」链接,以前在默认部署上看到的是一个“找不到”的错误页,现在直接打开控制台里的这条审批请求;审批完成页上的「打开审批中心」链接也一样修好了。 - 属于审批与通知的整体工作:每位审批人收到的邮件唯一的链接是坏的,这次把它修好。 - 出错的话,审批人点邮件链接仍会落到错误页或错误路径,但不影响在控制台内直接审批;本改动可直接撤回。 - 无。 ## What changes The approval e-mail's link (`approvalUrl`, built in `notify()`) and the action-link result page's "Open the Approvals Inbox" link now carry the Console's mount. The mount is not written in plugin-approvals: it is read from the auth service's Console page composer, `getConsoleUrl` (`AuthManager.getConsolePageUrl`, which reads `AuthConfig.uiBasePath`, default `/_console`). That is the composer the auth e-mails and the mention e-mail (`plugin-audit`) already use, so the approval links now follow the same one setting. - `public-base-url.ts`: new `consolePageLink(publicBaseUrl, composer, pagePath)`. The origin is `publicBaseUrl` (#30509's no-guess origin rule is unchanged; the composer's own origin is dropped). Only the composer's PATH is taken, minus any base path the two share, so a sub-path deployment is not prefixed twice. No composer, a composer that throws, or one that answers no URL gives no mount: the e-mail link is then the one built before, and the inbox link is `BASE/system/approvals`. - `approvals-plugin.ts`: reads `ctx.getService('auth').getConsoleUrl` lazily at link time (the same reader `audit-plugin.ts` uses), and passes it to the service. The raw-app action-page mount builds the inbox href through the same function. - `approval-service.ts`: `ApprovalServiceOptions.getConsoleUrl` (optional, additive). `approvalUrl` = `consolePageLink(publicBaseUrl, getConsoleUrl, actionUrl)`. The action page's inbox link moves from the origin-relative `/system/approvals` to `BASE/_console/system/approvals` (relative `/_console/system/approvals` when no base resolves; `BASE/system/approvals` with no mount to read). `handleActionPage` and the plugin's raw-app door build it through the same function, so the two action-page doors still answer the same bytes. - `action-link-pages.ts`: `renderResultPage` takes an optional `inboxHref` (default: the bare route, as before). `APPROVALS_INBOX_PATH` names the route. - The in-app `actionUrl` (`/system/approvals?request=ID`) is unchanged: the Console routes on it. Files outside the claim's named surface, named before editing: `approvals-plugin.ts` (the wiring), `public-base-url.ts` and `public-base-url.test.ts` (the helper and its pins). The one source of truth used is `AuthConfig.uiBasePath`, through the auth service's `getConsoleUrl`. No `packages/spec/**` change and no new export; the one public-surface change is the optional `ApprovalServiceOptions.getConsoleUrl` member. ## Measured hops (real `os dev` boot, the showcase, which runs `serve --dev`) Boot: `objectstack dev --seed-admin --fresh -p 38617`, `OS_BASE_URL=http://localhost:38617`, SMTP pointed at a local sink (`OS_EMAIL_PROVIDER=smtp`, `OS_MAIL_SMTP_HOST=127.0.0.1`, `OS_MAIL_SMTP_SECURE=false`), Console built (`pnpm console:build`, the `console-static` plugin loaded). Trigger: sign in as the seeded admin and retitle the "Q3 field-ops rollout" announcement, which opens `showcase_dynamic_approval` (`approval.requested` to the admin). The URL was read from the e-mail the sink received. <details><summary>Before (origin/main a5a5312)</summary> - E-mail: `Open the approval: http://localhost:38617/system/approvals?request=areq_d3e65840-cc6b-43cf-877c-a2b5402aab42` - `GET` that URL, anonymous: `404`, `application/json`, `{"success":false,"error":{"code":"ENDPOINT_NOT_FOUND","message":"Not found"}}`, no `Location`. - Same URL signed in, following redirects: `404`, 0 redirects, the same JSON. Chromium: one navigation, `404`, page text is that JSON. - Action-link page inbox link `/system/approvals`: `404`. - Control: the same path under the mount, `/_console/system/approvals?request=...`: `200 text/html` with the base href set to the mount; in Chromium it opens the request ("Q3 field-ops rollout", Pending, Approve / Reject). </details> <details><summary>After (this branch, plugin-approvals rebuilt)</summary> - E-mail: `Open the approval: http://localhost:38617/_console/system/approvals?request=areq_9dac833e-7dad-48d7-bb38-4c6c8b6b82cd` - `GET` anonymous: `200 text/html`. Signed in, following redirects: `200`, 0 redirects, the base href is the mount. - Chromium: one navigation, `200`, then the Console routes to `/_console/apps/com.objectstack.setup/sys_approval_request/record/areq_9dac833e-...`, which shows the request (title, Pending, Lead Review, Approve / Reject). - `GET /api/v1/approvals/act?token=not-a-token`: `200`, and the inbox link is `http://localhost:38617/_console/system/approvals`, which answers `200`. </details> Root mount: no boot on this tree serves the Console at `/`. `createConsoleStaticPlugin` always mounts at `CONSOLE_PATH` (`/_console`), and `os serve` passes no `uiBasePath` to `AuthPlugin`, so it is always `/_console` there. A deployment that serves the Console at `/` tells the platform through `AuthConfig.uiBasePath: '/'`. That case is pinned at the service with the auth composer's exact composition: the link stays `BASE/system/approvals?request=ID`. Not measured on a real boot, because no boot here can produce it. ## Tests - `approval-service.test.ts`, new top-level describe "Console page links carry the Console mount": e-mail link under `/_console`, under `/`, the action page's inbox href under both, and no auth service (the e-mail link as before, the inbox link `BASE/system/approvals`). - `public-base-url.test.ts`, `consolePageLink`: composer origin ignored, root mount, shared sub-path, no base, and no composer / undefined / throws / not a URL. - `pnpm --filter @objectstack/plugin-approvals typecheck`: exit 0, test-typecheck debt held. `pnpm --filter @objectstack/plugin-approvals test`: 126 files, 1817 tests passed. Ablations (src-imported suite, both legs through `scripts/ablation-replace.mjs` with a disk-verified mutation and a HEAD-blob restore): - Mount dropped (`${publicBaseUrl}${pagePath}`): the `/_console` e-mail pin and the action-page pin go red (2 failed / 2 passed). The root and no-auth pins stay green. - Mount hard-coded (`${publicBaseUrl}/_console${pagePath}`): the root pin, the action-page pin and the no-auth pin go red (3 failed / 1 passed). - Restored: `git diff HEAD` empty, blob `1e946f96f358` equal to HEAD. ## Acceptance notes - With no auth service in the kernel (for example `os serve` in production without `OS_AUTH_SECRET`, where `AuthPlugin` is skipped), there is no mount to read: the e-mail link stays as before, and the inbox link becomes `BASE/system/approvals` (it was the origin-relative `/system/approvals`). Nobody can sign in to such a deployment's Console, so its approvals inbox cannot be used anyway. - With no `publicBaseUrl` the e-mail link is still relative, now under the mount (`/_console/system/approvals?...`) when the auth service answers; the inbox link is then the relative `/_console/system/approvals`. ## Verification First files to read, by risk: 1. `packages/plugins/plugin-approvals/src/public-base-url.ts`, `consoleMountPath`: the base-path strip is the one subtle line. 2. `packages/plugins/plugin-approvals/src/approvals-plugin.ts`: the lazy auth reader, and the raw-app mount's inbox href. 3. `packages/plugins/plugin-approvals/src/approval-service.ts`, the `approvalUrl` hunk in `notify()`. Two-minute check: `pnpm --filter @objectstack/plugin-approvals exec vitest run src/approval-service.test.ts -t "Console page links carry the Console mount"` shows 4 passed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01FEkQ5pb2t8Z8C64PkPyVt1 <!-- signed: repo:objectstack#4 · os-project-manager · session_01FEkQ5pb2t8Z8C64PkPyVt1 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 83e545a commit e100a37

7 files changed

Lines changed: 260 additions & 15 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@objectstack/plugin-approvals': patch
3+
---
4+
5+
fix(approvals): the approval e-mail's link and the action-link page's inbox link open the Console under its mount
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: none
9+
10+
The approval e-mail's "Open the approval" link was `BASE/system/approvals?request=ID`. `os serve` serves the Console at `/_console/` and nothing at `/system/*`, so the link answered `404 ENDPOINT_NOT_FOUND` and the request never opened. The "Open the Approvals Inbox" link on the action-link result page (`/api/v1/approvals/act`) had the same defect.
11+
12+
Both links now carry the Console's mount. The mount is read from the auth service's Console page composer (`getConsoleUrl`, which reads `AuthConfig.uiBasePath`, default `/_console`), the same composer the auth e-mails and the mention e-mail use.
13+
14+
- The e-mail link goes from `BASE/system/approvals?request=ID` to `BASE/_console/system/approvals?request=ID` on a default deployment. A deployment that sets `uiBasePath` to `/` keeps `BASE/system/approvals?request=ID`. Its base is still the approval links' own (`publicBaseUrl`, else `OS_AUTH_URL` / `OS_BASE_URL`). A kernel with no auth service has no mount to read, and the e-mail link stays as it was.
15+
- The inbox link goes from the origin-relative `/system/approvals` to `BASE/_console/system/approvals`. It is now absolute under the approval links' base when one resolves, and relative (`/_console/system/approvals`) when none does. With no mount to read (no auth service, or `uiBasePath` set to `/`) it is `BASE/system/approvals`.
16+
17+
The widening: the exported `ApprovalServiceOptions` gains the optional `getConsoleUrl` that carries the composer; the in-app `actionUrl` is unchanged.

‎packages/plugins/plugin-approvals/src/action-link-pages.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,25 @@ const RESULT_COPY: Record<string, { cls: string; title: string; body: string }>
108108
not_approver: { cls: 'warn', title: 'No longer your approval · 已不在你名下', body: 'This approval was handed to someone else. · 该审批已转由他人处理。' },
109109
};
110110

111-
/** Terminal page for every redemption outcome (and stale GETs). */
112-
export function renderResultPage(kind: keyof typeof RESULT_COPY, request?: ApprovalRequestRow): string {
111+
/** The Console's approvals inbox route, relative to the Console's mount. */
112+
export const APPROVALS_INBOX_PATH = '/system/approvals';
113+
114+
/**
115+
* Terminal page for every redemption outcome (and stale GETs).
116+
*
117+
* [#34862] `inboxHref` is the Console's inbox as the caller links it: under
118+
* the Console's mount (`consolePageLink`), which this page cannot know. It
119+
* defaults to the bare route.
120+
*/
121+
export function renderResultPage(
122+
kind: keyof typeof RESULT_COPY,
123+
request?: ApprovalRequestRow,
124+
inboxHref: string = APPROVALS_INBOX_PATH,
125+
): string {
113126
const copy = RESULT_COPY[kind] ?? RESULT_COPY.invalid;
114127
return shell(copy.title, `
115128
<span class="badge ${copy.cls}">${esc(copy.title)}</span>
116129
${request ? summaryRows(request) : ''}
117130
<p>${esc(copy.body)}</p>
118-
<p class="foot"><a href="/system/approvals">Open the Approvals Inbox · 打开审批中心</a></p>`);
131+
<p class="foot"><a href="${esc(inboxHref)}">Open the Approvals Inbox · 打开审批中心</a></p>`);
119132
}

‎packages/plugins/plugin-approvals/src/approval-service.test.ts‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7232,3 +7232,71 @@ describe('ApprovalService — one spec names each resolved person once (#28684)'
72327232
expect(snapshotGroups()).toEqual({ l1: ['legal', 'finance'] });
72337233
});
72347234
});
7235+
7236+
/**
7237+
* [#34862] A link that opens a Console page carries the Console's mount.
7238+
*
7239+
* `os serve` serves the Console at `/_console/` and nothing at `/system/*`, so
7240+
* the approval e-mail's link and the action-link pages' inbox link open a page
7241+
* only under that mount. The mount is read from the auth service's Console page
7242+
* composer (`getConsoleUrl`, which reads `AuthConfig.uiBasePath`); the double
7243+
* below composes exactly as `AuthManager.getConsolePageUrl` does, so the two
7244+
* mounts pinned here are the two values that setting takes: its `/_console`
7245+
* default, and `/` for a deployment that serves the Console at the root.
7246+
*/
7247+
describe('ApprovalService — Console page links carry the Console mount (#34862)', () => {
7248+
const ORIGIN = 'https://app.example.test';
7249+
/** `AuthManager.getConsolePageUrl`'s composition: `${origin}${uiBasePath}${path}`. */
7250+
const authComposer = (uiBasePath: string) => (path: string) =>
7251+
`${ORIGIN}${uiBasePath.replace(/\/$/, '')}${path.startsWith('/') ? path : `/${path}`}`;
7252+
7253+
function serviceUnder(uiBasePath: string | undefined) {
7254+
let n = 0;
7255+
const engine = makeFakeEngine();
7256+
const svc = new ApprovalService({
7257+
engine: engine as any,
7258+
clock: { now: () => new Date(Date.UTC(2026, 0, 15, 10, 0, n++)) },
7259+
publicBaseUrl: ORIGIN,
7260+
...(uiBasePath === undefined ? {} : { getConsoleUrl: authComposer(uiBasePath) }),
7261+
});
7262+
const emitted: any[] = [];
7263+
svc.attachMessaging({ async emit(input) { emitted.push(input); } });
7264+
return { svc, emitted };
7265+
}
7266+
7267+
async function requestedLink(uiBasePath: string | undefined) {
7268+
const { svc, emitted } = serviceUnder(uiBasePath);
7269+
const { id } = (await svc.openNodeRequest(openInput(['u9']), CTX)) as unknown as { id: string };
7270+
const [requested] = emitted.filter(e => e.topic === 'approval.requested');
7271+
return { id, payload: requested.payload };
7272+
}
7273+
7274+
async function inboxHref(uiBasePath: string | undefined) {
7275+
const { svc } = serviceUnder(uiBasePath);
7276+
const res = await svc.handleActionPage(new Request(`${ORIGIN}/api/v1/approvals/act?token=not-a-token`));
7277+
return /<a href="([^"]*)">Open the Approvals Inbox/.exec(await res.text())?.[1];
7278+
}
7279+
7280+
it('under the default /_console mount the e-mail link opens the request in the Console', async () => {
7281+
const { id, payload } = await requestedLink('/_console');
7282+
expect(payload.approvalUrl).toBe(`${ORIGIN}/_console/system/approvals?request=${id}`);
7283+
// The inbox notice's own link stays the Console's route: the Console routes on it.
7284+
expect(payload.actionUrl).toBe(`/system/approvals?request=${id}`);
7285+
});
7286+
7287+
it('under a root mount the e-mail link stays at the root', async () => {
7288+
const { id, payload } = await requestedLink('/');
7289+
expect(payload.approvalUrl).toBe(`${ORIGIN}/system/approvals?request=${id}`);
7290+
});
7291+
7292+
it('the action-link page links the Console inbox under the same mount', async () => {
7293+
expect(await inboxHref('/_console')).toBe(`${ORIGIN}/_console/system/approvals`);
7294+
expect(await inboxHref('/')).toBe(`${ORIGIN}/system/approvals`);
7295+
});
7296+
7297+
it('with no auth service there is no mount to read: the e-mail link is the one built before, and the inbox link carries the base', async () => {
7298+
const { id, payload } = await requestedLink(undefined);
7299+
expect(payload.approvalUrl).toBe(`${ORIGIN}/system/approvals?request=${id}`);
7300+
expect(await inboxHref(undefined)).toBe(`${ORIGIN}/system/approvals`);
7301+
});
7302+
});

‎packages/plugins/plugin-approvals/src/approval-service.ts‎

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ import { nodeConfigLocksRecord, recordHeldByLockingApproval } from './lifecycle-
166166
import { PendingApproverReadGrantSource, type PendingApproverReadGrants } from './pending-approver-read-grant.js';
167167
// The ADR-0043 pages — the ONE copy of their text, rendered by the plugin's
168168
// self-hosted mount and by `handleActionPage` alike.
169-
import { renderConfirmPage, renderResultPage } from './action-link-pages.js';
169+
import { APPROVALS_INBOX_PATH, renderConfirmPage, renderResultPage } from './action-link-pages.js';
170+
import { consolePageLink, type ConsolePageComposer } from './public-base-url.js';
170171
import { APPROVAL_EMAIL_CHANNELS, EMAILED_APPROVAL_TOPICS } from './approval-email-templates.js';
171172
import { enMessages } from './translations/messages.js';
172173
import {
@@ -574,7 +575,8 @@ type ApprovalNotificationPayload = {
574575
readonly actionUrl: string;
575576
/**
576577
* [#30509] The same request page as `actionUrl`, prefixed with the
577-
* deployment's public origin when one resolves (`publicBaseUrl`), for a
578+
* deployment's public origin when one resolves (`publicBaseUrl`) and
579+
* [#34862] the Console's mount (`consolePageLink`), for a
578580
* channel read outside the Console: the approval e-mail's link
579581
* (`approval-email-templates.ts`). Set by `notify()` beside the
580582
* deep-linked `actionUrl` on the notices that go by e-mail
@@ -2023,6 +2025,14 @@ export interface ApprovalServiceOptions {
20232025
* the Console and IM webviews; outbound email needs the absolute form.
20242026
*/
20252027
publicBaseUrl?: string;
2028+
/**
2029+
* [#34862] The auth service's Console page composer (`getConsoleUrl`,
2030+
* `${origin}${uiBasePath}${path}`), read for the Console's MOUNT only: the
2031+
* approval e-mail's link and the action-link pages' inbox link open a
2032+
* Console page under {@link publicBaseUrl} plus that mount
2033+
* (`consolePageLink`). Absent, or answering nothing, they carry no mount.
2034+
*/
2035+
getConsoleUrl?: ConsolePageComposer;
20262036
/**
20272037
* [ADR-0105 D9] The tenancy posture in force. Cross-organization approver
20282038
* targeting is a `group`-posture capability; the resolver refuses the
@@ -2213,6 +2223,7 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
22132223
private automation?: ApprovalResumeSurface;
22142224
private messaging?: ApprovalMessagingSurface;
22152225
private publicBaseUrl: string;
2226+
private readonly getConsoleUrl?: ConsolePageComposer;
22162227
private tenancyPosture?: () => string | undefined;
22172228
private fieldVisibility?: FieldVisibilitySource;
22182229
/** [#23637] Lazily-resolved object-level read admission ({@link attachObjectReadAdmission}). */
@@ -2267,6 +2278,7 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
22672278
this.automation = opts.automation;
22682279
this.messaging = opts.messaging;
22692280
this.publicBaseUrl = (opts.publicBaseUrl ?? '').replace(/\/$/, '');
2281+
this.getConsoleUrl = opts.getConsoleUrl;
22702282
this.tenancyPosture = opts.tenancyPosture;
22712283
this.fieldVisibility = opts.fieldVisibility;
22722284
this.messageTranslator = opts.messageTranslator;
@@ -2559,7 +2571,10 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
25592571
...payload,
25602572
actionUrl,
25612573
// [#30509] The e-mail's link: only the notices that go by e-mail carry it.
2562-
...(EMAILED_APPROVAL_TOPICS.has(event.topic) ? { approvalUrl: `${this.publicBaseUrl}${actionUrl}` } : {}),
2574+
// [#34862] A Console page, so under the Console's mount as well.
2575+
...(EMAILED_APPROVAL_TOPICS.has(event.topic)
2576+
? { approvalUrl: consolePageLink(this.publicBaseUrl, this.getConsoleUrl, actionUrl) }
2577+
: {}),
25632578
};
25642579
}
25652580
// A dedup key names ONE event: a notice split per name keys each part by
@@ -8094,7 +8109,7 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
80948109
if (request.method === 'GET') {
80958110
const token = new URL(request.url).searchParams.get('token') ?? '';
80968111
const peek = await this.peekActionToken(token);
8097-
if (!peek.ok) return actionPageResponse(renderResultPage(peek.reason, peek.request));
8112+
if (!peek.ok) return actionPageResponse(renderResultPage(peek.reason, peek.request, this.approvalsInboxLink()));
80988113
return actionPageResponse(renderConfirmPage({
80998114
request: peek.request, action: peek.action, approverId: peek.approverId,
81008115
token, actPath: ACTION_PAGE_PATH,
@@ -8109,12 +8124,24 @@ export class ApprovalService implements IApprovalService, ObjectSchemaReadDelega
81098124
token = String(fields[fields.length - 1] ?? '');
81108125
} catch { /* not a form body: no token, told "invalid" below */ }
81118126
const out = await this.redeemActionToken(token);
8112-
if (!out.ok) return actionPageResponse(renderResultPage(out.reason, out.request));
8113-
return actionPageResponse(renderResultPage(out.action === 'approve' ? 'approved' : 'rejected', out.request));
8127+
if (!out.ok) return actionPageResponse(renderResultPage(out.reason, out.request, this.approvalsInboxLink()));
8128+
return actionPageResponse(
8129+
renderResultPage(out.action === 'approve' ? 'approved' : 'rejected', out.request, this.approvalsInboxLink()),
8130+
);
81148131
}
81158132
return new Response(null, { status: 405, headers: { Allow: 'GET, POST' } });
81168133
}
81178134

8135+
/**
8136+
* [#34862] The action-link pages' "Open the Approvals Inbox" link: the
8137+
* Console's inbox under the approval links' base and the Console's mount,
8138+
* built as the plugin's raw-app mount builds it (`consolePageLink`), so the
8139+
* two doors still answer the same bytes.
8140+
*/
8141+
private approvalsInboxLink(): string {
8142+
return consolePageLink(this.publicBaseUrl, this.getConsoleUrl, APPROVALS_INBOX_PATH);
8143+
}
8144+
81188145
/**
81198146
* The person an action-link token's slot belongs to — the `sys_user` id to
81208147
* vouch for on the decision's context — or `null` when no person can be

‎packages/plugins/plugin-approvals/src/approvals-plugin.ts‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { SysApprovalApprover } from './sys-approval-approver.object.js';
1515
import { SysApprovalToken } from './sys-approval-token.object.js';
1616
import { SysApprovalDelegation } from './sys-approval-delegation.object.js';
1717
import { SysApprovalRequestDetailPage } from './sys-approval-request.page.js';
18-
import { renderConfirmPage, renderResultPage } from './action-link-pages.js';
18+
import { APPROVALS_INBOX_PATH, renderConfirmPage, renderResultPage } from './action-link-pages.js';
1919
import {
2020
ApprovalService,
2121
requestVisibilitySourceOf,
@@ -44,7 +44,7 @@ import { backfillActionSlots } from './action-slot-backfill.js';
4444
import { backfillApprovalDisplayLabels } from './display-label-backfill.js';
4545
import { backfillProcessPackages, logProcessPackageBackfill, type FlowHolderSource } from './stored-process-package-backfill.js';
4646
import { APPROVAL_EMAIL_TEMPLATES } from './approval-email-templates.js';
47-
import { resolvePublicBaseUrl } from './public-base-url.js';
47+
import { consolePageLink, resolvePublicBaseUrl } from './public-base-url.js';
4848

4949
export interface ApprovalsPluginOptions {
5050
/** Disable runtime registration (schemas still register). */
@@ -129,6 +129,8 @@ export class ApprovalsServicePlugin implements Plugin {
129129

130130
private readonly options: ApprovalsPluginOptions;
131131
private service?: ApprovalService;
132+
/** [#34862] A Console page's link under the approval links' base and the Console's mount. */
133+
private consoleLink?: (pagePath: string) => string;
132134
private engine?: IObjectQLEngine;
133135
private escalationJobScheduled = false;
134136
/**
@@ -251,10 +253,27 @@ export class ApprovalsServicePlugin implements Plugin {
251253
);
252254
}
253255

256+
// [#34862] The Console's mount, for the links that open a Console page:
257+
// the auth service's Console page composer (`getConsoleUrl`, which reads
258+
// `uiBasePath`), the one composer of Console page links in mail. Read at
259+
// link time: the auth service is another plugin's and may start later.
260+
// `getService` THROWS on an empty slot; no auth service, no mount.
261+
const getConsoleUrl = (path: string): string | undefined => {
262+
let auth: { getConsoleUrl?: (path: string) => string } | undefined;
263+
try {
264+
auth = ctx.getService<{ getConsoleUrl?: (path: string) => string }>('auth');
265+
} catch {
266+
return undefined;
267+
}
268+
return typeof auth?.getConsoleUrl === 'function' ? auth.getConsoleUrl(path) : undefined;
269+
};
270+
this.consoleLink = (pagePath) => consolePageLink(publicBase.url, getConsoleUrl, pagePath);
271+
254272
this.service = new ApprovalService({
255273
engine: engine as ApprovalEngine,
256274
logger: ctx.logger,
257275
publicBaseUrl: publicBase.url,
276+
getConsoleUrl,
258277
// [#8652] Read-only record-reader visibility. Default OFF — an absent
259278
// option reaches the service as an empty set. This is the host's half
260279
// only: an object's own `enable.approvalsVisibleToReaders` is read by
@@ -541,10 +560,14 @@ export class ApprovalsServicePlugin implements Plugin {
541560
const ACT_PATH = '/api/v1/approvals/act';
542561
const html = (c: any, body: string, status = 200) =>
543562
c.body(body, status, { 'Content-Type': 'text/html; charset=utf-8' });
563+
// [#34862] The inbox link under the Console's mount, as the service's
564+
// `handleActionPage` door builds it, so both doors answer one page.
565+
const consoleLink = this.consoleLink;
566+
const inboxHref = () => (consoleLink ? consoleLink(APPROVALS_INBOX_PATH) : APPROVALS_INBOX_PATH);
544567
rawApp.get(ACT_PATH, async (c: any) => {
545568
const token = String(c.req.query('token') ?? '');
546569
const peek = await svc.peekActionToken(token);
547-
if (!peek.ok) return html(c, renderResultPage(peek.reason, peek.request), 200);
570+
if (!peek.ok) return html(c, renderResultPage(peek.reason, peek.request, inboxHref()), 200);
548571
return html(c, renderConfirmPage({
549572
request: peek.request, action: peek.action, approverId: peek.approverId,
550573
token, actPath: ACT_PATH,
@@ -557,8 +580,8 @@ export class ApprovalsServicePlugin implements Plugin {
557580
token = String(body?.token ?? '');
558581
} catch { /* fall through to invalid */ }
559582
const out = await svc.redeemActionToken(token);
560-
if (!out.ok) return html(c, renderResultPage(out.reason, out.request), 200);
561-
return html(c, renderResultPage(out.action === 'approve' ? 'approved' : 'rejected', out.request));
583+
if (!out.ok) return html(c, renderResultPage(out.reason, out.request, inboxHref()), 200);
584+
return html(c, renderResultPage(out.action === 'approve' ? 'approved' : 'rejected', out.request, inboxHref()));
562585
});
563586
ctx.logger.info(`ApprovalsServicePlugin: actionable-link pages mounted at ${ACT_PATH}`);
564587
} catch { /* http server not installed */ }

‎packages/plugins/plugin-approvals/src/public-base-url.test.ts‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import { describe, it, expect } from 'vitest';
4-
import { resolvePublicBaseUrl } from './public-base-url.js';
4+
import { consolePageLink, resolvePublicBaseUrl } from './public-base-url.js';
55

66
/**
77
* [#30509] The origin approval links are built under: the option, else
@@ -42,3 +42,42 @@ describe('resolvePublicBaseUrl', () => {
4242
}
4343
});
4444
});
45+
46+
/**
47+
* [#34862] A Console page's link: the approval links' base, the Console's mount
48+
* read from the auth service's composer, then the page.
49+
*/
50+
describe('consolePageLink', () => {
51+
const at = (base: string, uiBasePath: string) => (path: string) => `${base}${uiBasePath.replace(/\/$/, '')}${path}`;
52+
53+
it('takes the mount from the composer and keeps its own origin', () => {
54+
expect(consolePageLink('https://app.example.test', at('https://app.example.test', '/_console'), '/system/approvals'))
55+
.toBe('https://app.example.test/_console/system/approvals');
56+
// The composer's origin is not taken: only its path is.
57+
expect(consolePageLink('https://mail.example.test', at('http://localhost:3000', '/_console'), '/system/approvals'))
58+
.toBe('https://mail.example.test/_console/system/approvals');
59+
});
60+
61+
it('a Console served at the root has no mount', () => {
62+
expect(consolePageLink('https://app.example.test', at('https://app.example.test', '/'), '/system/approvals'))
63+
.toBe('https://app.example.test/system/approvals');
64+
});
65+
66+
it('a base path the two share is not prefixed twice', () => {
67+
expect(consolePageLink('https://app.example.test/crm', at('https://app.example.test/crm', '/_console'), '/system/approvals'))
68+
.toBe('https://app.example.test/crm/_console/system/approvals');
69+
});
70+
71+
it('with no base the link is relative, still under the mount', () => {
72+
expect(consolePageLink('', at('http://localhost:3000', '/_console'), '/system/approvals'))
73+
.toBe('/_console/system/approvals');
74+
});
75+
76+
it('no composer, one that answers nothing, one that throws, or one that answers no URL: no mount', () => {
77+
const page = '/system/approvals';
78+
expect(consolePageLink('https://app.example.test', undefined, page)).toBe(`https://app.example.test${page}`);
79+
expect(consolePageLink('https://app.example.test', () => undefined, page)).toBe(`https://app.example.test${page}`);
80+
expect(consolePageLink('https://app.example.test', () => { throw new Error('no auth'); }, page)).toBe(`https://app.example.test${page}`);
81+
expect(consolePageLink('https://app.example.test', () => '/_console/', page)).toBe(`https://app.example.test${page}`);
82+
});
83+
});

0 commit comments

Comments
 (0)