@app-vitals/agent-admin 1.67.0 → 1.69.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-ui-account-nav.ts +25 -13
- package/src/admin-ui-account-nav.unit.test.ts +55 -12
- package/src/admin-ui-agent-template.smoke.test.ts +93 -0
- package/src/admin-ui-github-enterprise-pages.unit.test.ts +4 -2
- package/src/admin-ui-pages.ts +25 -10
- package/src/admin-ui-styles.ts +4 -2
- package/src/admin-ui-templates-pages.unit.test.ts +30 -0
- package/src/admin-ui-templates.smoke.test.ts +81 -0
- package/src/admin-ui.ts +9 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-admin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.69.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.137.0",
|
|
45
|
-
"@app-vitals/agent-lib": "1.
|
|
45
|
+
"@app-vitals/agent-lib": "1.69.0",
|
|
46
46
|
"@hono/zod-openapi": "^1.0.0",
|
|
47
47
|
"@prisma/adapter-pg": "^7.10.0",
|
|
48
48
|
"@prisma/client": "^7.10.0",
|
|
@@ -1,26 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* admin/src/admin-ui-account-nav.ts
|
|
3
|
-
* Per-request
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
3
|
+
* Per-request toolbar audience. renderAdminToolbar() is called from dozens of
|
|
4
|
+
* page renderers; rather than thread a parameter through all of them, an
|
|
5
|
+
* admin-ui middleware wraps each /admin/* request in runWithToolbarAudience()
|
|
6
|
+
* and the toolbar reads it back. Outside any context (tests, other services)
|
|
7
|
+
* no audience is set and the toolbar renders its legacy default (no Settings).
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
11
|
+
import type { ToolbarAudience } from "@app-vitals/agent-lib/web/toolbar.ts";
|
|
11
12
|
|
|
12
|
-
interface
|
|
13
|
-
|
|
13
|
+
export interface ToolbarViewer {
|
|
14
|
+
audience: ToolbarAudience;
|
|
15
|
+
/**
|
|
16
|
+
* Show Settings even though the audience's manifest hides it. Account members
|
|
17
|
+
* (SGL-2.2) keep their Settings entry; the manifest lists it admin-only.
|
|
18
|
+
*/
|
|
14
19
|
showSettings: boolean;
|
|
15
20
|
}
|
|
16
21
|
|
|
17
|
-
const storage = new AsyncLocalStorage<
|
|
22
|
+
const storage = new AsyncLocalStorage<ToolbarViewer>();
|
|
18
23
|
|
|
19
|
-
/** Wrap a request so the toolbar
|
|
20
|
-
export function
|
|
21
|
-
|
|
24
|
+
/** Wrap a request so the toolbar renders for the given audience. */
|
|
25
|
+
export function runWithToolbarAudience<T>(
|
|
26
|
+
audience: ToolbarAudience,
|
|
27
|
+
fn: () => T,
|
|
28
|
+
opts: { showSettings?: boolean } = {},
|
|
29
|
+
): T {
|
|
30
|
+
return storage.run(
|
|
31
|
+
{ audience, showSettings: audience === "admin" || !!opts.showSettings },
|
|
32
|
+
fn,
|
|
33
|
+
);
|
|
22
34
|
}
|
|
23
35
|
|
|
24
|
-
export function
|
|
25
|
-
return storage.getStore()
|
|
36
|
+
export function currentToolbarViewer(): ToolbarViewer | undefined {
|
|
37
|
+
return storage.getStore();
|
|
26
38
|
}
|
|
@@ -1,24 +1,67 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* admin/src/admin-ui-account-nav.unit.test.ts
|
|
3
|
-
*
|
|
3
|
+
* Audience plumbing for the admin toolbar.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { describe, expect, test } from "bun:test";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
currentToolbarViewer,
|
|
9
|
+
runWithToolbarAudience,
|
|
10
10
|
} from "./admin-ui-account-nav.ts";
|
|
11
|
+
import { renderAdminToolbar } from "./admin-ui-styles.ts";
|
|
11
12
|
|
|
12
|
-
describe("
|
|
13
|
-
test("
|
|
14
|
-
expect(
|
|
15
|
-
});
|
|
16
|
-
test("
|
|
17
|
-
|
|
18
|
-
expect(
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
describe("toolbar audience context", () => {
|
|
14
|
+
test("no viewer outside any context", () => {
|
|
15
|
+
expect(currentToolbarViewer()).toBeUndefined();
|
|
16
|
+
});
|
|
17
|
+
test("admin audience implies Settings; nested contexts override", () => {
|
|
18
|
+
runWithToolbarAudience("admin", () => {
|
|
19
|
+
expect(currentToolbarViewer()).toEqual({
|
|
20
|
+
audience: "admin",
|
|
21
|
+
showSettings: true,
|
|
22
|
+
});
|
|
23
|
+
runWithToolbarAudience("member", () => {
|
|
24
|
+
expect(currentToolbarViewer()?.audience).toBe("member");
|
|
25
|
+
expect(currentToolbarViewer()?.showSettings).toBe(false);
|
|
21
26
|
});
|
|
22
27
|
});
|
|
23
28
|
});
|
|
29
|
+
test("member keeps Settings only with the account opt-in", () => {
|
|
30
|
+
runWithToolbarAudience("member", () => {
|
|
31
|
+
expect(currentToolbarViewer()?.showSettings).toBe(true);
|
|
32
|
+
}, { showSettings: true });
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("renderAdminToolbar audience mapping", () => {
|
|
37
|
+
const settings = 'href="/admin/settings"';
|
|
38
|
+
test("outside a context: legacy output, no Settings", () => {
|
|
39
|
+
const html = renderAdminToolbar("a@x.com");
|
|
40
|
+
expect(html).not.toContain(settings);
|
|
41
|
+
expect(html).toContain("Agents");
|
|
42
|
+
});
|
|
43
|
+
test("admin sees Settings", () => {
|
|
44
|
+
expect(
|
|
45
|
+
runWithToolbarAudience("admin", () => renderAdminToolbar("a@x.com")),
|
|
46
|
+
).toContain(settings);
|
|
47
|
+
});
|
|
48
|
+
test("plain member does not see Settings but sees the other items", () => {
|
|
49
|
+
const html = runWithToolbarAudience("member", () =>
|
|
50
|
+
renderAdminToolbar("a@x.com"),
|
|
51
|
+
);
|
|
52
|
+
expect(html).not.toContain(settings);
|
|
53
|
+
expect(html).toContain("/admin/sessions");
|
|
54
|
+
});
|
|
55
|
+
test("account member keeps Settings (SGL-2.2)", () => {
|
|
56
|
+
const html = runWithToolbarAudience(
|
|
57
|
+
"member",
|
|
58
|
+
() => renderAdminToolbar("a@x.com"),
|
|
59
|
+
{ showSettings: true },
|
|
60
|
+
);
|
|
61
|
+
expect(html).toContain(settings);
|
|
62
|
+
});
|
|
63
|
+
test("audience output matches legacy flag output", () => {
|
|
64
|
+
const base = runWithToolbarAudience("admin", () => renderAdminToolbar("a"));
|
|
65
|
+
expect(base).toContain("Queue & Activity");
|
|
66
|
+
});
|
|
24
67
|
});
|
|
@@ -419,3 +419,96 @@ describe("provisioning form (ATP-2.4)", () => {
|
|
|
419
419
|
expect(patched.some((e) => e.EXTRA === "two words")).toBe(true);
|
|
420
420
|
});
|
|
421
421
|
});
|
|
422
|
+
|
|
423
|
+
describe("agent Marketplaces card (TMK-3.1)", () => {
|
|
424
|
+
const row = (over: Record<string, unknown>) => ({
|
|
425
|
+
id: "m-x",
|
|
426
|
+
agentId: AGENT_ID,
|
|
427
|
+
name: "x",
|
|
428
|
+
source: "acme/x",
|
|
429
|
+
ref: null,
|
|
430
|
+
rowSource: "custom",
|
|
431
|
+
enabled: true,
|
|
432
|
+
createdAt: d,
|
|
433
|
+
updatedAt: d,
|
|
434
|
+
...over,
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
function marketplaceApp() {
|
|
438
|
+
const deps = detailDeps({ agentsApi: fakeAgentsApi().api });
|
|
439
|
+
const agentDetail = deps.agentService.getDetail;
|
|
440
|
+
return createAdminUIApp({
|
|
441
|
+
...deps,
|
|
442
|
+
agentService: {
|
|
443
|
+
...deps.agentService,
|
|
444
|
+
getDetail: async (id: string) => ({
|
|
445
|
+
...(await agentDetail(id)),
|
|
446
|
+
bakedMarketplaces: ["baked-mp"],
|
|
447
|
+
}),
|
|
448
|
+
},
|
|
449
|
+
agentMarketplaceService: {
|
|
450
|
+
list: async () => [
|
|
451
|
+
row({ id: "m-tpl", name: "tpl-mp", rowSource: "template" }),
|
|
452
|
+
row({ id: "m-own", name: "own-mp", rowSource: "custom" }),
|
|
453
|
+
row({
|
|
454
|
+
id: "m-dead",
|
|
455
|
+
name: "dead-mp",
|
|
456
|
+
rowSource: "template",
|
|
457
|
+
enabled: false,
|
|
458
|
+
}),
|
|
459
|
+
],
|
|
460
|
+
upsert: async () => row({}),
|
|
461
|
+
remove: async () => undefined,
|
|
462
|
+
},
|
|
463
|
+
} as never);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
async function card(): Promise<string> {
|
|
467
|
+
const html = await (
|
|
468
|
+
await get(marketplaceApp(), `/admin/agents/${AGENT_ID}/extensions`)
|
|
469
|
+
).text();
|
|
470
|
+
const start = html.indexOf('id="marketplaces-table"');
|
|
471
|
+
return html.slice(start, html.indexOf("</table>", start));
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const rowHtml = (html: string, name: string) =>
|
|
475
|
+
html
|
|
476
|
+
.slice(html.lastIndexOf("<tr", html.indexOf(`>${name}`)))
|
|
477
|
+
.split("</tr>")[0] ?? "";
|
|
478
|
+
|
|
479
|
+
it("badges template and custom rows", async () => {
|
|
480
|
+
const html = await card();
|
|
481
|
+
expect(rowHtml(html, "tpl-mp")).toContain('data-source="template"');
|
|
482
|
+
expect(rowHtml(html, "own-mp")).toContain('data-source="custom"');
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
it("marks tombstoned rows disabled", async () => {
|
|
486
|
+
const html = await card();
|
|
487
|
+
const dead = rowHtml(html, "dead-mp");
|
|
488
|
+
expect(dead).toContain('data-disabled="true"');
|
|
489
|
+
expect(dead).toContain(">disabled</span>");
|
|
490
|
+
expect(dead).not.toContain("marketplaces/delete");
|
|
491
|
+
const live = rowHtml(html, "tpl-mp");
|
|
492
|
+
expect(live).not.toContain("data-disabled");
|
|
493
|
+
expect(live).toContain("marketplaces/delete");
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it("still renders baked rows as from image", async () => {
|
|
497
|
+
const html = await card();
|
|
498
|
+
expect(html).toContain('data-baked-marketplace="baked-mp"');
|
|
499
|
+
expect(html).toContain("from image");
|
|
500
|
+
expect(rowHtml(html, "baked-mp")).not.toContain("data-source=");
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
it("suggests template-sourced marketplace names for the plugin field, not tombstones", async () => {
|
|
504
|
+
const html = await (
|
|
505
|
+
await get(marketplaceApp(), `/admin/agents/${AGENT_ID}/extensions`)
|
|
506
|
+
).text();
|
|
507
|
+
const list = html.slice(html.indexOf('id="plugin-marketplaces"'));
|
|
508
|
+
const datalist = list.slice(0, list.indexOf("</datalist>"));
|
|
509
|
+
expect(datalist).toContain('value="tpl-mp"');
|
|
510
|
+
expect(datalist).toContain('value="own-mp"');
|
|
511
|
+
expect(datalist).toContain('value="baked-mp"');
|
|
512
|
+
expect(datalist).not.toContain("dead-mp");
|
|
513
|
+
});
|
|
514
|
+
});
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { describe, expect, test } from "bun:test";
|
|
8
|
-
import {
|
|
8
|
+
import { runWithToolbarAudience } from "./admin-ui-account-nav.ts";
|
|
9
9
|
import {
|
|
10
10
|
type GheApp,
|
|
11
11
|
renderGithubEnterpriseSettingsPage,
|
|
@@ -236,7 +236,9 @@ describe("renderGithubEnterpriseSettingsPage", () => {
|
|
|
236
236
|
describe("toolbar Settings entry", () => {
|
|
237
237
|
test("hidden outside a settings-nav context, shown inside one", () => {
|
|
238
238
|
expect(renderAdminToolbar("a@x.com")).not.toContain("/admin/settings");
|
|
239
|
-
const html =
|
|
239
|
+
const html = runWithToolbarAudience("admin", () =>
|
|
240
|
+
renderAdminToolbar("a@x.com"),
|
|
241
|
+
);
|
|
240
242
|
expect(html).toContain('href="/admin/settings" class="vos-nav-link');
|
|
241
243
|
});
|
|
242
244
|
});
|
package/src/admin-ui-pages.ts
CHANGED
|
@@ -212,6 +212,10 @@ export interface MarketplaceItem {
|
|
|
212
212
|
name: string;
|
|
213
213
|
source: string;
|
|
214
214
|
ref: string | null;
|
|
215
|
+
/** TMK-3.1: `template` or `custom` (AgentMarketplace.rowSource). */
|
|
216
|
+
rowSource?: string;
|
|
217
|
+
/** TMK-3.1: false = tombstone of a deleted template row. */
|
|
218
|
+
enabled?: boolean;
|
|
215
219
|
createdAt: Date;
|
|
216
220
|
}
|
|
217
221
|
|
|
@@ -1544,20 +1548,28 @@ export function renderAgentDetailPage(
|
|
|
1544
1548
|
const marketplaces = opts?.marketplaces ?? [];
|
|
1545
1549
|
const bakedMarketplaces = agent.bakedMarketplaces ?? [];
|
|
1546
1550
|
const marketplaceRows = marketplaces
|
|
1547
|
-
.map(
|
|
1548
|
-
|
|
1549
|
-
|
|
1551
|
+
.map((m) => {
|
|
1552
|
+
const tombstone = m.enabled === false;
|
|
1553
|
+
return `<tr${tombstone ? ' data-disabled="true" style="opacity:.6"' : ""}>
|
|
1554
|
+
<td class="mono">${escapeHtml(m.name)}${sourceBadge(m.rowSource)}</td>
|
|
1550
1555
|
<td class="mono">${escapeHtml(m.source)}</td>
|
|
1551
1556
|
<td class="mono">${m.ref ? escapeHtml(m.ref) : "default"}</td>
|
|
1552
|
-
<td
|
|
1553
|
-
|
|
1557
|
+
<td>${
|
|
1558
|
+
tombstone
|
|
1559
|
+
? `<span class="badge badge-gray" title="Removed from this agent; the template no longer re-adds it">disabled</span>`
|
|
1560
|
+
: `<span class="badge badge-green">remote</span>`
|
|
1561
|
+
}</td>
|
|
1562
|
+
<td>${
|
|
1563
|
+
tombstone
|
|
1564
|
+
? ""
|
|
1565
|
+
: `
|
|
1554
1566
|
<form method="POST" action="/admin/agents/${escapeHtml(agent.id)}/marketplaces/delete" style="display:inline">
|
|
1555
1567
|
<input type="hidden" name="marketplaceId" value="${escapeHtml(m.id)}" />
|
|
1556
1568
|
<button type="submit" class="btn btn-danger" style="font-size:11px;padding:3px 8px">Remove</button>
|
|
1557
|
-
</form
|
|
1558
|
-
</td>
|
|
1559
|
-
</tr
|
|
1560
|
-
)
|
|
1569
|
+
</form>`
|
|
1570
|
+
}</td>
|
|
1571
|
+
</tr>`;
|
|
1572
|
+
})
|
|
1561
1573
|
.join("\n");
|
|
1562
1574
|
const bakedMarketplaceRows = bakedMarketplaces
|
|
1563
1575
|
.map(
|
|
@@ -2009,7 +2021,10 @@ export function renderAgentDetailPage(
|
|
|
2009
2021
|
</div>`;
|
|
2010
2022
|
|
|
2011
2023
|
const pluginMarketplaceNames = [
|
|
2012
|
-
...new Set([
|
|
2024
|
+
...new Set([
|
|
2025
|
+
...marketplaces.filter((m) => m.enabled !== false).map((m) => m.name),
|
|
2026
|
+
...bakedMarketplaces,
|
|
2027
|
+
]),
|
|
2013
2028
|
];
|
|
2014
2029
|
const pluginsSection = `<div class="card">
|
|
2015
2030
|
<div class="card-title">Plugins</div>
|
package/src/admin-ui-styles.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
renderShipwrightToolbar,
|
|
4
4
|
baseStyles as toolbarBaseStyles,
|
|
5
5
|
} from "@app-vitals/agent-lib/web/toolbar.ts";
|
|
6
|
-
import {
|
|
6
|
+
import { currentToolbarViewer } from "./admin-ui-account-nav.ts";
|
|
7
7
|
|
|
8
8
|
export { escapeHtml };
|
|
9
9
|
|
|
@@ -684,11 +684,13 @@ export function baseStyles(): string {
|
|
|
684
684
|
}
|
|
685
685
|
|
|
686
686
|
export function renderAdminToolbar(userName: string, activePath = ""): string {
|
|
687
|
+
const viewer = currentToolbarViewer();
|
|
687
688
|
return renderShipwrightToolbar({
|
|
688
689
|
userName,
|
|
689
690
|
activePath,
|
|
690
691
|
logoutAction: "/admin/logout",
|
|
691
692
|
metricsUrl: process.env.METRICS_DASHBOARD_URL ?? "/dashboard",
|
|
692
|
-
|
|
693
|
+
audience: viewer?.audience,
|
|
694
|
+
showSettings: viewer?.showSettings,
|
|
693
695
|
});
|
|
694
696
|
}
|
|
@@ -83,3 +83,33 @@ describe("renderTemplatesPage settings shell (SGL-2.2)", () => {
|
|
|
83
83
|
);
|
|
84
84
|
});
|
|
85
85
|
});
|
|
86
|
+
|
|
87
|
+
describe("renderTemplatesPage marketplace kind (TMK-3.1)", () => {
|
|
88
|
+
const html = renderTemplatesPage({
|
|
89
|
+
...base,
|
|
90
|
+
templateExists: true,
|
|
91
|
+
items: [
|
|
92
|
+
{
|
|
93
|
+
kind: "marketplace",
|
|
94
|
+
key: "acme-plugins",
|
|
95
|
+
payload: { source: "acme/<plugins>", ref: "v1" },
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("renders a Marketplaces card with an add form for name, source and ref", () => {
|
|
101
|
+
expect(html).toContain('id="template-marketplace"');
|
|
102
|
+
expect(html).toContain("Add marketplace");
|
|
103
|
+
expect(html).toContain('name="source"');
|
|
104
|
+
expect(html).toContain('name="ref"');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("lists an existing item with escaped values and a remove button", () => {
|
|
108
|
+
expect(html).toContain('data-kind="marketplace" data-key="acme-plugins"');
|
|
109
|
+
expect(html).toContain('value="acme/<plugins>"');
|
|
110
|
+
expect(html).toContain('value="v1"');
|
|
111
|
+
expect(html).toContain(
|
|
112
|
+
'formaction="/admin/settings/templates/items/delete"',
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -328,3 +328,84 @@ describe("/admin/settings/templates smoke", () => {
|
|
|
328
328
|
).toBe(403);
|
|
329
329
|
});
|
|
330
330
|
});
|
|
331
|
+
|
|
332
|
+
describe("/admin/settings/templates marketplace items (TMK-3.1)", () => {
|
|
333
|
+
const scope = { accountId: "", specialty: "" };
|
|
334
|
+
|
|
335
|
+
it("creates a marketplace item with name, source and ref and lists it", async () => {
|
|
336
|
+
const { app, rows } = setup();
|
|
337
|
+
const res = await app.request(
|
|
338
|
+
`${BASE}/items`,
|
|
339
|
+
form({
|
|
340
|
+
...scope,
|
|
341
|
+
kind: "marketplace",
|
|
342
|
+
key: "acme-plugins",
|
|
343
|
+
source: "acme/plugins",
|
|
344
|
+
ref: "v1",
|
|
345
|
+
}),
|
|
346
|
+
);
|
|
347
|
+
expect(res.status).toBe(302);
|
|
348
|
+
expect(rows[0]?.items[0]).toMatchObject({
|
|
349
|
+
kind: "marketplace",
|
|
350
|
+
key: "acme-plugins",
|
|
351
|
+
payload: { source: "acme/plugins", ref: "v1" },
|
|
352
|
+
});
|
|
353
|
+
const html = await (await app.request(BASE)).text();
|
|
354
|
+
expect(html).toContain('data-kind="marketplace" data-key="acme-plugins"');
|
|
355
|
+
expect(html).toContain('value="acme/plugins"');
|
|
356
|
+
expect(html).toContain('value="v1"');
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("stores an empty ref as null", async () => {
|
|
360
|
+
const { app, rows } = setup();
|
|
361
|
+
await app.request(
|
|
362
|
+
`${BASE}/items`,
|
|
363
|
+
form({
|
|
364
|
+
...scope,
|
|
365
|
+
kind: "marketplace",
|
|
366
|
+
key: "m",
|
|
367
|
+
source: "acme/plugins",
|
|
368
|
+
ref: "",
|
|
369
|
+
}),
|
|
370
|
+
);
|
|
371
|
+
expect(rows[0]?.items[0]?.payload).toMatchObject({ ref: null });
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it("shows an invalid source as an inline 422 and creates nothing", async () => {
|
|
375
|
+
const { app, rows } = setup();
|
|
376
|
+
const res = await app.request(
|
|
377
|
+
`${BASE}/items`,
|
|
378
|
+
form({
|
|
379
|
+
...scope,
|
|
380
|
+
kind: "marketplace",
|
|
381
|
+
key: "m",
|
|
382
|
+
source: "/etc/passwd",
|
|
383
|
+
ref: "",
|
|
384
|
+
}),
|
|
385
|
+
);
|
|
386
|
+
expect(res.status).toBe(422);
|
|
387
|
+
const html = await res.text();
|
|
388
|
+
expect(html).toContain("alert-error");
|
|
389
|
+
expect(html).toContain("source must be a GitHub");
|
|
390
|
+
expect(rows).toHaveLength(0);
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
it("removes a marketplace item", async () => {
|
|
394
|
+
const { app, rows } = setup();
|
|
395
|
+
await app.request(
|
|
396
|
+
`${BASE}/items`,
|
|
397
|
+
form({
|
|
398
|
+
...scope,
|
|
399
|
+
kind: "marketplace",
|
|
400
|
+
key: "m",
|
|
401
|
+
source: "acme/plugins",
|
|
402
|
+
}),
|
|
403
|
+
);
|
|
404
|
+
const res = await app.request(
|
|
405
|
+
`${BASE}/items/delete`,
|
|
406
|
+
form({ ...scope, kind: "marketplace", key: "m" }),
|
|
407
|
+
);
|
|
408
|
+
expect(res.status).toBe(302);
|
|
409
|
+
expect(rows[0]?.items).toHaveLength(0);
|
|
410
|
+
});
|
|
411
|
+
});
|
package/src/admin-ui.ts
CHANGED
|
@@ -46,7 +46,7 @@ import {
|
|
|
46
46
|
type SettingsNavContribution,
|
|
47
47
|
} from "./admin-extension.ts";
|
|
48
48
|
import { registerAccountRoutes } from "./admin-ui-account.ts";
|
|
49
|
-
import {
|
|
49
|
+
import { runWithToolbarAudience } from "./admin-ui-account-nav.ts";
|
|
50
50
|
import { renderZeroQuotaNotice } from "./admin-ui-account-pages.ts";
|
|
51
51
|
import { registerAdminAccountsRoutes } from "./admin-ui-accounts.ts";
|
|
52
52
|
import { registerAdminGithubEnterpriseRoutes } from "./admin-ui-github-enterprise.ts";
|
|
@@ -1021,8 +1021,9 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1021
1021
|
app.use("/admin/*", async (c, next) => {
|
|
1022
1022
|
const token = getCookie(c, SESSION_COOKIE);
|
|
1023
1023
|
const user = token ? await getSessionUser(token, sessionSecret) : null;
|
|
1024
|
-
|
|
1025
|
-
|
|
1024
|
+
const isAdmin = user?.isAdmin === true;
|
|
1025
|
+
let show = false; // member with an account keeps Settings (SGL-2.2)
|
|
1026
|
+
if (user && !isAdmin && accountServices) {
|
|
1026
1027
|
try {
|
|
1027
1028
|
show =
|
|
1028
1029
|
(await accountServices.accounts.getByMemberEmail(user.email)) !==
|
|
@@ -1031,7 +1032,11 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1031
1032
|
// nav is cosmetic — never fail the page over the lookup
|
|
1032
1033
|
}
|
|
1033
1034
|
}
|
|
1034
|
-
return
|
|
1035
|
+
return runWithToolbarAudience(
|
|
1036
|
+
isAdmin ? "admin" : "member",
|
|
1037
|
+
() => next(),
|
|
1038
|
+
{ showSettings: show },
|
|
1039
|
+
);
|
|
1035
1040
|
});
|
|
1036
1041
|
}
|
|
1037
1042
|
|