From d221236f2be616412c2c7bc947a6c01937f05397 Mon Sep 17 00:00:00 2001 From: Brendan Asselstine Date: Tue, 24 Nov 2026 15:54:16 -0700 Subject: [PATCH] Align dashboard page headers and client connection details --- packages/api-client/src/schema.d.ts | 1 + packages/api/src/api-service.ts | 14 ++++- packages/api/src/settings-contracts.ts | 2 +- .../connection-permissions.postgres.test.ts | 21 ++++--- packages/app/src/features/apps/index.tsx | 2 +- packages/app/src/features/events/events.tsx | 4 +- .../features/settings/authorized-clients.tsx | 56 ++++++++++------- .../app/src/features/workloads/workloads.tsx | 2 +- packages/app/test/functional/apps.spec.mjs | 2 +- .../functional/client-permissions.spec.mjs | 60 ++++++++++++------- .../functional/dashboard-headers.spec.mjs | 24 ++++++++ packages/docs/openapi.yaml | 2 + 12 files changed, 129 insertions(+), 61 deletions(-) create mode 100644 packages/app/test/functional/dashboard-headers.spec.mjs diff --git a/packages/api-client/src/schema.d.ts b/packages/api-client/src/schema.d.ts index 442837c2..29b83feb 100644 --- a/packages/api-client/src/schema.d.ts +++ b/packages/api-client/src/schema.d.ts @@ -5269,6 +5269,7 @@ export interface operations { clientId: string; clientName: string; appName?: string; + ownerUsername?: string; scopes: string[]; authorizationDate: string; expiresAt: string | null; diff --git a/packages/api/src/api-service.ts b/packages/api/src/api-service.ts index fc57d076..631cb6a4 100644 --- a/packages/api/src/api-service.ts +++ b/packages/api/src/api-service.ts @@ -677,9 +677,17 @@ export class ApiService { if (!this.env.OAUTH_PROVIDER) throw new ServiceError(503, "operation_failed", "OAuth management unavailable"); const grants: any[] = []; let cursor: string | undefined; do { const page = await this.env.OAUTH_PROVIDER.listUserGrants(this.auth.userId, { limit: 100, cursor }); grants.push(...page.items.filter(grant => (grant.metadata as any)?.tenantId === this.auth.tenantId && (!grant.expiresAt || grant.expiresAt > Math.floor(Date.now() / 1000)))); cursor = page.cursor; } while (cursor); - const clients = await Promise.all([...new Set(grants.map(grant => grant.clientId))].map(async clientId => [clientId, await this.env.OAUTH_PROVIDER!.lookupClient(clientId)] as const)); + if (!grants.length) return []; + // listUserGrants is scoped to the authenticated owner; do not read account + // information for another user or expose grants from another workspace. + const db = databaseFor(this.env); + const [clients, settings, owner] = await Promise.all([ + Promise.all([...new Set(grants.map(grant => grant.clientId))].map(async clientId => [clientId, await this.env.OAUTH_PROVIDER!.lookupClient(clientId)] as const)), + db.pool.query("SELECT subject,display_name,disabled_scopes,scope_overrides,integration_overrides,permissions_revision FROM app.agent_identities WHERE tenant_id=$1 AND user_id=$2 AND kind='oauth' AND subject=ANY($3)", [this.auth.tenantId, this.auth.userId, grants.map(g => g.id)]), + db.pool.query<{ username: string }>("SELECT username FROM app.auth_users WHERE id=$1", [this.auth.userId]), + ]); const byId = new Map(clients); - const settings = await databaseFor(this.env).pool.query("SELECT subject,display_name,disabled_scopes,scope_overrides,integration_overrides,permissions_revision FROM app.agent_identities WHERE tenant_id=$1 AND user_id=$2 AND kind='oauth' AND subject=ANY($3)", [this.auth.tenantId, this.auth.userId, grants.map(g => g.id)]); + const ownerUsername = owner.rows[0]?.username; const byGrant = new Map(settings.rows.map(row => [row.subject, row])); const { integrations } = await listAgentPolicies(this.env, this.auth.tenantId); const globallyAvailable = [...AGENT_SCOPES, ...integrations.filter(row => row.available && row.policy !== "disabled").map(row => row.requiredScope)]; @@ -696,7 +704,7 @@ export class ApiService { const availableScopes = [...new Set([...globallyAvailable, ...scopes])]; return { grantId: grant.id, clientId: grant.clientId, clientName: row?.display_name ?? byId.get(grant.clientId)?.clientName ?? grant.clientId, appName: byId.get(grant.clientId)?.clientName ?? grant.clientId, availableScopes, scopeLabels, scopes, revision: row?.permissions_revision ?? 0, - integrationOverrides, authorizationDate: new Date(grant.createdAt * 1000).toISOString(), + integrationOverrides, ownerUsername, authorizationDate: new Date(grant.createdAt * 1000).toISOString(), expiresAt: grant.expiresAt ? new Date(grant.expiresAt * 1000).toISOString() : null, lastUsedAt: null }; })); } diff --git a/packages/api/src/settings-contracts.ts b/packages/api/src/settings-contracts.ts index d3b2ad1b..dedef8e8 100644 --- a/packages/api/src/settings-contracts.ts +++ b/packages/api/src/settings-contracts.ts @@ -14,7 +14,7 @@ export const clientPermissionsInput = z.object({ expectedRevision: z.number().int().nonnegative().optional(), }).strict().refine(value => value.scopes !== undefined || value.disabledScopes !== undefined || value.integrationOverrides !== undefined, "Supply a scope selection."); export const clientPermissionsUpdate = clientPermissionsInput; -export const authorizedClient = z.object({ availableScopes: z.array(z.string()), scopeLabels: z.record(z.string(),z.string()).default({}), integrationOverrides: z.record(z.uuid(), z.union([z.string(), z.literal(false)])).default({}), revision: z.number().int(), grantId: z.string(), clientId: z.string(), clientName: z.string(), appName: z.string().optional(), scopes: z.array(z.string()), authorizationDate: timestamp, expiresAt: timestamp.nullable(), lastUsedAt: timestamp.nullable() }); +export const authorizedClient = z.object({ availableScopes: z.array(z.string()), scopeLabels: z.record(z.string(),z.string()).default({}), integrationOverrides: z.record(z.uuid(), z.union([z.string(), z.literal(false)])).default({}), revision: z.number().int(), grantId: z.string(), clientId: z.string(), clientName: z.string(), appName: z.string().optional(), ownerUsername: z.string().optional(), scopes: z.array(z.string()), authorizationDate: timestamp, expiresAt: timestamp.nullable(), lastUsedAt: timestamp.nullable() }); export const accessToken = z.object({ id: z.string(), name: z.string(), scopes: z.array(z.enum(ACCESS_SCOPES)), created_at: timestamp, expires_at: timestamp, last_used_at: timestamp.nullable().optional(), revoked_at: timestamp.nullable().optional() }); export const createdAccessToken = accessToken.extend({ token: z.string() }); export const okResult = z.object({ ok: z.boolean() }); diff --git a/packages/api/test/connection-permissions.postgres.test.ts b/packages/api/test/connection-permissions.postgres.test.ts index 1b75ba1d..4e610715 100644 --- a/packages/api/test/connection-permissions.postgres.test.ts +++ b/packages/api/test/connection-permissions.postgres.test.ts @@ -72,13 +72,19 @@ it.skipIf(!url)("renames only the selected connection and preserves policy befor try { const integrationId = crypto.randomUUID(), scope = `integration:${integrationId}:1`; const grantId = "rename-fixture"; + await f.db.pool.query("UPDATE app.auth_users SET username=$1 WHERE id=$2", ["actual-owner", f.userId]); + const now = Math.floor(Date.now() / 1000); const grants = [ - { id: grantId, metadata: { tenantId: f.tenantId, initialIntegrationDenials: [integrationId] } }, + { id: grantId, metadata: { tenantId: f.tenantId, initialIntegrationDenials: [integrationId] }, expiresAt: now + 86400 }, { id: "sibling", metadata: { tenantId: f.tenantId } }, { id: "other-team", metadata: { tenantId: f.otherTenant } }, - ].map(grant => ({ ...grant, clientId: "same-app", scope: ["proxy:use", scope], createdAt: Math.floor(Date.now() / 1000) })); + { id: "expired-grant", metadata: { tenantId: f.tenantId }, expiresAt: now - 1 }, + ].map(grant => ({ ...grant, clientId: "same-app", scope: ["proxy:use", scope], createdAt: now })); Object.assign(f.env, { OAUTH_PROVIDER: { - listUserGrants: async () => ({ items: grants }), + listUserGrants: async (userId: string) => { + expect(userId).toBe(f.userId); + return { items: grants }; + }, lookupClient: async () => ({ clientName: "Registered app" }), } }); await f.db.pool.query(`INSERT INTO app.agent_integrations(tenant_id,id,kind,credential_id,name,available,policy) @@ -96,10 +102,11 @@ it.skipIf(!url)("renames only the selected connection and preserves policy befor const response = await rename(grantId, " Release assistant "); expect(response.status, await response.clone().text()).toBe(200); expect(await response.json()).toEqual({ name: "Release assistant" }); - expect(await clients()).toEqual(expect.arrayContaining([ - expect.objectContaining({ grantId, clientName: "Release assistant", appName: "Registered app", scopes: ["proxy:use"], revision: 0, integrationOverrides: { [integrationId]: false } }), - expect.objectContaining({ grantId: "sibling", clientName: "Registered app" }), - ])); + expect(await clients()).toEqual([ + expect.objectContaining({ grantId, clientName: "Release assistant", appName: "Registered app", ownerUsername: "actual-owner", scopes: ["proxy:use"], revision: 0, integrationOverrides: { [integrationId]: false }, authorizationDate: new Date(now * 1000).toISOString(), expiresAt: new Date((now + 86400) * 1000).toISOString() }), + expect.objectContaining({ grantId: "sibling", clientName: "Registered app", ownerUsername: "actual-owner", expiresAt: null }), + ]); + expect((await request("/api/v1/access/authorized-clients", undefined, { ...f.auth, authMethod: "oauth" })).status).toBe(403); const permissions = await request(`/api/v1/access/authorizations/${grantId}/permissions`, { scopes: ["team:read"], expectedRevision: 0 }); expect(permissions.status, await permissions.text()).toBe(200); diff --git a/packages/app/src/features/apps/index.tsx b/packages/app/src/features/apps/index.tsx index bb403df3..4f8059d1 100644 --- a/packages/app/src/features/apps/index.tsx +++ b/packages/app/src/features/apps/index.tsx @@ -26,7 +26,7 @@ export function ConnectedAppsPage() { }, onSuccess: () => cache.invalidateQueries({ queryKey: connectedKey }), }); - return + return {connected.isPending &&

Loading connected apps…

} {connected.error &&

{connected.error.message}

} {revoke.error &&

{revoke.error.message}

} diff --git a/packages/app/src/features/events/events.tsx b/packages/app/src/features/events/events.tsx index ce272f7d..bfb2bcaf 100644 --- a/packages/app/src/features/events/events.tsx +++ b/packages/app/src/features/events/events.tsx @@ -1,7 +1,7 @@ import { useState } from "react"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { api } from "factorize-api-client"; -import { Button, Page } from "../../shared/ui"; +import { Button, Page, PageHeader } from "../../shared/ui"; export function EventsPage() { const client = useQueryClient(); @@ -20,7 +20,7 @@ export function EventsPage() { const result = await api.DELETE("/api/v1/events/{eventId}", { params: { path: { eventId } } }); if (result.error) throw new Error(result.error.error?.message ?? "Could not delete Event"); }, onSuccess: async (_result, eventId) => { if (selected === eventId) setSelected(undefined); await client.invalidateQueries({ queryKey: ["events"] }); } }); - return

Event stream

Events

Durable occurrences published by Triggers. Subscribe to an Event’s occurrence resource over MCP.

+ return {events.error &&

{events.error.message}

} {remove.error &&

{remove.error.message}

}

Defined Events

    {(events.data ?? []).map(item =>
  • )}
{events.data?.length === 0 &&

No Events yet.

}
diff --git a/packages/app/src/features/settings/authorized-clients.tsx b/packages/app/src/features/settings/authorized-clients.tsx index bfff9429..ba6c1107 100644 --- a/packages/app/src/features/settings/authorized-clients.tsx +++ b/packages/app/src/features/settings/authorized-clients.tsx @@ -3,7 +3,9 @@ import { Link, useParams } from "@tanstack/react-router"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { api } from "factorize-api-client"; import { Dialog } from "../../shared/dialog"; -import { Button, Input, Label, Page } from "../../shared/ui"; +import { + Button, Input, Label, Page, PageHeader, Table, tableCellClasses, tableHeadClasses, tableRowClasses, +} from "../../shared/ui"; import { messageOf } from "../auth/session"; import { ClientPermissions, type AuthorizedClient } from "./client-permissions"; import { clientsQuery } from "./queries"; @@ -63,31 +65,30 @@ function RevokeConnection({ client }: { client: AuthorizedClient }) { ; } +function ConnectionDate({ value }: { value: string | null }) { + return value ? : "No expiration"; +} + export function ClientsPage() { const clients = useQuery(clientsQuery); - const [editing, setEditing] = useState(null); return -

Clients

+ {clients.isPending &&

Loading clients…

} {clients.error &&

{clients.error.message}

} {clients.data?.length === 0 &&

No authorized clients.

} - {!!clients.data?.length &&
- - - - - + {!!clients.data?.length &&
ConnectionAppAuthorizedActions
+ + {["Username", "Connection", "App", "Authorized", "Expires"].map(label => + )} - {clients.data.map(client => - - - - + {clients.data.map(client => + + + + + )} -
{label}
{client.clientName}{client.appName ?? client.clientName}{new Date(client.authorizationDate).toLocaleString()}
- -
{client.ownerUsername ?? "—"}{client.clientName}{client.appName ?? client.clientName}
} - {editing && setEditing(null)} />} + }
; } @@ -97,12 +98,21 @@ export function ClientPage() { const client = clients.data?.find(item => item.grantId === grantId); const [editing, setEditing] = useState(false); return - Clients -

{client?.clientName ?? "Client connection"}

+ + {clients.isPending &&

Loading client…

} {clients.error &&

{clients.error.message}

} - {client &&
- -
} + {!clients.isPending && !clients.error && !client &&

Client connection not found.

} + {client && <> +
+
Username
{client.ownerUsername ?? "—"}
+
Client
{client.appName ?? client.clientName}
+
Authorized
+
Expires
+
+
+ +
+ } {editing && client && setEditing(false)} />}
; } diff --git a/packages/app/src/features/workloads/workloads.tsx b/packages/app/src/features/workloads/workloads.tsx index a0037a9e..c992e82a 100644 --- a/packages/app/src/features/workloads/workloads.tsx +++ b/packages/app/src/features/workloads/workloads.tsx @@ -42,7 +42,7 @@ export function WorkloadsPage() { const state = useVmGrants(); const rows = state.canRead ? state.grants.data : undefined; return - + {rows?.length === 0 &&

No workloads have Factorize permissions.

} {!!rows?.length && diff --git a/packages/app/test/functional/apps.spec.mjs b/packages/app/test/functional/apps.spec.mjs index fde7f0ba..29eb3690 100644 --- a/packages/app/test/functional/apps.spec.mjs +++ b/packages/app/test/functional/apps.spec.mjs @@ -9,7 +9,7 @@ test("Connected apps use the dashboard tab and Registered apps live in Settings" await page.goto(origin + "/apps"); const dashboard = page.getByRole("navigation", { name: "Dashboard navigation" }); await expect(dashboard.getByRole("link", { name: "Apps", exact: true })).toHaveAttribute("aria-current", "page"); - await expect(page.getByRole("heading", { name: "Connected apps" })).toBeVisible(); + await expect(page.getByRole("heading", { name: "Apps", level: 1 })).toBeVisible(); await expect(page.getByText("No connected apps.")).toBeVisible(); await expect(page.getByRole("link", { name: "Registered apps" })).toHaveCount(0); diff --git a/packages/app/test/functional/client-permissions.spec.mjs b/packages/app/test/functional/client-permissions.spec.mjs index 847db4ed..f090b6cc 100644 --- a/packages/app/test/functional/client-permissions.spec.mjs +++ b/packages/app/test/functional/client-permissions.spec.mjs @@ -15,7 +15,7 @@ test("saving client permissions keeps a blocked integration unchecked until expl team: { id: "workspace", name: "Workspace", role: "owner" }, capabilities: [], } })); await page.route("**/api/v1/access/authorized-clients", route => route.fulfill({ json: [{ - grantId: "fixture-grant", clientId: "fixture-client", clientName: "Fixture client", + grantId: "fixture-grant", clientId: "fixture-client", clientName: "Fixture client", ownerUsername: "owner-user", availableScopes: [...editedScopes, integrationScope], scopes, revision, scopeLabels: { [integrationScope]: "Linear integration access" }, integrationOverrides: denied ? { [integrationId]: false } : {}, @@ -60,17 +60,17 @@ test("saving client permissions keeps a blocked integration unchecked until expl }); -test("renames a connection from the list and detail without changing the registered app or sibling connection", async ({ page, origin }) => { - const grant = { grantId: "primary", clientId: "same-app", clientName: "Registered app", appName: "Registered app", +test("shows owner and dates in the Clients list and manages the connection on its detail page", async ({ page, origin }) => { + const grant = { grantId: "primary", clientId: "same-app", clientName: "Release assistant", appName: "Registered app", ownerUsername: "brendan", availableScopes: ["team:read"], scopes: ["team:read"], revision: 0, scopeLabels: {}, integrationOverrides: {}, - authorizationDate: "2026-10-09T12:00:00Z", expiresAt: null, lastUsedAt: null }; + authorizationDate: "2026-10-09T12:00:00Z", expiresAt: "2026-12-10T18:30:00Z", lastUsedAt: null }; const writes = []; await page.route("**/api/v1/session", route => route.fulfill({ json: { - authenticated: true, user: { id: "owner", email: "owner@example.test" }, + authenticated: true, user: { id: "owner", email: "different-name@example.test" }, team: { id: "workspace", name: "Workspace", role: "owner" }, capabilities: [], } })); await page.route("**/api/v1/access/authorized-clients", route => route.fulfill({ json: [grant, - { ...grant, grantId: "sibling", clientName: "Other connection" }] })); + { ...grant, grantId: "sibling", clientName: "Other connection", expiresAt: null }] })); await page.route("**/api/v1/access/authorizations/primary/name", route => { expect(route.request().method()).toBe("PUT"); const body = route.request().postDataJSON(); @@ -80,24 +80,40 @@ test("renames a connection from the list and detail without changing the registe }); await page.goto(origin + "/clients"); - const row = page.getByRole("row", { name: /Registered app/ }).filter({ has: page.getByRole("link", { name: "Registered app" }) }); - await row.getByRole("button", { name: "Rename connection" }).click(); + const main = page.getByRole("main"); + const table = main.getByRole("table", { name: "MCP connections" }); + await expect(table.getByRole("columnheader")).toHaveText(["Username", "Connection", "App", "Authorized", "Expires"]); + const row = table.getByRole("row").filter({ has: page.getByRole("link", { name: "Release assistant" }) }); + await expect(row.getByRole("cell").first()).toHaveText("brendan"); + await expect(row.getByRole("cell", { name: "Registered app" })).toBeVisible(); + await expect(row.locator("time").first()).toHaveAttribute("datetime", grant.authorizationDate); + await expect(row.locator("time").last()).toHaveAttribute("datetime", grant.expiresAt); + await expect(table.getByRole("button")).toHaveCount(0); + await expect(table.getByRole("cell", { name: "No expiration" })).toBeVisible(); + + await row.getByRole("link", { name: "Release assistant" }).click(); + await expect(page).toHaveURL(origin + "/clients/primary"); + await expect(main.getByRole("heading", { level: 1, name: "Release assistant", exact: true })).toBeVisible(); + await expect(main.getByRole("link", { name: "Clients", exact: true })).toHaveCount(0); + await expect(main.locator("dt")).toHaveText(["Username", "Client", "Authorized", "Expires"]); + await expect(main.locator("dd").nth(0)).toHaveText("brendan"); + await expect(main.locator("dd").nth(1)).toHaveText("Registered app"); + await expect(main.locator("dd").nth(2).locator("time")).toHaveAttribute("datetime", grant.authorizationDate); + await expect(main.locator("dd").nth(3).locator("time")).toHaveAttribute("datetime", grant.expiresAt); + await expect(main.getByRole("button", { name: "Edit permissions" })).toBeVisible(); + await expect(main.getByRole("button", { name: "Revoke connection" })).toBeVisible(); + + await main.getByRole("button", { name: "Rename connection" }).click(); const name = page.getByRole("textbox", { name: "Connection name" }); - await expect(name).toHaveValue("Registered app"); + await expect(name).toHaveValue("Release assistant"); await name.fill(" "); await expect(page.getByRole("button", { name: "Save name" })).toBeDisabled(); - await name.fill(" Release assistant "); + await name.fill(" Updated assistant "); await name.press("Enter"); - await expect(page.getByRole("link", { name: "Release assistant" })).toBeVisible(); - await expect(page.getByRole("link", { name: "Other connection" })).toBeVisible(); - await expect(page.getByRole("cell", { name: "Registered app", exact: true })).toHaveCount(2); - - await page.getByRole("link", { name: "Release assistant" }).click(); - await expect(page.getByRole("heading", { name: "Release assistant", exact: true })).toBeVisible(); - await page.getByRole("button", { name: "Rename connection" }).click(); - await expect(name).toHaveValue("Release assistant"); - await name.fill("Updated assistant"); - await page.getByRole("button", { name: "Save name" }).click(); - await expect(page.getByRole("heading", { name: "Updated assistant" })).toBeVisible(); - expect(writes).toEqual([{ name: "Release assistant" }, { name: "Updated assistant" }]); + await expect(main.getByRole("heading", { level: 1, name: "Updated assistant" })).toBeVisible(); + await page.getByRole("navigation", { name: "Dashboard navigation" }).getByRole("link", { name: "Clients" }).click(); + await expect(table.getByRole("link", { name: "Updated assistant" })).toBeVisible(); + await expect(table.getByRole("link", { name: "Other connection" })).toBeVisible(); + await expect(table.getByRole("cell", { name: "Registered app", exact: true })).toHaveCount(2); + expect(writes).toEqual([{ name: "Updated assistant" }]); }); diff --git a/packages/app/test/functional/dashboard-headers.spec.mjs b/packages/app/test/functional/dashboard-headers.spec.mjs new file mode 100644 index 00000000..8cbf67af --- /dev/null +++ b/packages/app/test/functional/dashboard-headers.spec.mjs @@ -0,0 +1,24 @@ +import { test, expect } from "./fixtures.mjs"; + +test("dashboard pages share a title and domain description", async ({ page, origin }) => { + await page.route("**/api/v1/session", route => route.fulfill({ json: { + authenticated: true, user: { id: "owner" }, team: { id: "team", name: "Team" }, capabilities: [], + } })); + for (const endpoint of ["access/authorized-clients", "app-connections", "events"]) { + await page.route("**/api/v1/" + endpoint, route => route.fulfill({ json: [] })); + } + await page.goto(origin + "/clients"); + + const dashboard = page.getByRole("navigation", { name: "Dashboard navigation" }); + const main = page.getByRole("main"); + for (const [title, description] of [ + ["Clients", "All of the connected MCP clients"], + ["Workloads", "Virtual Machines, VPSs, and other workloads that have been granted permissions"], + ["Apps", "Apps connected to this Team"], + ["Events", "MCP Events to help coordinate your agents"], + ]) { + await dashboard.getByRole("link", { name: title, exact: true }).click(); + await expect(main.getByRole("heading", { level: 1, name: title, exact: true })).toBeVisible(); + await expect(main.getByText(description, { exact: true })).toBeVisible(); + } +}); diff --git a/packages/docs/openapi.yaml b/packages/docs/openapi.yaml index ff2cc0aa..45eb4ddc 100644 --- a/packages/docs/openapi.yaml +++ b/packages/docs/openapi.yaml @@ -5000,6 +5000,8 @@ paths: type: string appName: type: string + ownerUsername: + type: string scopes: type: array items: