@app-vitals/agent-admin 1.50.0 → 1.51.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 +3 -14
- package/src/admin-ui-account-nav.unit.test.ts +5 -14
- package/src/admin-ui-account-pages.ts +21 -10
- package/src/admin-ui-account-pages.unit.test.ts +12 -12
- package/src/admin-ui-account.smoke.test.ts +4 -0
- package/src/admin-ui-account.ts +5 -0
- package/src/admin-ui-accounts-pages.ts +36 -16
- package/src/admin-ui-accounts-pages.unit.test.ts +29 -0
- package/src/admin-ui-accounts.smoke.test.ts +2 -0
- package/src/admin-ui-accounts.ts +10 -1
- package/src/admin-ui-settings-layout.ts +24 -6
- package/src/admin-ui-settings.smoke.test.ts +28 -0
- package/src/admin-ui-styles.ts +1 -5
- package/src/admin-ui.ts +27 -35
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-admin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.51.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.51.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,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* admin/src/admin-ui-account-nav.ts
|
|
3
|
-
* Per-request "show the
|
|
3
|
+
* Per-request "show the Settings nav entry" flag. renderAdminToolbar()
|
|
4
4
|
* is called from dozens of page renderers; rather than thread a parameter
|
|
5
5
|
* through all of them, an admin-ui middleware wraps each /admin/* request in
|
|
6
6
|
* runWithAccountNav() and the toolbar reads the flag back. Outside any
|
|
@@ -10,26 +10,15 @@
|
|
|
10
10
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
11
11
|
|
|
12
12
|
interface NavFlags {
|
|
13
|
-
|
|
14
|
-
/** GHE-1.4: the admin-only "Settings" entry. */
|
|
13
|
+
/** The "Settings" entry (admins and account members). */
|
|
15
14
|
showSettings: boolean;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
const storage = new AsyncLocalStorage<NavFlags>();
|
|
19
18
|
|
|
20
|
-
export function runWithAccountNav<T>(showAccount: boolean, fn: () => T): T {
|
|
21
|
-
const showSettings = storage.getStore()?.showSettings === true;
|
|
22
|
-
return storage.run({ showAccount, showSettings }, fn);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function shouldShowAccountNav(): boolean {
|
|
26
|
-
return storage.getStore()?.showAccount === true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
19
|
/** Wrap a request so the toolbar shows (or hides) the admin Settings entry. */
|
|
30
20
|
export function runWithSettingsNav<T>(showSettings: boolean, fn: () => T): T {
|
|
31
|
-
|
|
32
|
-
return storage.run({ showAccount, showSettings }, fn);
|
|
21
|
+
return storage.run({ showSettings }, fn);
|
|
33
22
|
}
|
|
34
23
|
|
|
35
24
|
export function shouldShowSettingsNav(): boolean {
|
|
@@ -1,31 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* admin/src/admin-ui-account-nav.unit.test.ts
|
|
3
|
-
* Flag plumbing for the toolbar
|
|
3
|
+
* Flag plumbing for the toolbar Settings entry.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { describe, expect, test } from "bun:test";
|
|
7
7
|
import {
|
|
8
|
-
runWithAccountNav,
|
|
9
8
|
runWithSettingsNav,
|
|
10
|
-
shouldShowAccountNav,
|
|
11
9
|
shouldShowSettingsNav,
|
|
12
10
|
} from "./admin-ui-account-nav.ts";
|
|
13
11
|
|
|
14
|
-
describe("
|
|
15
|
-
test("
|
|
16
|
-
expect(shouldShowAccountNav()).toBe(false);
|
|
12
|
+
describe("settings-nav flag", () => {
|
|
13
|
+
test("hidden outside any context", () => {
|
|
17
14
|
expect(shouldShowSettingsNav()).toBe(false);
|
|
18
15
|
});
|
|
19
|
-
test("
|
|
16
|
+
test("reflects the wrapper value, including nested", () => {
|
|
20
17
|
runWithSettingsNav(true, () => {
|
|
21
|
-
|
|
22
|
-
expect(shouldShowSettingsNav()).toBe(true);
|
|
23
|
-
expect(shouldShowAccountNav()).toBe(false);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
runWithAccountNav(true, () => {
|
|
18
|
+
expect(shouldShowSettingsNav()).toBe(true);
|
|
27
19
|
runWithSettingsNav(false, () => {
|
|
28
|
-
expect(shouldShowAccountNav()).toBe(true);
|
|
29
20
|
expect(shouldShowSettingsNav()).toBe(false);
|
|
30
21
|
});
|
|
31
22
|
});
|
|
@@ -8,7 +8,12 @@ import type { AccountInvite } from "./account-invites.ts";
|
|
|
8
8
|
import type { AccountMember } from "./account-members.ts";
|
|
9
9
|
import type { Account } from "./accounts.ts";
|
|
10
10
|
import { renderAdminPage } from "./admin-ui-layout.ts";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
buildSettingsNav,
|
|
13
|
+
renderSettingsLayout,
|
|
14
|
+
type SettingsNav,
|
|
15
|
+
} from "./admin-ui-settings-layout.ts";
|
|
16
|
+
import { escapeHtml } from "./admin-ui-styles.ts";
|
|
12
17
|
|
|
13
18
|
export const ACCOUNT_PATH = "/admin/account";
|
|
14
19
|
|
|
@@ -21,6 +26,10 @@ interface AccountPageOpts {
|
|
|
21
26
|
/** True when the viewer is an owner; members get a read-only page. */
|
|
22
27
|
isOwner: boolean;
|
|
23
28
|
error?: string;
|
|
29
|
+
/** Settings sidebar nav; defaults to the base Account/Accounts nav. */
|
|
30
|
+
nav?: SettingsNav;
|
|
31
|
+
/** Platform admin viewing (shows adminOnly nav items). */
|
|
32
|
+
isAdmin?: boolean;
|
|
24
33
|
}
|
|
25
34
|
|
|
26
35
|
function emailForm(
|
|
@@ -88,13 +97,15 @@ export function renderAccountPage(opts: AccountPageOpts): string {
|
|
|
88
97
|
: "";
|
|
89
98
|
|
|
90
99
|
return renderAdminPage({
|
|
91
|
-
title: "Account — Shipwright Admin",
|
|
92
|
-
body:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
title: "Account — Settings — Shipwright Admin",
|
|
101
|
+
body: renderSettingsLayout({
|
|
102
|
+
userName: opts.userEmail,
|
|
103
|
+
title: account.name,
|
|
104
|
+
nav: opts.nav ?? buildSettingsNav({ accounts: true }),
|
|
105
|
+
active: ACCOUNT_PATH,
|
|
106
|
+
toolbarPath: "/admin/settings",
|
|
107
|
+
isAdmin: opts.isAdmin ?? false,
|
|
108
|
+
body: `${errorHtml}
|
|
98
109
|
<div class="card">
|
|
99
110
|
<div class="card-title">Account</div>
|
|
100
111
|
<p>Agents: <strong>${opts.agentCount} / ${account.maxAgents}</strong></p>
|
|
@@ -118,8 +129,8 @@ export function renderAccountPage(opts: AccountPageOpts): string {
|
|
|
118
129
|
</table>
|
|
119
130
|
</div>
|
|
120
131
|
${inviteForm}
|
|
121
|
-
</div
|
|
122
|
-
|
|
132
|
+
</div>`,
|
|
133
|
+
}),
|
|
123
134
|
});
|
|
124
135
|
}
|
|
125
136
|
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
renderZeroQuotaNotice,
|
|
10
10
|
} from "./admin-ui-account-pages.ts";
|
|
11
11
|
import { renderAdminToolbar } from "./admin-ui-styles.ts";
|
|
12
|
-
import { runWithAccountNav } from "./admin-ui-account-nav.ts";
|
|
13
12
|
|
|
14
13
|
const d = new Date("2026-01-01T00:00:00Z");
|
|
15
14
|
const account = {
|
|
@@ -92,21 +91,22 @@ describe("renderZeroQuotaNotice", () => {
|
|
|
92
91
|
});
|
|
93
92
|
|
|
94
93
|
describe("renderAdminToolbar account nav", () => {
|
|
95
|
-
test("no Account entry
|
|
94
|
+
test("no top-level Account entry (Settings covers it, SGL-2.3)", () => {
|
|
96
95
|
expect(renderAdminToolbar("u", "/admin/agents")).not.toContain(
|
|
97
|
-
"/admin/account",
|
|
96
|
+
'href="/admin/account"',
|
|
98
97
|
);
|
|
99
98
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("renderAccountPage in the settings shell", () => {
|
|
102
|
+
test("renders inside the layout with Account active and Settings in the toolbar", () => {
|
|
103
|
+
const html = render(true);
|
|
104
|
+
expect(html).toContain("settings-sidebar");
|
|
105
|
+
expect(html).toContain(
|
|
106
|
+
'<a class="settings-nav-link" href="/admin/account" aria-current="page">Account</a>',
|
|
103
107
|
);
|
|
104
|
-
expect(html).toContain('href="/admin/account"');
|
|
105
108
|
});
|
|
106
|
-
test("
|
|
107
|
-
|
|
108
|
-
renderAdminToolbar("u", "/admin/agents"),
|
|
109
|
-
);
|
|
110
|
-
expect(html).not.toContain("/admin/account");
|
|
109
|
+
test("Accounts nav item only for admins", () => {
|
|
110
|
+
expect(render(true)).not.toContain('href="/admin/accounts"');
|
|
111
111
|
});
|
|
112
112
|
});
|
|
@@ -178,6 +178,10 @@ describe("/admin/account", () => {
|
|
|
178
178
|
const body = await res.text();
|
|
179
179
|
expect(body).toContain("Acme");
|
|
180
180
|
expect(body).toContain("1 / 2");
|
|
181
|
+
// SGL-2.3: rendered inside the settings shell; no top-level Account link.
|
|
182
|
+
expect(body).toContain("settings-sidebar");
|
|
183
|
+
expect(body).toContain('href="/admin/account" aria-current="page"');
|
|
184
|
+
expect(body).not.toContain('class="vos-nav-link" href="/admin/account"');
|
|
181
185
|
});
|
|
182
186
|
|
|
183
187
|
it("owner can invite, see it pending, and revoke it", async () => {
|
package/src/admin-ui-account.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { normalizeEmail } from "./account-email.ts";
|
|
|
19
19
|
import type { Account, AccountService } from "./accounts.ts";
|
|
20
20
|
import { ACCOUNT_PATH, renderAccountPage } from "./admin-ui-account-pages.ts";
|
|
21
21
|
import type { AdminUIEnv } from "./admin-ui.ts";
|
|
22
|
+
import type { SettingsNav } from "./admin-ui-settings-layout.ts";
|
|
22
23
|
|
|
23
24
|
export interface AccountRouteDeps {
|
|
24
25
|
/** SHIPWRIGHT_SELF_SERVE_ENABLED === "enabled". */
|
|
@@ -30,6 +31,8 @@ export interface AccountRouteDeps {
|
|
|
30
31
|
"listByAccount" | "getByEmail" | "remove" | "promote" | "demote"
|
|
31
32
|
>;
|
|
32
33
|
invites: Pick<AccountInviteService, "create" | "listPending" | "revoke">;
|
|
34
|
+
/** Settings sidebar nav (SGL-2.3). */
|
|
35
|
+
settingsNav?: SettingsNav;
|
|
33
36
|
html: (content: string, opts?: { status?: number }) => Response;
|
|
34
37
|
}
|
|
35
38
|
|
|
@@ -71,6 +74,8 @@ export function registerAccountRoutes(
|
|
|
71
74
|
invites,
|
|
72
75
|
isOwner,
|
|
73
76
|
error,
|
|
77
|
+
isAdmin: c.var.isAdmin === true,
|
|
78
|
+
...(deps.settingsNav ? { nav: deps.settingsNav } : {}),
|
|
74
79
|
}),
|
|
75
80
|
{ status },
|
|
76
81
|
);
|
|
@@ -8,7 +8,12 @@ import type { AccountInvite } from "./account-invites.ts";
|
|
|
8
8
|
import type { AccountMember } from "./account-members.ts";
|
|
9
9
|
import type { AccountWithCounts } from "./accounts.ts";
|
|
10
10
|
import { renderAdminPage } from "./admin-ui-layout.ts";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
buildSettingsNav,
|
|
13
|
+
renderSettingsLayout,
|
|
14
|
+
type SettingsNav,
|
|
15
|
+
} from "./admin-ui-settings-layout.ts";
|
|
16
|
+
import { escapeHtml } from "./admin-ui-styles.ts";
|
|
12
17
|
|
|
13
18
|
export const ADMIN_ACCOUNTS_PATH = "/admin/accounts";
|
|
14
19
|
|
|
@@ -36,6 +41,8 @@ interface AccountsListPageOpts {
|
|
|
36
41
|
accounts: AccountWithCounts[];
|
|
37
42
|
/** accountId -> owner emails. */
|
|
38
43
|
owners: Map<string, string[]>;
|
|
44
|
+
/** Settings sidebar nav; defaults to the base Account/Accounts nav. */
|
|
45
|
+
nav?: SettingsNav;
|
|
39
46
|
}
|
|
40
47
|
|
|
41
48
|
export function renderAccountsListPage(opts: AccountsListPageOpts): string {
|
|
@@ -60,16 +67,20 @@ export function renderAccountsListPage(opts: AccountsListPageOpts): string {
|
|
|
60
67
|
|
|
61
68
|
return renderAdminPage({
|
|
62
69
|
title: "Accounts — Shipwright Admin",
|
|
63
|
-
body:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
body: renderSettingsLayout({
|
|
71
|
+
userName: opts.userEmail,
|
|
72
|
+
title: "Accounts",
|
|
73
|
+
nav: opts.nav ?? buildSettingsNav({ accounts: true }),
|
|
74
|
+
active: ADMIN_ACCOUNTS_PATH,
|
|
75
|
+
toolbarPath: "/admin/settings",
|
|
76
|
+
isAdmin: true,
|
|
77
|
+
body: `<div class="card">
|
|
67
78
|
<table class="data-table">
|
|
68
79
|
<thead><tr><th>Name</th><th>Owner</th><th>Members</th><th>Agents</th><th>Status</th><th>Trial expires</th><th>Created</th><th></th></tr></thead>
|
|
69
80
|
<tbody>${rows}</tbody>
|
|
70
81
|
</table>
|
|
71
|
-
</div
|
|
72
|
-
|
|
82
|
+
</div>`,
|
|
83
|
+
}),
|
|
73
84
|
});
|
|
74
85
|
}
|
|
75
86
|
|
|
@@ -80,6 +91,8 @@ interface AccountDetailPageOpts {
|
|
|
80
91
|
members: AccountMember[];
|
|
81
92
|
invites: AccountInvite[];
|
|
82
93
|
error?: string;
|
|
94
|
+
/** Settings sidebar nav; defaults to the base Account/Accounts nav. */
|
|
95
|
+
nav?: SettingsNav;
|
|
83
96
|
}
|
|
84
97
|
|
|
85
98
|
function postForm(
|
|
@@ -110,8 +123,12 @@ export function renderAccountDetailPage(opts: AccountDetailPageOpts): string {
|
|
|
110
123
|
|
|
111
124
|
const statusAction =
|
|
112
125
|
account.status === "active"
|
|
113
|
-
?
|
|
114
|
-
|
|
126
|
+
? `<div class="settings-danger-zone">
|
|
127
|
+
<div class="settings-section-title">Danger zone</div>
|
|
128
|
+
<p class="help-text">Suspending locks down this account's crons until it is reactivated.</p>
|
|
129
|
+
${postForm(id, "suspend", {}, "Suspend", true)}
|
|
130
|
+
</div>`
|
|
131
|
+
: `<div class="card">${postForm(id, "reactivate", {}, "Reactivate")}</div>`;
|
|
115
132
|
|
|
116
133
|
const memberRows = opts.members
|
|
117
134
|
.map(
|
|
@@ -150,12 +167,14 @@ export function renderAccountDetailPage(opts: AccountDetailPageOpts): string {
|
|
|
150
167
|
|
|
151
168
|
return renderAdminPage({
|
|
152
169
|
title: `${account.name} — Accounts — Shipwright Admin`,
|
|
153
|
-
body:
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
170
|
+
body: renderSettingsLayout({
|
|
171
|
+
userName: opts.userEmail,
|
|
172
|
+
title: account.name,
|
|
173
|
+
nav: opts.nav ?? buildSettingsNav({ accounts: true }),
|
|
174
|
+
active: ADMIN_ACCOUNTS_PATH,
|
|
175
|
+
toolbarPath: "/admin/settings",
|
|
176
|
+
isAdmin: true,
|
|
177
|
+
body: `<p>${statusBadge(account.status)}</p>
|
|
159
178
|
<p><a href="${ADMIN_ACCOUNTS_PATH}">← All accounts</a></p>
|
|
160
179
|
${errorHtml}
|
|
161
180
|
<div class="card">
|
|
@@ -197,6 +216,7 @@ export function renderAccountDetailPage(opts: AccountDetailPageOpts): string {
|
|
|
197
216
|
<tbody>${inviteRows}</tbody>
|
|
198
217
|
</table>
|
|
199
218
|
</div>
|
|
200
|
-
|
|
219
|
+
${statusAction}`,
|
|
220
|
+
}),
|
|
201
221
|
});
|
|
202
222
|
}
|
|
@@ -136,3 +136,32 @@ describe("renderAgentsPage Account column", () => {
|
|
|
136
136
|
expect(html).not.toContain("<th>Account</th>");
|
|
137
137
|
});
|
|
138
138
|
});
|
|
139
|
+
|
|
140
|
+
describe("accounts pages in the settings shell (SGL-2.3)", () => {
|
|
141
|
+
test("list page renders in the layout with Accounts active", () => {
|
|
142
|
+
const html = renderAccountsListPage({
|
|
143
|
+
userEmail: "a@x.com",
|
|
144
|
+
accounts: [],
|
|
145
|
+
owners: new Map(),
|
|
146
|
+
});
|
|
147
|
+
expect(html).toContain("settings-sidebar");
|
|
148
|
+
expect(html).toContain(
|
|
149
|
+
'<a class="settings-nav-link" href="/admin/accounts" aria-current="page">Accounts</a>',
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("detail page puts Suspend in the shared danger box", () => {
|
|
154
|
+
const html = renderAccountDetailPage({
|
|
155
|
+
userEmail: "a@x.com",
|
|
156
|
+
account,
|
|
157
|
+
agents: [],
|
|
158
|
+
members: [],
|
|
159
|
+
invites: [],
|
|
160
|
+
});
|
|
161
|
+
expect(html).toContain("settings-danger-zone");
|
|
162
|
+
expect(html).toContain("/admin/accounts/a1/suspend");
|
|
163
|
+
expect(html).toContain(
|
|
164
|
+
'<a class="settings-nav-link" href="/admin/accounts" aria-current="page">Accounts</a>',
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -250,6 +250,8 @@ describe("/admin/accounts", () => {
|
|
|
250
250
|
const body = await res.text();
|
|
251
251
|
expect(body).toContain("Acme");
|
|
252
252
|
expect(body).toContain("owner@x.com");
|
|
253
|
+
expect(body).toContain("settings-sidebar");
|
|
254
|
+
expect(body).toContain('href="/admin/accounts" aria-current="page"');
|
|
253
255
|
});
|
|
254
256
|
|
|
255
257
|
it("403 for non-admin on every route", async () => {
|
package/src/admin-ui-accounts.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
renderAccountDetailPage,
|
|
24
24
|
renderAccountsListPage,
|
|
25
25
|
} from "./admin-ui-accounts-pages.ts";
|
|
26
|
+
import type { SettingsNav } from "./admin-ui-settings-layout.ts";
|
|
26
27
|
import { reconcileAgentAfterAccountChange } from "./agent-account-assignment.ts";
|
|
27
28
|
import type { AgentProvisioner } from "./agent-provisioner.ts";
|
|
28
29
|
import type { AgentService } from "./agents.ts";
|
|
@@ -46,6 +47,8 @@ export interface AdminAccountsRouteDeps {
|
|
|
46
47
|
/** SSP-5.3: assign/unassign agents (admin only). */
|
|
47
48
|
agents: Pick<AgentService, "getDetail" | "updateFields">;
|
|
48
49
|
provisioner: Pick<AgentProvisioner, "reconcile">;
|
|
50
|
+
/** Settings sidebar nav (SGL-2.3). */
|
|
51
|
+
settingsNav?: SettingsNav;
|
|
49
52
|
html: (content: string, opts?: { status?: number }) => Response;
|
|
50
53
|
}
|
|
51
54
|
|
|
@@ -82,7 +85,12 @@ export function registerAdminAccountsRoutes(
|
|
|
82
85
|
}),
|
|
83
86
|
);
|
|
84
87
|
return deps.html(
|
|
85
|
-
renderAccountsListPage({
|
|
88
|
+
renderAccountsListPage({
|
|
89
|
+
userEmail: c.var.userEmail,
|
|
90
|
+
accounts,
|
|
91
|
+
owners,
|
|
92
|
+
...(deps.settingsNav ? { nav: deps.settingsNav } : {}),
|
|
93
|
+
}),
|
|
86
94
|
);
|
|
87
95
|
});
|
|
88
96
|
|
|
@@ -107,6 +115,7 @@ export function registerAdminAccountsRoutes(
|
|
|
107
115
|
members,
|
|
108
116
|
invites,
|
|
109
117
|
error,
|
|
118
|
+
...(deps.settingsNav ? { nav: deps.settingsNav } : {}),
|
|
110
119
|
}),
|
|
111
120
|
{ status },
|
|
112
121
|
);
|
|
@@ -101,11 +101,15 @@ export function mergeSettingsNavItems(
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
export const SETTINGS_GHE_PATH = "/admin/settings/github-enterprise";
|
|
104
|
+
export const SETTINGS_ACCOUNT_PATH = "/admin/account";
|
|
105
|
+
export const SETTINGS_ACCOUNTS_PATH = "/admin/accounts";
|
|
104
106
|
export const SETTINGS_TEMPLATES_PATH = "/admin/settings/templates";
|
|
105
107
|
|
|
106
108
|
export interface BuildSettingsNavOptions {
|
|
107
109
|
/** Include the GitHub Enterprise item (its routes are registered). */
|
|
108
110
|
githubEnterprise?: boolean;
|
|
111
|
+
/** Include Account (members) and, admin-only, Accounts (SGL-2.3). */
|
|
112
|
+
accounts?: boolean;
|
|
109
113
|
/** Include the Templates item (its routes are registered). */
|
|
110
114
|
templates?: boolean;
|
|
111
115
|
/** Extension-contributed items (SGL-2.1). */
|
|
@@ -113,8 +117,9 @@ export interface BuildSettingsNavOptions {
|
|
|
113
117
|
}
|
|
114
118
|
|
|
115
119
|
/**
|
|
116
|
-
* Base settings nav (SGL-2.
|
|
117
|
-
*
|
|
120
|
+
* Base settings nav: Account section (SGL-2.3), Platform section (GitHub
|
|
121
|
+
* Enterprise, Templates, admin-only Accounts) plus extension items. Empty
|
|
122
|
+
* sections are dropped.
|
|
118
123
|
*/
|
|
119
124
|
export function buildSettingsNav(
|
|
120
125
|
opts: BuildSettingsNavOptions = {},
|
|
@@ -130,10 +135,23 @@ export function buildSettingsNav(
|
|
|
130
135
|
if (opts.templates) {
|
|
131
136
|
platform.push({ label: "Templates", path: SETTINGS_TEMPLATES_PATH });
|
|
132
137
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
138
|
+
if (opts.accounts) {
|
|
139
|
+
platform.push({
|
|
140
|
+
label: "Accounts",
|
|
141
|
+
path: SETTINGS_ACCOUNTS_PATH,
|
|
142
|
+
adminOnly: true,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
const sections: SettingsNavSection[] = [];
|
|
146
|
+
if (opts.accounts) {
|
|
147
|
+
sections.push({
|
|
148
|
+
label: "Account",
|
|
149
|
+
items: [{ label: "Account", path: SETTINGS_ACCOUNT_PATH }],
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
if (platform.length > 0)
|
|
153
|
+
sections.push({ label: "Platform", items: platform });
|
|
154
|
+
const base: SettingsNav = { sections };
|
|
137
155
|
return mergeSettingsNavItems(base, [...(opts.extraItems ?? [])]);
|
|
138
156
|
}
|
|
139
157
|
|
|
@@ -191,3 +191,31 @@ describe("toolbar Settings entry", () => {
|
|
|
191
191
|
);
|
|
192
192
|
});
|
|
193
193
|
});
|
|
194
|
+
|
|
195
|
+
describe("GET /admin/settings with accounts (SGL-2.3)", () => {
|
|
196
|
+
const selfServe = { enabled: true, contactEmail: "c@x.com" };
|
|
197
|
+
const build = (member: string | null) =>
|
|
198
|
+
createAdminUIApp(
|
|
199
|
+
makeMockDeps({
|
|
200
|
+
templateService,
|
|
201
|
+
selfServe,
|
|
202
|
+
accountServices: memberAccounts(member),
|
|
203
|
+
} as never),
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
it("lands an account member on Account", async () => {
|
|
207
|
+
const res = await build("m@acme.com").request("/admin/settings", {
|
|
208
|
+
headers: { cookie: await userCookie("m@acme.com") },
|
|
209
|
+
});
|
|
210
|
+
expect(res.status).toBe(302);
|
|
211
|
+
expect(res.headers.get("location")).toBe("/admin/account");
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("skips Account for an admin without an account", async () => {
|
|
215
|
+
const res = await build(null).request("/admin/settings", {
|
|
216
|
+
headers: { cookie: await adminCookie() },
|
|
217
|
+
});
|
|
218
|
+
expect(res.status).toBe(302);
|
|
219
|
+
expect(res.headers.get("location")).toBe("/admin/settings/templates");
|
|
220
|
+
});
|
|
221
|
+
});
|
package/src/admin-ui-styles.ts
CHANGED
|
@@ -3,10 +3,7 @@ import {
|
|
|
3
3
|
renderShipwrightToolbar,
|
|
4
4
|
baseStyles as toolbarBaseStyles,
|
|
5
5
|
} from "@app-vitals/agent-lib/web/toolbar.ts";
|
|
6
|
-
import {
|
|
7
|
-
shouldShowAccountNav,
|
|
8
|
-
shouldShowSettingsNav,
|
|
9
|
-
} from "./admin-ui-account-nav.ts";
|
|
6
|
+
import { shouldShowSettingsNav } from "./admin-ui-account-nav.ts";
|
|
10
7
|
|
|
11
8
|
export { escapeHtml };
|
|
12
9
|
|
|
@@ -686,7 +683,6 @@ export function renderAdminToolbar(userName: string, activePath = ""): string {
|
|
|
686
683
|
activePath,
|
|
687
684
|
logoutAction: "/admin/logout",
|
|
688
685
|
metricsUrl: process.env.METRICS_DASHBOARD_URL ?? "/dashboard",
|
|
689
|
-
showAccount: shouldShowAccountNav(),
|
|
690
686
|
showSettings: shouldShowSettingsNav(),
|
|
691
687
|
});
|
|
692
688
|
}
|
package/src/admin-ui.ts
CHANGED
|
@@ -46,15 +46,13 @@ import {
|
|
|
46
46
|
renderAgentDetailCardSlots,
|
|
47
47
|
} from "./admin-extension.ts";
|
|
48
48
|
import { registerAccountRoutes } from "./admin-ui-account.ts";
|
|
49
|
-
import {
|
|
50
|
-
runWithAccountNav,
|
|
51
|
-
runWithSettingsNav,
|
|
52
|
-
} from "./admin-ui-account-nav.ts";
|
|
49
|
+
import { runWithSettingsNav } from "./admin-ui-account-nav.ts";
|
|
53
50
|
import { renderZeroQuotaNotice } from "./admin-ui-account-pages.ts";
|
|
54
51
|
import { registerAdminAccountsRoutes } from "./admin-ui-accounts.ts";
|
|
55
52
|
import {
|
|
56
53
|
buildSettingsNav,
|
|
57
54
|
firstVisibleSettingsItem,
|
|
55
|
+
SETTINGS_ACCOUNT_PATH,
|
|
58
56
|
} from "./admin-ui-settings-layout.ts";
|
|
59
57
|
import { registerAdminGithubEnterpriseRoutes } from "./admin-ui-github-enterprise.ts";
|
|
60
58
|
import { registerAdminTemplatesRoutes } from "./admin-ui-templates.ts";
|
|
@@ -949,10 +947,11 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
949
947
|
devAuthEnabled,
|
|
950
948
|
});
|
|
951
949
|
|
|
952
|
-
|
|
953
|
-
|
|
950
|
+
const accountNavEnabled = Boolean(selfServe?.enabled && accountServices);
|
|
951
|
+
|
|
952
|
+
// GHE-1.4: the admin-only "Settings" toolbar entry.
|
|
954
953
|
// SGL-2.2: shown to admins and to account members.
|
|
955
|
-
if (githubEnterpriseApi || templateService) {
|
|
954
|
+
if (githubEnterpriseApi || templateService || accountNavEnabled) {
|
|
956
955
|
app.use("/admin/*", async (c, next) => {
|
|
957
956
|
const token = getCookie(c, SESSION_COOKIE);
|
|
958
957
|
const user = token ? await getSessionUser(token, sessionSecret) : null;
|
|
@@ -970,28 +969,6 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
970
969
|
});
|
|
971
970
|
}
|
|
972
971
|
|
|
973
|
-
// SSP-3.2: show the toolbar's "Account" entry only for signed-in users who
|
|
974
|
-
// belong to an account, and only while self-serve is on. The flag is carried
|
|
975
|
-
// in AsyncLocalStorage so renderAdminToolbar() needs no extra parameter.
|
|
976
|
-
const accountNavEnabled = Boolean(selfServe?.enabled && accountServices);
|
|
977
|
-
if (accountNavEnabled && accountServices) {
|
|
978
|
-
app.use("/admin/*", async (c, next) => {
|
|
979
|
-
const token = getCookie(c, SESSION_COOKIE);
|
|
980
|
-
const user = token ? await getSessionUser(token, sessionSecret) : null;
|
|
981
|
-
let showAccount = false;
|
|
982
|
-
if (user) {
|
|
983
|
-
try {
|
|
984
|
-
showAccount =
|
|
985
|
-
(await accountServices.accounts.getByMemberEmail(user.email)) !==
|
|
986
|
-
null;
|
|
987
|
-
} catch {
|
|
988
|
-
// nav is cosmetic — never fail the page over the lookup
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
return runWithAccountNav(showAccount, () => next());
|
|
992
|
-
});
|
|
993
|
-
}
|
|
994
|
-
|
|
995
972
|
// Extracted Slack app-manifest-creation/OAuth/app-token orchestration
|
|
996
973
|
// (UAP-1.1) — shared by the legacy /admin/provision/* wizard's Slack
|
|
997
974
|
// branch and the new per-agent /admin/agents/:id/connect-slack routes so
|
|
@@ -3977,16 +3954,29 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
3977
3954
|
const settingsNav = buildSettingsNav({
|
|
3978
3955
|
githubEnterprise: Boolean(githubEnterpriseApi),
|
|
3979
3956
|
templates: Boolean(templateService),
|
|
3957
|
+
accounts: accountNavEnabled,
|
|
3980
3958
|
extraItems: deps.settingsNavItems ?? [],
|
|
3981
3959
|
});
|
|
3982
3960
|
|
|
3983
3961
|
// SGL-2.2: /admin/settings lands on the first nav item the viewer can see.
|
|
3984
|
-
if (githubEnterpriseApi || templateService) {
|
|
3985
|
-
app.get("/admin/settings", requireAuth, (c) => {
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3962
|
+
if (githubEnterpriseApi || templateService || accountNavEnabled) {
|
|
3963
|
+
app.get("/admin/settings", requireAuth, async (c) => {
|
|
3964
|
+
// Admins without an account would 404 on the Account item; skip it.
|
|
3965
|
+
let nav = settingsNav;
|
|
3966
|
+
if (accountNavEnabled && accountServices) {
|
|
3967
|
+
const account = await accountServices.accounts
|
|
3968
|
+
.getByMemberEmail(c.var.userEmail)
|
|
3969
|
+
.catch(() => null);
|
|
3970
|
+
if (!account) {
|
|
3971
|
+
nav = {
|
|
3972
|
+
sections: settingsNav.sections.map((sec) => ({
|
|
3973
|
+
...sec,
|
|
3974
|
+
items: sec.items.filter((i) => i.path !== SETTINGS_ACCOUNT_PATH),
|
|
3975
|
+
})),
|
|
3976
|
+
};
|
|
3977
|
+
}
|
|
3978
|
+
}
|
|
3979
|
+
const first = firstVisibleSettingsItem(nav, c.var.isAdmin === true);
|
|
3990
3980
|
if (!first) {
|
|
3991
3981
|
return new Response("No settings are available for your account.", {
|
|
3992
3982
|
status: 404,
|
|
@@ -4025,12 +4015,14 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
4025
4015
|
registerAccountRoutes(app, {
|
|
4026
4016
|
enabled: accountNavEnabled,
|
|
4027
4017
|
requireAuth,
|
|
4018
|
+
settingsNav,
|
|
4028
4019
|
...accountServices,
|
|
4029
4020
|
html,
|
|
4030
4021
|
});
|
|
4031
4022
|
registerAdminAccountsRoutes(app, {
|
|
4032
4023
|
enabled: accountNavEnabled,
|
|
4033
4024
|
requireAuth,
|
|
4025
|
+
settingsNav,
|
|
4034
4026
|
...accountServices,
|
|
4035
4027
|
agents: agentService,
|
|
4036
4028
|
provisioner,
|