@app-vitals/agent-admin 1.46.0 → 1.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/admin-boot.ts +3 -0
- package/src/admin-extension.ts +30 -0
- package/src/admin-extension.unit.test.ts +64 -1
- package/src/admin-ui-account-nav.unit.test.ts +33 -0
- package/src/admin-ui-github-enterprise-pages.ts +21 -7
- package/src/admin-ui-github-enterprise-pages.unit.test.ts +27 -1
- package/src/admin-ui-github-enterprise.smoke.test.ts +1 -1
- package/src/admin-ui-github-enterprise.ts +7 -0
- package/src/admin-ui-settings-layout.merge.unit.test.ts +66 -0
- package/src/admin-ui-settings-layout.ts +71 -0
- package/src/admin-ui-settings-layout.unit.test.ts +59 -0
- package/src/admin-ui-settings.smoke.test.ts +193 -0
- package/src/admin-ui-templates-pages.ts +20 -7
- package/src/admin-ui-templates-pages.unit.test.ts +22 -0
- package/src/admin-ui-templates.ts +5 -0
- package/src/admin-ui.ts +47 -2
- package/src/server.exports.unit.test.ts +35 -0
- package/src/server.ts +15 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-admin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.48.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/app-vitals/agent.git",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@anthropic-ai/sdk": "0.135.0",
|
|
45
|
-
"@app-vitals/agent-lib": "1.
|
|
45
|
+
"@app-vitals/agent-lib": "1.48.0",
|
|
46
46
|
"@hono/zod-openapi": "^1.0.0",
|
|
47
47
|
"@prisma/adapter-pg": "^7.10.0",
|
|
48
48
|
"@prisma/client": "^7.10.0",
|
package/src/admin-boot.ts
CHANGED
|
@@ -704,6 +704,9 @@ export async function startAdmin(
|
|
|
704
704
|
...(resolvedExtensions.agentDetailCards.length > 0
|
|
705
705
|
? { agentDetailCards: resolvedExtensions.agentDetailCards }
|
|
706
706
|
: {}),
|
|
707
|
+
...(resolvedExtensions.settingsNavItems.length > 0
|
|
708
|
+
? { settingsNavItems: resolvedExtensions.settingsNavItems }
|
|
709
|
+
: {}),
|
|
707
710
|
...resolvedExtensions.uiDeps,
|
|
708
711
|
});
|
|
709
712
|
root.route("/", adminUIApp);
|
package/src/admin-extension.ts
CHANGED
|
@@ -24,6 +24,12 @@
|
|
|
24
24
|
* agentDetailCards(ctx) — extra cards on the agent detail page, each placed
|
|
25
25
|
* in the header or the Configuration group
|
|
26
26
|
* backgroundPasses(ctx) — interval loops, started after the platform sweepers
|
|
27
|
+
* settingsNavItems(ctx) — extra settings-sidebar entries, each naming the
|
|
28
|
+
* section it joins (an unknown section is appended).
|
|
29
|
+
* Merged into the nav with mergeSettingsNavItems
|
|
30
|
+
* (admin-ui-settings-layout.ts, also exported from
|
|
31
|
+
* server.ts with renderSettingsLayout). A throwing
|
|
32
|
+
* hook is logged and contributes nothing
|
|
27
33
|
* specialtyDefaults(name) — a specialty's default crons/tools/plugins. Like
|
|
28
34
|
* serviceIntegrations it needs no context and is
|
|
29
35
|
* collected before the services are built; the cron
|
|
@@ -196,6 +202,15 @@ export interface AdminOpenApiContribution {
|
|
|
196
202
|
};
|
|
197
203
|
}
|
|
198
204
|
|
|
205
|
+
/** One settings-sidebar entry contributed by an extension. */
|
|
206
|
+
export interface SettingsNavContribution {
|
|
207
|
+
/** Label of the section to join; an unknown label appends a new section. */
|
|
208
|
+
section: string;
|
|
209
|
+
label: string;
|
|
210
|
+
path: string;
|
|
211
|
+
adminOnly?: boolean;
|
|
212
|
+
}
|
|
213
|
+
|
|
199
214
|
export interface AdminExtension {
|
|
200
215
|
name?: string;
|
|
201
216
|
/** See the header: env-only, resolved before the provisioner is built. */
|
|
@@ -209,6 +224,7 @@ export interface AdminExtension {
|
|
|
209
224
|
adminUiRoutes?(ctx: AdminExtensionContext): AdminRouteContribution[];
|
|
210
225
|
agentDetailCards?(ctx: AdminExtensionContext): AgentDetailCardSlot[];
|
|
211
226
|
backgroundPasses?(ctx: AdminExtensionContext): AdminBackgroundPass[];
|
|
227
|
+
settingsNavItems?(ctx: AdminExtensionContext): SettingsNavContribution[];
|
|
212
228
|
openApi?(): AdminOpenApiContribution;
|
|
213
229
|
}
|
|
214
230
|
|
|
@@ -219,6 +235,7 @@ export const ADMIN_EXTENSION_HOOK_ORDER = [
|
|
|
219
235
|
"adminUiRoutes",
|
|
220
236
|
"agentDetailCards",
|
|
221
237
|
"backgroundPasses",
|
|
238
|
+
"settingsNavItems",
|
|
222
239
|
] as const;
|
|
223
240
|
|
|
224
241
|
export interface ResolvedAdminExtensions {
|
|
@@ -230,6 +247,7 @@ export interface ResolvedAdminExtensions {
|
|
|
230
247
|
adminUiRoutes: AdminRouteContribution[];
|
|
231
248
|
agentDetailCards: AgentDetailCardSlot[];
|
|
232
249
|
backgroundPasses: AdminBackgroundPass[];
|
|
250
|
+
settingsNavItems: SettingsNavContribution[];
|
|
233
251
|
}
|
|
234
252
|
|
|
235
253
|
/**
|
|
@@ -248,6 +266,17 @@ export function resolveAdminExtensions(
|
|
|
248
266
|
const adminUiRoutes = collect((ext) => ext.adminUiRoutes?.(ctx));
|
|
249
267
|
const agentDetailCards = collect((ext) => ext.agentDetailCards?.(ctx));
|
|
250
268
|
const backgroundPasses = collect((ext) => ext.backgroundPasses?.(ctx));
|
|
269
|
+
const settingsNavItems = extensions.flatMap((ext) => {
|
|
270
|
+
try {
|
|
271
|
+
return ext.settingsNavItems?.(ctx) ?? [];
|
|
272
|
+
} catch (err) {
|
|
273
|
+
console.error(
|
|
274
|
+
`[admin] extension "${ext.name ?? "unnamed"}" settingsNavItems failed:`,
|
|
275
|
+
err,
|
|
276
|
+
);
|
|
277
|
+
return [];
|
|
278
|
+
}
|
|
279
|
+
});
|
|
251
280
|
const agentPhaseMethodologyService = services
|
|
252
281
|
.map((s) => s.agentPhaseMethodologyService)
|
|
253
282
|
.filter((svc) => svc !== undefined)
|
|
@@ -265,6 +294,7 @@ export function resolveAdminExtensions(
|
|
|
265
294
|
adminUiRoutes,
|
|
266
295
|
agentDetailCards,
|
|
267
296
|
backgroundPasses,
|
|
297
|
+
settingsNavItems,
|
|
268
298
|
};
|
|
269
299
|
}
|
|
270
300
|
|
|
@@ -53,6 +53,7 @@ describe("resolveAdminExtensions", () => {
|
|
|
53
53
|
adminUiRoutes: [],
|
|
54
54
|
agentDetailCards: [],
|
|
55
55
|
backgroundPasses: [],
|
|
56
|
+
settingsNavItems: [],
|
|
56
57
|
});
|
|
57
58
|
});
|
|
58
59
|
|
|
@@ -88,6 +89,10 @@ describe("resolveAdminExtensions", () => {
|
|
|
88
89
|
calls.push(`${id}:backgroundPasses:${c === ctx}`);
|
|
89
90
|
return [];
|
|
90
91
|
},
|
|
92
|
+
settingsNavItems: (c) => {
|
|
93
|
+
calls.push(`${id}:settingsNavItems:${c === ctx}`);
|
|
94
|
+
return [];
|
|
95
|
+
},
|
|
91
96
|
openApi: () => {
|
|
92
97
|
calls.push(`${id}:openApi`);
|
|
93
98
|
return {};
|
|
@@ -105,16 +110,74 @@ describe("resolveAdminExtensions", () => {
|
|
|
105
110
|
expect(calls.some((c) => c.endsWith(":openApi"))).toBe(false);
|
|
106
111
|
});
|
|
107
112
|
|
|
108
|
-
it("pins the hook order: services first,
|
|
113
|
+
it("pins the hook order: services first, settings nav items last", () => {
|
|
109
114
|
expect([...ADMIN_EXTENSION_HOOK_ORDER]).toEqual([
|
|
110
115
|
"services",
|
|
111
116
|
"apiRoutes",
|
|
112
117
|
"adminUiRoutes",
|
|
113
118
|
"agentDetailCards",
|
|
114
119
|
"backgroundPasses",
|
|
120
|
+
"settingsNavItems",
|
|
121
|
+
]);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("settingsNavItems: concatenates in extension order and passes adminOnly through", () => {
|
|
125
|
+
const resolved = resolveAdminExtensions(
|
|
126
|
+
[
|
|
127
|
+
{
|
|
128
|
+
settingsNavItems: () => [
|
|
129
|
+
{ section: "A", label: "a1", path: "/a1", adminOnly: true },
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
{},
|
|
133
|
+
{
|
|
134
|
+
settingsNavItems: (c) => [
|
|
135
|
+
{ section: c === ctx ? "B" : "?", label: "b1", path: "/b1" },
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
ctx,
|
|
140
|
+
);
|
|
141
|
+
expect(resolved.settingsNavItems).toEqual([
|
|
142
|
+
{ section: "A", label: "a1", path: "/a1", adminOnly: true },
|
|
143
|
+
{ section: "B", label: "b1", path: "/b1" },
|
|
115
144
|
]);
|
|
116
145
|
});
|
|
117
146
|
|
|
147
|
+
it("settingsNavItems: a throwing hook is logged and skipped, others unaffected", () => {
|
|
148
|
+
const errSpy = spyOn(console, "error").mockImplementation(() => {});
|
|
149
|
+
try {
|
|
150
|
+
const resolved = resolveAdminExtensions(
|
|
151
|
+
[
|
|
152
|
+
{
|
|
153
|
+
settingsNavItems: () => {
|
|
154
|
+
throw new Error("boom");
|
|
155
|
+
},
|
|
156
|
+
backgroundPasses: () => [
|
|
157
|
+
{
|
|
158
|
+
name: "p",
|
|
159
|
+
logPrefix: "[p]",
|
|
160
|
+
intervalMs: 1,
|
|
161
|
+
tick: async () => {},
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
settingsNavItems: () => [{ section: "S", label: "l", path: "/l" }],
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
ctx,
|
|
170
|
+
);
|
|
171
|
+
expect(resolved.settingsNavItems).toEqual([
|
|
172
|
+
{ section: "S", label: "l", path: "/l" },
|
|
173
|
+
]);
|
|
174
|
+
expect(resolved.backgroundPasses).toHaveLength(1);
|
|
175
|
+
expect(errSpy).toHaveBeenCalledTimes(1);
|
|
176
|
+
} finally {
|
|
177
|
+
errSpy.mockRestore();
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
118
181
|
it("concatenates list contributions in extension order", () => {
|
|
119
182
|
const app = new Hono();
|
|
120
183
|
const pass = (name: string): AdminBackgroundPass => ({
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/admin-ui-account-nav.unit.test.ts
|
|
3
|
+
* Flag plumbing for the toolbar Account / Settings entries.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, expect, test } from "bun:test";
|
|
7
|
+
import {
|
|
8
|
+
runWithAccountNav,
|
|
9
|
+
runWithSettingsNav,
|
|
10
|
+
shouldShowAccountNav,
|
|
11
|
+
shouldShowSettingsNav,
|
|
12
|
+
} from "./admin-ui-account-nav.ts";
|
|
13
|
+
|
|
14
|
+
describe("account-nav flags", () => {
|
|
15
|
+
test("both hidden outside any context", () => {
|
|
16
|
+
expect(shouldShowAccountNav()).toBe(false);
|
|
17
|
+
expect(shouldShowSettingsNav()).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
test("settings flag survives a nested account wrapper, and vice versa", () => {
|
|
20
|
+
runWithSettingsNav(true, () => {
|
|
21
|
+
runWithAccountNav(false, () => {
|
|
22
|
+
expect(shouldShowSettingsNav()).toBe(true);
|
|
23
|
+
expect(shouldShowAccountNav()).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
runWithAccountNav(true, () => {
|
|
27
|
+
runWithSettingsNav(false, () => {
|
|
28
|
+
expect(shouldShowAccountNav()).toBe(true);
|
|
29
|
+
expect(shouldShowSettingsNav()).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -12,7 +12,12 @@ import {
|
|
|
12
12
|
type GheWarningCode,
|
|
13
13
|
} from "./github-enterprise-warnings.ts";
|
|
14
14
|
import { renderAdminPage } from "./admin-ui-layout.ts";
|
|
15
|
-
import { escapeHtml
|
|
15
|
+
import { escapeHtml } from "./admin-ui-styles.ts";
|
|
16
|
+
import {
|
|
17
|
+
buildSettingsNav,
|
|
18
|
+
renderSettingsLayout,
|
|
19
|
+
type SettingsNav,
|
|
20
|
+
} from "./admin-ui-settings-layout.ts";
|
|
16
21
|
|
|
17
22
|
export const ADMIN_GITHUB_ENTERPRISE_PATH = "/admin/settings/github-enterprise";
|
|
18
23
|
|
|
@@ -53,6 +58,10 @@ export interface GheOrgs {
|
|
|
53
58
|
|
|
54
59
|
export interface GithubEnterpriseSettingsPageOpts {
|
|
55
60
|
userEmail: string;
|
|
61
|
+
/** Viewer is an admin (drives adminOnly sidebar items). */
|
|
62
|
+
isAdmin?: boolean;
|
|
63
|
+
/** Settings sidebar nav; defaults to the base Platform nav. */
|
|
64
|
+
nav?: SettingsNav;
|
|
56
65
|
status: GheStatus;
|
|
57
66
|
/** Present when the installer App is configured and the org list loaded. */
|
|
58
67
|
orgs?: GheOrgs;
|
|
@@ -263,13 +272,18 @@ export function renderGithubEnterpriseSettingsPage(
|
|
|
263
272
|
|
|
264
273
|
return renderAdminPage({
|
|
265
274
|
title: "GitHub Enterprise — Settings — Shipwright Admin",
|
|
266
|
-
body:
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
275
|
+
body: renderSettingsLayout({
|
|
276
|
+
userName: opts.userEmail,
|
|
277
|
+
title: "GitHub Enterprise apps",
|
|
278
|
+
nav:
|
|
279
|
+
opts.nav ??
|
|
280
|
+
buildSettingsNav({ githubEnterprise: true, templates: true }),
|
|
281
|
+
active: BASE,
|
|
282
|
+
isAdmin: opts.isAdmin ?? false,
|
|
283
|
+
body: `${error}${notice}${intro}
|
|
270
284
|
${appCard("installer", status.installer, opts.warnings)}
|
|
271
285
|
${appCard("lookup", status.lookup, opts.warnings)}
|
|
272
|
-
${orgsCard(opts)}
|
|
273
|
-
|
|
286
|
+
${orgsCard(opts)}`,
|
|
287
|
+
}),
|
|
274
288
|
});
|
|
275
289
|
}
|
|
@@ -262,6 +262,32 @@ describe("toolbar Settings entry", () => {
|
|
|
262
262
|
test("hidden outside a settings-nav context, shown inside one", () => {
|
|
263
263
|
expect(renderAdminToolbar("a@x.com")).not.toContain("/admin/settings");
|
|
264
264
|
const html = runWithSettingsNav(true, () => renderAdminToolbar("a@x.com"));
|
|
265
|
-
expect(html).toContain('href="/admin/settings
|
|
265
|
+
expect(html).toContain('href="/admin/settings" class="vos-nav-link');
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
describe("settings shell wrapper (SGL-2.2)", () => {
|
|
270
|
+
const html = renderGithubEnterpriseSettingsPage({
|
|
271
|
+
userEmail: "a@x.com",
|
|
272
|
+
isAdmin: true,
|
|
273
|
+
status: { configured: false, installer: null, lookup: null },
|
|
274
|
+
});
|
|
275
|
+
test("renders inside the settings layout with the active GHE item", () => {
|
|
276
|
+
expect(html).toContain("settings-sidebar");
|
|
277
|
+
expect(html).toContain(
|
|
278
|
+
'href="/admin/settings/github-enterprise" aria-current="page">GitHub Enterprise',
|
|
279
|
+
);
|
|
280
|
+
});
|
|
281
|
+
test("drops the ad hoc Agent templates cross-link button", () => {
|
|
282
|
+
expect(html).not.toContain('btn btn-secondary">Agent templates');
|
|
283
|
+
});
|
|
284
|
+
test("hides the adminOnly GHE item from non-admins", () => {
|
|
285
|
+
const h = renderGithubEnterpriseSettingsPage({
|
|
286
|
+
userEmail: "a@x.com",
|
|
287
|
+
status: { configured: false, installer: null, lookup: null },
|
|
288
|
+
});
|
|
289
|
+
expect(h).not.toContain(
|
|
290
|
+
'class="settings-nav-link" href="/admin/settings/github-enterprise"',
|
|
291
|
+
);
|
|
266
292
|
});
|
|
267
293
|
});
|
|
@@ -383,7 +383,7 @@ describe("nav entry in the full admin UI", () => {
|
|
|
383
383
|
headers: { "Content-Type": "application/json" },
|
|
384
384
|
},
|
|
385
385
|
);
|
|
386
|
-
const NAV = 'href="/admin/settings
|
|
386
|
+
const NAV = 'href="/admin/settings" class="vos-nav-link';
|
|
387
387
|
|
|
388
388
|
it("shows Settings to admins and serves the page", async () => {
|
|
389
389
|
const app = createAdminUIApp(makeMockDeps({ githubEnterpriseApi: api }));
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* `{ error }` bodies as readable messages. No key is ever read back.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import type { SettingsNav } from "./admin-ui-settings-layout.ts";
|
|
10
11
|
import type { Context, Hono, MiddlewareHandler } from "hono";
|
|
11
12
|
import { readPrivateKeyField } from "./github-enterprise-pem-upload.ts";
|
|
12
13
|
import { warningCodeFor } from "./github-enterprise-warnings.ts";
|
|
@@ -22,6 +23,8 @@ export interface AdminGithubEnterpriseRouteDeps {
|
|
|
22
23
|
requireAuth: MiddlewareHandler<AdminUIEnv>;
|
|
23
24
|
/** Calls the GHE-1.3 API app (its `.request`), e.g. `/github-enterprise/apps`. */
|
|
24
25
|
api: (path: string, init?: RequestInit) => Response | Promise<Response>;
|
|
26
|
+
/** Settings sidebar nav (SGL-2.2). */
|
|
27
|
+
settingsNav?: SettingsNav;
|
|
25
28
|
html: (content: string, opts?: { status?: number }) => Response;
|
|
26
29
|
}
|
|
27
30
|
|
|
@@ -103,6 +106,8 @@ export function registerAdminGithubEnterpriseRoutes(
|
|
|
103
106
|
return deps.html(
|
|
104
107
|
renderGithubEnterpriseSettingsPage({
|
|
105
108
|
userEmail: c.var.userEmail,
|
|
109
|
+
isAdmin: c.var.isAdmin === true,
|
|
110
|
+
...(deps.settingsNav ? { nav: deps.settingsNav } : {}),
|
|
106
111
|
status: { configured: false, installer: null, lookup: null },
|
|
107
112
|
error: flash.error ?? statusRes.error,
|
|
108
113
|
}),
|
|
@@ -123,6 +128,8 @@ export function registerAdminGithubEnterpriseRoutes(
|
|
|
123
128
|
return deps.html(
|
|
124
129
|
renderGithubEnterpriseSettingsPage({
|
|
125
130
|
userEmail: c.var.userEmail,
|
|
131
|
+
isAdmin: c.var.isAdmin === true,
|
|
132
|
+
...(deps.settingsNav ? { nav: deps.settingsNav } : {}),
|
|
126
133
|
status,
|
|
127
134
|
orgs,
|
|
128
135
|
orgsError,
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
mergeSettingsNavItems,
|
|
4
|
+
renderSettingsLayout,
|
|
5
|
+
type SettingsNav,
|
|
6
|
+
} from "./admin-ui-settings-layout.ts";
|
|
7
|
+
|
|
8
|
+
const base = (): SettingsNav => ({
|
|
9
|
+
sections: [
|
|
10
|
+
{ label: "General", items: [{ label: "Profile", path: "/p" }] },
|
|
11
|
+
{ label: "Org", items: [{ label: "Members", path: "/m" }] },
|
|
12
|
+
],
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe("mergeSettingsNavItems", () => {
|
|
16
|
+
it("appends into the section with a matching label", () => {
|
|
17
|
+
const out = mergeSettingsNavItems(base(), [
|
|
18
|
+
{ section: "General", label: "Extra", path: "/x" },
|
|
19
|
+
]);
|
|
20
|
+
expect(out.sections.map((s) => s.label)).toEqual(["General", "Org"]);
|
|
21
|
+
expect(out.sections[0]?.items).toEqual([
|
|
22
|
+
{ label: "Profile", path: "/p" },
|
|
23
|
+
{ label: "Extra", path: "/x" },
|
|
24
|
+
]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("appends a new section at the end for an unknown label", () => {
|
|
28
|
+
const out = mergeSettingsNavItems(base(), [
|
|
29
|
+
{ section: "Coding", label: "A", path: "/a" },
|
|
30
|
+
{ section: "Coding", label: "B", path: "/b" },
|
|
31
|
+
]);
|
|
32
|
+
expect(out.sections.map((s) => s.label)).toEqual([
|
|
33
|
+
"General",
|
|
34
|
+
"Org",
|
|
35
|
+
"Coding",
|
|
36
|
+
]);
|
|
37
|
+
expect(out.sections[2]?.items.map((i) => i.label)).toEqual(["A", "B"]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("does not mutate the input", () => {
|
|
41
|
+
const nav = base();
|
|
42
|
+
const snapshot = structuredClone(nav);
|
|
43
|
+
mergeSettingsNavItems(nav, [
|
|
44
|
+
{ section: "General", label: "Extra", path: "/x" },
|
|
45
|
+
{ section: "New", label: "N", path: "/n" },
|
|
46
|
+
]);
|
|
47
|
+
expect(nav).toEqual(snapshot);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("preserves adminOnly so non-admins do not see the item", () => {
|
|
51
|
+
const nav = mergeSettingsNavItems(base(), [
|
|
52
|
+
{ section: "Coding", label: "Secret", path: "/s", adminOnly: true },
|
|
53
|
+
]);
|
|
54
|
+
const render = (isAdmin: boolean) =>
|
|
55
|
+
renderSettingsLayout({
|
|
56
|
+
userName: "u",
|
|
57
|
+
title: "T",
|
|
58
|
+
nav,
|
|
59
|
+
active: "/p",
|
|
60
|
+
body: "",
|
|
61
|
+
isAdmin,
|
|
62
|
+
});
|
|
63
|
+
expect(render(false)).not.toContain("Secret");
|
|
64
|
+
expect(render(true)).toContain("Secret");
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Styles live in baseStyles() between the "Settings layout" markers.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import type { SettingsNavContribution } from "./admin-extension.ts";
|
|
8
9
|
import { escapeHtml, renderAdminToolbar } from "./admin-ui-styles.ts";
|
|
9
10
|
|
|
10
11
|
export interface SettingsNavItem {
|
|
@@ -75,3 +76,73 @@ export function renderSettingsLayout(
|
|
|
75
76
|
</div>
|
|
76
77
|
</div>`;
|
|
77
78
|
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Appends contributed items into the section with the matching label (an
|
|
82
|
+
* unknown section is appended at the end). Pure: the input nav is not mutated.
|
|
83
|
+
*/
|
|
84
|
+
export function mergeSettingsNavItems(
|
|
85
|
+
nav: SettingsNav,
|
|
86
|
+
items: SettingsNavContribution[],
|
|
87
|
+
): SettingsNav {
|
|
88
|
+
const sections: SettingsNavSection[] = nav.sections.map((s) => ({
|
|
89
|
+
label: s.label,
|
|
90
|
+
items: [...s.items],
|
|
91
|
+
}));
|
|
92
|
+
for (const { section, ...item } of items) {
|
|
93
|
+
let target = sections.find((s) => s.label === section);
|
|
94
|
+
if (!target) {
|
|
95
|
+
target = { label: section, items: [] };
|
|
96
|
+
sections.push(target);
|
|
97
|
+
}
|
|
98
|
+
target.items.push(item);
|
|
99
|
+
}
|
|
100
|
+
return { sections };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const SETTINGS_GHE_PATH = "/admin/settings/github-enterprise";
|
|
104
|
+
export const SETTINGS_TEMPLATES_PATH = "/admin/settings/templates";
|
|
105
|
+
|
|
106
|
+
export interface BuildSettingsNavOptions {
|
|
107
|
+
/** Include the GitHub Enterprise item (its routes are registered). */
|
|
108
|
+
githubEnterprise?: boolean;
|
|
109
|
+
/** Include the Templates item (its routes are registered). */
|
|
110
|
+
templates?: boolean;
|
|
111
|
+
/** Extension-contributed items (SGL-2.1). */
|
|
112
|
+
extraItems?: readonly SettingsNavContribution[];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Base settings nav (SGL-2.2): the Platform section plus extension items.
|
|
117
|
+
* Account/Personal sections arrive in SGL-2.3. Empty sections are dropped.
|
|
118
|
+
*/
|
|
119
|
+
export function buildSettingsNav(
|
|
120
|
+
opts: BuildSettingsNavOptions = {},
|
|
121
|
+
): SettingsNav {
|
|
122
|
+
const platform: SettingsNavItem[] = [];
|
|
123
|
+
if (opts.githubEnterprise) {
|
|
124
|
+
platform.push({
|
|
125
|
+
label: "GitHub Enterprise",
|
|
126
|
+
path: SETTINGS_GHE_PATH,
|
|
127
|
+
adminOnly: true,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (opts.templates) {
|
|
131
|
+
platform.push({ label: "Templates", path: SETTINGS_TEMPLATES_PATH });
|
|
132
|
+
}
|
|
133
|
+
const base: SettingsNav = {
|
|
134
|
+
sections:
|
|
135
|
+
platform.length > 0 ? [{ label: "Platform", items: platform }] : [],
|
|
136
|
+
};
|
|
137
|
+
return mergeSettingsNavItems(base, [...(opts.extraItems ?? [])]);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** First nav item visible to the viewer, or undefined. */
|
|
141
|
+
export function firstVisibleSettingsItem(
|
|
142
|
+
nav: SettingsNav,
|
|
143
|
+
isAdmin: boolean,
|
|
144
|
+
): SettingsNavItem | undefined {
|
|
145
|
+
return nav.sections
|
|
146
|
+
.flatMap((s) => s.items)
|
|
147
|
+
.find((i) => isAdmin || !i.adminOnly);
|
|
148
|
+
}
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
import { describe, expect, test } from "bun:test";
|
|
7
7
|
import {
|
|
8
|
+
buildSettingsNav,
|
|
9
|
+
firstVisibleSettingsItem,
|
|
8
10
|
renderSettingsLayout,
|
|
9
11
|
type SettingsNav,
|
|
10
12
|
} from "./admin-ui-settings-layout.ts";
|
|
@@ -104,3 +106,60 @@ describe("renderSettingsLayout", () => {
|
|
|
104
106
|
expect(withPath).toContain("vos-toolbar");
|
|
105
107
|
});
|
|
106
108
|
});
|
|
109
|
+
|
|
110
|
+
describe("buildSettingsNav / firstVisibleSettingsItem (SGL-2.2)", () => {
|
|
111
|
+
const both = { githubEnterprise: true, templates: true };
|
|
112
|
+
test("Platform section lists GHE (adminOnly) then Templates", () => {
|
|
113
|
+
expect(buildSettingsNav(both)).toEqual({
|
|
114
|
+
sections: [
|
|
115
|
+
{
|
|
116
|
+
label: "Platform",
|
|
117
|
+
items: [
|
|
118
|
+
{
|
|
119
|
+
label: "GitHub Enterprise",
|
|
120
|
+
path: "/admin/settings/github-enterprise",
|
|
121
|
+
adminOnly: true,
|
|
122
|
+
},
|
|
123
|
+
{ label: "Templates", path: "/admin/settings/templates" },
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
test("omits unregistered features and empty sections", () => {
|
|
130
|
+
expect(buildSettingsNav({})).toEqual({ sections: [] });
|
|
131
|
+
expect(
|
|
132
|
+
buildSettingsNav({ templates: true }).sections[0]?.items.map(
|
|
133
|
+
(i) => i.label,
|
|
134
|
+
),
|
|
135
|
+
).toEqual(["Templates"]);
|
|
136
|
+
});
|
|
137
|
+
test("merges extension items into Platform or new sections", () => {
|
|
138
|
+
const nav = buildSettingsNav({
|
|
139
|
+
...both,
|
|
140
|
+
extraItems: [
|
|
141
|
+
{ section: "Platform", label: "A", path: "/a" },
|
|
142
|
+
{ section: "Extras", label: "B", path: "/b" },
|
|
143
|
+
],
|
|
144
|
+
});
|
|
145
|
+
expect(nav.sections.map((s) => s.label)).toEqual(["Platform", "Extras"]);
|
|
146
|
+
expect(nav.sections[0]?.items.map((i) => i.label)).toEqual([
|
|
147
|
+
"GitHub Enterprise",
|
|
148
|
+
"Templates",
|
|
149
|
+
"A",
|
|
150
|
+
]);
|
|
151
|
+
});
|
|
152
|
+
test("first visible item respects adminOnly", () => {
|
|
153
|
+
const nav = buildSettingsNav(both);
|
|
154
|
+
expect(firstVisibleSettingsItem(nav, true)?.label).toBe(
|
|
155
|
+
"GitHub Enterprise",
|
|
156
|
+
);
|
|
157
|
+
expect(firstVisibleSettingsItem(nav, false)?.label).toBe("Templates");
|
|
158
|
+
expect(
|
|
159
|
+
firstVisibleSettingsItem(
|
|
160
|
+
buildSettingsNav({ githubEnterprise: true }),
|
|
161
|
+
false,
|
|
162
|
+
),
|
|
163
|
+
).toBeUndefined();
|
|
164
|
+
});
|
|
165
|
+
});
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/admin-ui-settings.smoke.test.ts
|
|
3
|
+
* Smoke tests for the settings shell (SGL-2.2): GET /admin/settings redirect,
|
|
4
|
+
* sidebar rendering on GHE + Templates, and the toolbar Settings entry for
|
|
5
|
+
* admins / account members / non-account admins. Via the full admin UI app.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, expect, it } from "bun:test";
|
|
9
|
+
import { makeMockDeps, makeSessionCookie } from "./admin-ui.fixtures.ts";
|
|
10
|
+
import { createAdminUIApp } from "./admin-ui.ts";
|
|
11
|
+
|
|
12
|
+
const ghe = async () =>
|
|
13
|
+
new Response(
|
|
14
|
+
JSON.stringify({ configured: false, installer: null, lookup: null }),
|
|
15
|
+
{ status: 200, headers: { "Content-Type": "application/json" } },
|
|
16
|
+
);
|
|
17
|
+
const templateService = {
|
|
18
|
+
list: async () => [],
|
|
19
|
+
replace: async () => {
|
|
20
|
+
throw new Error("unused");
|
|
21
|
+
},
|
|
22
|
+
putItem: async () => {
|
|
23
|
+
throw new Error("unused");
|
|
24
|
+
},
|
|
25
|
+
deleteItem: async () => {},
|
|
26
|
+
delete: async () => {},
|
|
27
|
+
} as never;
|
|
28
|
+
|
|
29
|
+
const adminCookie = async () => `admin_session=${await makeSessionCookie()}`;
|
|
30
|
+
const userCookie = async (email = "m@acme.com") =>
|
|
31
|
+
`admin_session=${await makeSessionCookie(undefined, "u2", email, false)}`;
|
|
32
|
+
|
|
33
|
+
const memberAccounts = (member: string | null) =>
|
|
34
|
+
({
|
|
35
|
+
accounts: {
|
|
36
|
+
getByMemberEmail: async (e: string) =>
|
|
37
|
+
e === member ? ({ id: "acct-1", name: "Acme" } as never) : null,
|
|
38
|
+
listWithCounts: async () => [{ id: "acct-1", name: "Acme" }],
|
|
39
|
+
getWithCounts: async (id: string) => ({ id, name: "Acme" }),
|
|
40
|
+
},
|
|
41
|
+
members: {},
|
|
42
|
+
}) as never;
|
|
43
|
+
|
|
44
|
+
describe("GET /admin/settings", () => {
|
|
45
|
+
it("redirects an admin to GitHub Enterprise when registered", async () => {
|
|
46
|
+
const app = createAdminUIApp(
|
|
47
|
+
makeMockDeps({ githubEnterpriseApi: ghe, templateService }),
|
|
48
|
+
);
|
|
49
|
+
const res = await app.request("/admin/settings", {
|
|
50
|
+
headers: { cookie: await adminCookie() },
|
|
51
|
+
});
|
|
52
|
+
expect(res.status).toBe(302);
|
|
53
|
+
expect(res.headers.get("location")).toBe(
|
|
54
|
+
"/admin/settings/github-enterprise",
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("redirects an admin to Templates when only templates are wired", async () => {
|
|
59
|
+
const app = createAdminUIApp(makeMockDeps({ templateService }));
|
|
60
|
+
const res = await app.request("/admin/settings", {
|
|
61
|
+
headers: { cookie: await adminCookie() },
|
|
62
|
+
});
|
|
63
|
+
expect(res.headers.get("location")).toBe("/admin/settings/templates");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("redirects a non-admin member past the adminOnly item", async () => {
|
|
67
|
+
const app = createAdminUIApp(
|
|
68
|
+
makeMockDeps({
|
|
69
|
+
githubEnterpriseApi: ghe,
|
|
70
|
+
templateService,
|
|
71
|
+
accountServices: memberAccounts("m@acme.com"),
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
const res = await app.request("/admin/settings", {
|
|
75
|
+
headers: { cookie: await userCookie() },
|
|
76
|
+
});
|
|
77
|
+
expect(res.status).toBe(302);
|
|
78
|
+
expect(res.headers.get("location")).toBe("/admin/settings/templates");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("404s a non-admin when only admin-only items exist", async () => {
|
|
82
|
+
const app = createAdminUIApp(makeMockDeps({ githubEnterpriseApi: ghe }));
|
|
83
|
+
const res = await app.request("/admin/settings", {
|
|
84
|
+
headers: { cookie: await userCookie() },
|
|
85
|
+
});
|
|
86
|
+
expect(res.status).toBe(404);
|
|
87
|
+
expect(await res.text()).toContain("No settings");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("is not registered without GHE or templates", async () => {
|
|
91
|
+
const app = createAdminUIApp(makeMockDeps());
|
|
92
|
+
const res = await app.request("/admin/settings", {
|
|
93
|
+
headers: { cookie: await adminCookie() },
|
|
94
|
+
});
|
|
95
|
+
expect(res.status).toBe(404);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("requires a session", async () => {
|
|
99
|
+
const app = createAdminUIApp(makeMockDeps({ templateService }));
|
|
100
|
+
const res = await app.request("/admin/settings");
|
|
101
|
+
expect(res.status).not.toBe(200);
|
|
102
|
+
expect(res.headers.get("location") ?? "").not.toBe(
|
|
103
|
+
"/admin/settings/templates",
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe("settings shell pages", () => {
|
|
109
|
+
it("renders GHE in the shell with an active sidebar item and no cross-link button", async () => {
|
|
110
|
+
const app = createAdminUIApp(
|
|
111
|
+
makeMockDeps({ githubEnterpriseApi: ghe, templateService }),
|
|
112
|
+
);
|
|
113
|
+
const html = await (
|
|
114
|
+
await app.request("/admin/settings/github-enterprise", {
|
|
115
|
+
headers: { cookie: await adminCookie() },
|
|
116
|
+
})
|
|
117
|
+
).text();
|
|
118
|
+
expect(html).toContain("settings-sidebar");
|
|
119
|
+
expect(html).toContain(
|
|
120
|
+
'href="/admin/settings/github-enterprise" aria-current="page">GitHub Enterprise',
|
|
121
|
+
);
|
|
122
|
+
expect(html).toContain('href="/admin/settings/templates"');
|
|
123
|
+
expect(html).not.toContain('btn btn-secondary">Agent templates');
|
|
124
|
+
expect(html).toContain(
|
|
125
|
+
'href="/admin/settings" class="vos-nav-link active"',
|
|
126
|
+
);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("renders Templates in the shell and hides the GHE item from members", async () => {
|
|
130
|
+
const app = createAdminUIApp(
|
|
131
|
+
makeMockDeps({
|
|
132
|
+
githubEnterpriseApi: ghe,
|
|
133
|
+
templateService,
|
|
134
|
+
callerScopeResolver: async () => ({
|
|
135
|
+
kind: "scoped" as const,
|
|
136
|
+
accountId: "acct-1",
|
|
137
|
+
agentIds: [],
|
|
138
|
+
}),
|
|
139
|
+
accountServices: memberAccounts("m@acme.com"),
|
|
140
|
+
}),
|
|
141
|
+
);
|
|
142
|
+
const res = await app.request("/admin/settings/templates", {
|
|
143
|
+
headers: { cookie: await userCookie() },
|
|
144
|
+
});
|
|
145
|
+
expect(res.status).toBe(200);
|
|
146
|
+
const html = await res.text();
|
|
147
|
+
expect(html).toContain(
|
|
148
|
+
'href="/admin/settings/templates" aria-current="page">Templates',
|
|
149
|
+
);
|
|
150
|
+
expect(html).not.toContain(
|
|
151
|
+
'class="settings-nav-link" href="/admin/settings/github-enterprise"',
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("lists extension nav items in the sidebar", async () => {
|
|
156
|
+
const app = createAdminUIApp(
|
|
157
|
+
makeMockDeps({
|
|
158
|
+
templateService,
|
|
159
|
+
settingsNavItems: [
|
|
160
|
+
{ section: "Platform", label: "Widgets", path: "/admin/widgets" },
|
|
161
|
+
],
|
|
162
|
+
}),
|
|
163
|
+
);
|
|
164
|
+
const html = await (
|
|
165
|
+
await app.request("/admin/settings/templates", {
|
|
166
|
+
headers: { cookie: await adminCookie() },
|
|
167
|
+
})
|
|
168
|
+
).text();
|
|
169
|
+
expect(html).toContain('href="/admin/widgets"');
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe("toolbar Settings entry", () => {
|
|
174
|
+
const settingsLink = 'href="/admin/settings"';
|
|
175
|
+
const get = async (app: ReturnType<typeof createAdminUIApp>, c: string) =>
|
|
176
|
+
(await app.request("/admin/agents", { headers: { cookie: c } })).text();
|
|
177
|
+
|
|
178
|
+
it("shows for a non-account admin and for account members, hides for others", async () => {
|
|
179
|
+
const app = createAdminUIApp(
|
|
180
|
+
makeMockDeps({
|
|
181
|
+
templateService,
|
|
182
|
+
accountServices: memberAccounts("m@acme.com"),
|
|
183
|
+
}),
|
|
184
|
+
);
|
|
185
|
+
expect(await get(app, await adminCookie())).toContain(settingsLink);
|
|
186
|
+
expect(await get(app, await userCookie("m@acme.com"))).toContain(
|
|
187
|
+
settingsLink,
|
|
188
|
+
);
|
|
189
|
+
expect(await get(app, await userCookie("x@other.com"))).not.toContain(
|
|
190
|
+
settingsLink,
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
@@ -9,7 +9,12 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { renderAdminPage } from "./admin-ui-layout.ts";
|
|
12
|
-
import { escapeHtml
|
|
12
|
+
import { escapeHtml } from "./admin-ui-styles.ts";
|
|
13
|
+
import {
|
|
14
|
+
buildSettingsNav,
|
|
15
|
+
renderSettingsLayout,
|
|
16
|
+
type SettingsNav,
|
|
17
|
+
} from "./admin-ui-settings-layout.ts";
|
|
13
18
|
|
|
14
19
|
export const ADMIN_TEMPLATES_PATH = "/admin/settings/templates";
|
|
15
20
|
|
|
@@ -28,6 +33,10 @@ export interface TemplateItemRow {
|
|
|
28
33
|
|
|
29
34
|
export interface TemplatesPageOpts {
|
|
30
35
|
userEmail: string;
|
|
36
|
+
/** Viewer is an admin (drives adminOnly sidebar items). */
|
|
37
|
+
isAdmin?: boolean;
|
|
38
|
+
/** Settings sidebar nav; defaults to the base Platform nav. */
|
|
39
|
+
nav?: SettingsNav;
|
|
31
40
|
/** Accounts the caller may pick; the deployment-wide option is included only for admins. */
|
|
32
41
|
accountOptions: TemplateScopeOption[];
|
|
33
42
|
specialtyOptions: TemplateScopeOption[];
|
|
@@ -140,16 +149,20 @@ export function renderTemplatesPage(o: TemplatesPageOpts): string {
|
|
|
140
149
|
: `<p class="help-text">No template exists for this scope yet. Adding an item creates it.</p>`;
|
|
141
150
|
return renderAdminPage({
|
|
142
151
|
title: "Templates — Settings — Shipwright Admin",
|
|
143
|
-
body:
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
152
|
+
body: renderSettingsLayout({
|
|
153
|
+
userName: o.userEmail,
|
|
154
|
+
title: "Agent templates",
|
|
155
|
+
nav:
|
|
156
|
+
o.nav ?? buildSettingsNav({ githubEnterprise: true, templates: true }),
|
|
157
|
+
active: BASE,
|
|
158
|
+
isAdmin: o.isAdmin ?? false,
|
|
159
|
+
body: `${error}${notice}
|
|
147
160
|
<div class="card">
|
|
148
161
|
<p class="help-text">Default env vars, tools, plugins and crons for new agents in a scope. Secret values are masked after saving; leave <code>***</code> to keep the stored value.</p>
|
|
149
162
|
${scopePicker(o)}
|
|
150
163
|
${del}
|
|
151
164
|
</div>
|
|
152
|
-
${(["env", "tool", "plugin", "cron"] as const).map((k) => kindCard(o, k)).join("\n")}
|
|
153
|
-
|
|
165
|
+
${(["env", "tool", "plugin", "cron"] as const).map((k) => kindCard(o, k)).join("\n")}`,
|
|
166
|
+
}),
|
|
154
167
|
});
|
|
155
168
|
}
|
|
@@ -52,3 +52,25 @@ describe("renderTemplatesPage", () => {
|
|
|
52
52
|
expect(html).toMatch(/name="secret" value="1" checked/);
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
|
+
|
|
56
|
+
describe("renderTemplatesPage settings shell (SGL-2.2)", () => {
|
|
57
|
+
it("renders inside the settings layout with Templates active", () => {
|
|
58
|
+
const html = renderTemplatesPage({ ...base, isAdmin: true });
|
|
59
|
+
expect(html).toContain("settings-sidebar");
|
|
60
|
+
expect(html).toContain(
|
|
61
|
+
'href="/admin/settings/templates" aria-current="page">Templates',
|
|
62
|
+
);
|
|
63
|
+
expect(html).toContain("Agent templates");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("hides the adminOnly GitHub Enterprise item from non-admins", () => {
|
|
67
|
+
const member = renderTemplatesPage(base);
|
|
68
|
+
expect(member).not.toContain(
|
|
69
|
+
'class="settings-nav-link" href="/admin/settings/github-enterprise"',
|
|
70
|
+
);
|
|
71
|
+
const admin = renderTemplatesPage({ ...base, isAdmin: true });
|
|
72
|
+
expect(admin).toContain(
|
|
73
|
+
'class="settings-nav-link" href="/admin/settings/github-enterprise"',
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* errors (denylisted env key, unknown specialty, bad payload) are shown inline.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
import type { SettingsNav } from "./admin-ui-settings-layout.ts";
|
|
11
12
|
import type { Context, Hono, MiddlewareHandler } from "hono";
|
|
12
13
|
import { accountIdFromScope } from "./account-agent-create.ts";
|
|
13
14
|
import type { AccountService } from "./accounts.ts";
|
|
@@ -39,6 +40,8 @@ export interface AdminTemplatesRouteDeps {
|
|
|
39
40
|
"list" | "replace" | "putItem" | "deleteItem" | "delete"
|
|
40
41
|
>;
|
|
41
42
|
callerScopeResolver: CallerScopeResolver;
|
|
43
|
+
/** Settings sidebar nav (SGL-2.2). */
|
|
44
|
+
settingsNav?: SettingsNav;
|
|
42
45
|
/** Optional: without it admins can only pick deployment-wide. */
|
|
43
46
|
accounts?: Pick<AccountService, "listWithCounts" | "getWithCounts">;
|
|
44
47
|
specialtyRegistry: Pick<SpecialtyTypeResolver, "listTypes">;
|
|
@@ -141,6 +144,8 @@ export function registerAdminTemplatesRoutes(
|
|
|
141
144
|
return deps.html(
|
|
142
145
|
renderTemplatesPage({
|
|
143
146
|
userEmail: c.var.userEmail,
|
|
147
|
+
isAdmin: c.var.isAdmin === true,
|
|
148
|
+
...(deps.settingsNav ? { nav: deps.settingsNav } : {}),
|
|
144
149
|
accountOptions: await accountOptions(actor),
|
|
145
150
|
specialtyOptions: specialtyOptions(),
|
|
146
151
|
accountId: scope.accountId,
|
package/src/admin-ui.ts
CHANGED
|
@@ -42,6 +42,7 @@ import type { AccountOnboardingService } from "./account-onboarding.ts";
|
|
|
42
42
|
import type { AccountService } from "./accounts.ts";
|
|
43
43
|
import {
|
|
44
44
|
type AgentDetailCardSlot,
|
|
45
|
+
type SettingsNavContribution,
|
|
45
46
|
renderAgentDetailCardSlots,
|
|
46
47
|
} from "./admin-extension.ts";
|
|
47
48
|
import { registerAccountRoutes } from "./admin-ui-account.ts";
|
|
@@ -51,6 +52,10 @@ import {
|
|
|
51
52
|
} from "./admin-ui-account-nav.ts";
|
|
52
53
|
import { renderZeroQuotaNotice } from "./admin-ui-account-pages.ts";
|
|
53
54
|
import { registerAdminAccountsRoutes } from "./admin-ui-accounts.ts";
|
|
55
|
+
import {
|
|
56
|
+
buildSettingsNav,
|
|
57
|
+
firstVisibleSettingsItem,
|
|
58
|
+
} from "./admin-ui-settings-layout.ts";
|
|
54
59
|
import { registerAdminGithubEnterpriseRoutes } from "./admin-ui-github-enterprise.ts";
|
|
55
60
|
import { registerAdminTemplatesRoutes } from "./admin-ui-templates.ts";
|
|
56
61
|
import type { AgentTemplateReconcileService } from "./agent-template-reconcile.ts";
|
|
@@ -316,6 +321,11 @@ export interface AdminUIDeps {
|
|
|
316
321
|
* group); absent renders none.
|
|
317
322
|
*/
|
|
318
323
|
agentDetailCards?: readonly AgentDetailCardSlot[];
|
|
324
|
+
/**
|
|
325
|
+
* Optional extension items for the settings sidebar (SGL-2.1/2.2,
|
|
326
|
+
* ResolvedAdminExtensions.settingsNavItems); absent adds none.
|
|
327
|
+
*/
|
|
328
|
+
settingsNavItems?: readonly SettingsNavContribution[];
|
|
319
329
|
/**
|
|
320
330
|
* True when an extension mounts /admin/agents/:id/queue-activity (the coding
|
|
321
331
|
* extension, AEP-3.6); the agents list and agent detail render their Queue &
|
|
@@ -915,11 +925,22 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
915
925
|
|
|
916
926
|
// GHE-1.4: the admin-only "Settings" toolbar entry. Registered before the
|
|
917
927
|
// Account middleware; the two merge their flags in the shared store.
|
|
918
|
-
|
|
928
|
+
// SGL-2.2: shown to admins and to account members.
|
|
929
|
+
if (githubEnterpriseApi || templateService) {
|
|
919
930
|
app.use("/admin/*", async (c, next) => {
|
|
920
931
|
const token = getCookie(c, SESSION_COOKIE);
|
|
921
932
|
const user = token ? await getSessionUser(token, sessionSecret) : null;
|
|
922
|
-
|
|
933
|
+
let show = user?.isAdmin === true;
|
|
934
|
+
if (user && !show && accountServices) {
|
|
935
|
+
try {
|
|
936
|
+
show =
|
|
937
|
+
(await accountServices.accounts.getByMemberEmail(user.email)) !==
|
|
938
|
+
null;
|
|
939
|
+
} catch {
|
|
940
|
+
// nav is cosmetic — never fail the page over the lookup
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
return runWithSettingsNav(show, () => next());
|
|
923
944
|
});
|
|
924
945
|
}
|
|
925
946
|
|
|
@@ -3714,9 +3735,32 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
3714
3735
|
|
|
3715
3736
|
// ─── Enterprise GitHub apps settings (GHE-1.4) ───────────────────────────
|
|
3716
3737
|
|
|
3738
|
+
const settingsNav = buildSettingsNav({
|
|
3739
|
+
githubEnterprise: Boolean(githubEnterpriseApi),
|
|
3740
|
+
templates: Boolean(templateService),
|
|
3741
|
+
extraItems: deps.settingsNavItems ?? [],
|
|
3742
|
+
});
|
|
3743
|
+
|
|
3744
|
+
// SGL-2.2: /admin/settings lands on the first nav item the viewer can see.
|
|
3745
|
+
if (githubEnterpriseApi || templateService) {
|
|
3746
|
+
app.get("/admin/settings", requireAuth, (c) => {
|
|
3747
|
+
const first = firstVisibleSettingsItem(
|
|
3748
|
+
settingsNav,
|
|
3749
|
+
c.var.isAdmin === true,
|
|
3750
|
+
);
|
|
3751
|
+
if (!first) {
|
|
3752
|
+
return new Response("No settings are available for your account.", {
|
|
3753
|
+
status: 404,
|
|
3754
|
+
});
|
|
3755
|
+
}
|
|
3756
|
+
return c.redirect(first.path, 302);
|
|
3757
|
+
});
|
|
3758
|
+
}
|
|
3759
|
+
|
|
3717
3760
|
if (githubEnterpriseApi) {
|
|
3718
3761
|
registerAdminGithubEnterpriseRoutes(app, {
|
|
3719
3762
|
requireAuth,
|
|
3763
|
+
settingsNav,
|
|
3720
3764
|
api: githubEnterpriseApi,
|
|
3721
3765
|
html,
|
|
3722
3766
|
});
|
|
@@ -3728,6 +3772,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
3728
3772
|
registerAdminTemplatesRoutes(app, {
|
|
3729
3773
|
requireAuth,
|
|
3730
3774
|
templateService,
|
|
3775
|
+
settingsNav,
|
|
3731
3776
|
callerScopeResolver,
|
|
3732
3777
|
...(accountServices ? { accounts: accountServices.accounts } : {}),
|
|
3733
3778
|
specialtyRegistry,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import * as server from "./server.ts";
|
|
3
|
+
|
|
4
|
+
describe("server.ts export surface", () => {
|
|
5
|
+
it("exports the settings layout helpers", () => {
|
|
6
|
+
expect(typeof server.renderSettingsLayout).toBe("function");
|
|
7
|
+
expect(typeof server.mergeSettingsNavItems).toBe("function");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("keeps existing exports", () => {
|
|
11
|
+
expect(typeof server.createAdminUIApp).toBe("function");
|
|
12
|
+
expect(typeof server.createAdminApp).toBe("function");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("type exports compile", () => {
|
|
16
|
+
const item: server.SettingsNavItem = { label: "l", path: "/l" };
|
|
17
|
+
const section: server.SettingsNavSection = { label: "s", items: [item] };
|
|
18
|
+
const nav: server.SettingsNav = { sections: [section] };
|
|
19
|
+
const c: server.SettingsNavContribution = {
|
|
20
|
+
section: "s",
|
|
21
|
+
label: "l",
|
|
22
|
+
path: "/l",
|
|
23
|
+
};
|
|
24
|
+
const ext: server.AdminExtension = { settingsNavItems: () => [c] };
|
|
25
|
+
const opts: server.RenderSettingsLayoutOptions = {
|
|
26
|
+
userName: "u",
|
|
27
|
+
title: "t",
|
|
28
|
+
nav,
|
|
29
|
+
active: "/l",
|
|
30
|
+
body: "",
|
|
31
|
+
};
|
|
32
|
+
expect(server.renderSettingsLayout(opts)).toContain("l");
|
|
33
|
+
expect(ext.settingsNavItems).toBeDefined();
|
|
34
|
+
});
|
|
35
|
+
});
|
package/src/server.ts
CHANGED
|
@@ -48,3 +48,18 @@ export { HttpGoogleAuthClient } from "./google-auth-client.ts";
|
|
|
48
48
|
export type { GoogleAuthClient } from "./google-auth-client.ts";
|
|
49
49
|
export { PrismaClient } from "../prisma/client/client.ts";
|
|
50
50
|
export { createAdminPrismaClient } from "./prisma-client.ts";
|
|
51
|
+
export {
|
|
52
|
+
renderSettingsLayout,
|
|
53
|
+
mergeSettingsNavItems,
|
|
54
|
+
} from "./admin-ui-settings-layout.ts";
|
|
55
|
+
export type {
|
|
56
|
+
SettingsNav,
|
|
57
|
+
SettingsNavItem,
|
|
58
|
+
SettingsNavSection,
|
|
59
|
+
RenderSettingsLayoutOptions,
|
|
60
|
+
} from "./admin-ui-settings-layout.ts";
|
|
61
|
+
export type {
|
|
62
|
+
AdminExtension,
|
|
63
|
+
AdminExtensionContext,
|
|
64
|
+
SettingsNavContribution,
|
|
65
|
+
} from "./admin-extension.ts";
|