diff --git a/dashboard/e2e/hybrid.spec.ts b/dashboard/e2e/hybrid.spec.ts index 5540635d..b60d61c0 100644 --- a/dashboard/e2e/hybrid.spec.ts +++ b/dashboard/e2e/hybrid.spec.ts @@ -149,6 +149,11 @@ async function setup(page: Page, cfg: Record | null = SELF, ini if (p === "/api/system/hybrid/settings" && method === "PUT") { if (body?.github_mode) s.mode = body.github_mode as State["mode"]; if (Array.isArray(body?.integrations)) s.hosted = new Set(body!.integrations as string[]); + // Other apps, per tool: only the tools named change. + for (const [id, v] of Object.entries((body?.apps as Record | undefined) ?? {})) { + if (v === "coderhelm") s.hosted.add(id); + else s.hosted.delete(id); + } if (body?.sharing) s.sharing = body.sharing as State["sharing"]; return json(route, status(s)); } @@ -285,16 +290,31 @@ for (const [outcome, words, tone] of [ }); } -test("other apps: each choice sends the hosted list; direct and unavailable say so", async ({ page }) => { +test("other apps: a new install shows Coderhelm's app selected for every tool", async ({ page }) => { + // What the install answers when nobody chose: Coderhelm's app for each tool. + const { puts } = await setup(page, SELF, { registered: true, verified: true, hosted: new Set(["jira", "notion", "confluence", "google_drive"]) }); + await page.goto("/settings/system/"); + for (const id of ["jira", "notion", "confluence", "google_drive"]) { + const row = page.getByTestId(`hybrid-integration-${id}`); + await expect(row.getByRole("button", { name: "Use Coderhelm's app (easiest)" })).toHaveAttribute("aria-pressed", "true"); + await expect(row.getByRole("button", { name: "Use my own app (fully private)" })).toHaveAttribute("aria-pressed", "false"); + await expect(row).toContainText("Through Coderhelm"); + } + // Showing the defaults saves nothing. + expect(puts()).toEqual([]); +}); + +test("other apps: each choice sends only that tool; direct and unavailable say so", async ({ page }) => { const { puts } = await setup(page, SELF, { registered: true, verified: true }); await page.goto("/settings/system/"); const jira = page.getByTestId("hybrid-integration-jira"); await expect(jira).toContainText("Ticket events and the sign-in."); await jira.getByRole("button", { name: "Use Coderhelm's app (easiest)" }).click(); - await expect.poll(() => (puts().at(-1)?.integrations as string[] | undefined)?.slice().sort()).toEqual(["jira", "notion"]); + await expect.poll(() => puts().at(-1)).toEqual({ apps: { jira: "coderhelm" } }); await expect(jira.getByRole("button", { name: "Use Coderhelm's app (easiest)" })).toHaveAttribute("aria-pressed", "true"); await page.getByTestId("hybrid-integration-notion").getByRole("button", { name: "Use my own app (fully private)" }).click(); - await expect.poll(() => puts().at(-1)?.integrations).toEqual(["jira"]); + await expect.poll(() => puts().at(-1)).toEqual({ apps: { notion: "own" } }); + await expect(page.getByTestId("hybrid-integration-notion").getByRole("button", { name: "Use my own app (fully private)" })).toHaveAttribute("aria-pressed", "true"); await expect(page.getByTestId("hybrid-integration-confluence")).toHaveAttribute("data-mode", "hosted"); await expect(page.getByTestId("hybrid-integration-slack_notifications")).toContainText("Works from your install, no app needed"); await expect(page.getByTestId("hybrid-integration-mcp_apps")).toContainText("Works from your install, no app needed"); @@ -381,7 +401,7 @@ test("integration pages: the app choice saves the same settings, and links to Sy await page.goto("/settings/integrations/jira/"); const jira = page.getByTestId("hybrid-app-choice"); await jira.getByRole("button", { name: "Use Coderhelm's app (easiest)" }).click(); - await expect.poll(() => (puts().at(-1)?.integrations as string[] | undefined)?.slice().sort()).toEqual(["jira", "notion"]); + await expect.poll(() => puts().at(-1)).toEqual({ apps: { jira: "coderhelm" } }); }); test("integration pages before registering point to Settings, System, Hybrid", async ({ page }) => { diff --git a/dashboard/src/components/hybrid-app-choice.tsx b/dashboard/src/components/hybrid-app-choice.tsx index a4864c70..cddb48b9 100644 --- a/dashboard/src/components/hybrid-app-choice.tsx +++ b/dashboard/src/components/hybrid-app-choice.tsx @@ -2,7 +2,7 @@ import Link from "next/link"; import { useState } from "react"; -import { HYBRID_HREF, canUseCoderhelm, hostedIntegrations, useHybrid } from "@/lib/hybrid"; +import { HYBRID_HREF, appChoice, canUseCoderhelm, useHybrid } from "@/lib/hybrid"; import { Segmented } from "./segmented"; import { useToast } from "./toast"; import { linkButton } from "./ui"; @@ -44,7 +44,7 @@ export function HybridAppChoice({ id, name, className = "" }: { id: string; name if (next === value || busy) return; setBusy(true); try { - await hybrid.save(id === "github" ? { github_mode: next === "coderhelm" ? "hosted" : "own" } : { integrations: hostedIntegrations(s, id, next === "coderhelm") }); + await hybrid.save(id === "github" ? { github_mode: next === "coderhelm" ? "hosted" : "own" } : appChoice(id, next === "coderhelm")); toast(next === "coderhelm" ? `${name} now uses Coderhelm's app` : `${name} now uses your own app`); } catch (e) { toast(e instanceof Error ? e.message : "Could not save", "error"); diff --git a/dashboard/src/components/hybrid-section.tsx b/dashboard/src/components/hybrid-section.tsx index 91d978e2..fc5634df 100644 --- a/dashboard/src/components/hybrid-section.tsx +++ b/dashboard/src/components/hybrid-section.tsx @@ -3,7 +3,7 @@ import Link from "next/link"; import { useEffect, useId, useRef, useState, type ReactNode } from "react"; import { api, type HybridCheck, type HybridGithubLink, type HybridIntegration, type HybridNameCheck, type HybridStatus } from "@/lib/api"; -import { GITHUB_OUTCOMES, NAME_CODES, TRUST_MODEL_URL, cleanName, hostedIntegrations, useHybrid, type HybridState } from "@/lib/hybrid"; +import { GITHUB_OUTCOMES, NAME_CODES, TRUST_MODEL_URL, appChoice, cleanName, useHybrid, type HybridState } from "@/lib/hybrid"; import { Callout } from "./callout"; import { CopyButton } from "./copy-button"; import { useConfirm } from "./confirm-dialog"; @@ -657,7 +657,7 @@ function IntegrationItem({ i, hybrid, s }: { i: HybridIntegration } & RowProps) value={value} disabled={!!busy} onChange={(v) => - void act("set", () => hybrid.save({ integrations: hostedIntegrations(s, i.id, v === "coderhelm") }), v === "coderhelm" ? `${i.name} uses Coderhelm's app` : `${i.name} uses your own app`) + void act("set", () => hybrid.save(appChoice(i.id, v === "coderhelm")), v === "coderhelm" ? `${i.name} uses Coderhelm's app` : `${i.name} uses your own app`) } options={[ { value: "coderhelm", label: "Use Coderhelm's app (easiest)" }, diff --git a/dashboard/src/lib/api.ts b/dashboard/src/lib/api.ts index 394a8e31..75423be3 100644 --- a/dashboard/src/lib/api.ts +++ b/dashboard/src/lib/api.ts @@ -4626,8 +4626,10 @@ export interface HybridNameCheck { export interface HybridSettingsPatch { github_mode?: "own" | "hosted"; - /** The hosted-app integrations among jira, notion, confluence, google_drive (github follows github_mode). */ + /** The hosted-app integrations among jira, notion, confluence, google_drive (github follows github_mode). Older installs; newer ones take `apps`. */ integrations?: string[]; + /** Other apps, per tool (jira, notion, confluence, google_drive): only the tools named change. A tool nobody chose uses Coderhelm's app. */ + apps?: Record; sharing?: { enabled: boolean; payloads: boolean }; /** Settings, Integrations, Jira: link a hosted team's Jira site through Coderhelm. */ jira_link?: boolean; diff --git a/dashboard/src/lib/hybrid.ts b/dashboard/src/lib/hybrid.ts index 143e2692..04b277b8 100644 --- a/dashboard/src/lib/hybrid.ts +++ b/dashboard/src/lib/hybrid.ts @@ -217,10 +217,7 @@ export function canUseCoderhelm(i: HybridIntegration | undefined): boolean { return i?.mode === "hosted" && i.offered !== false; } -/** The hosted-app integrations after switching `id` on or off (GitHub follows its own mode). */ -export function hostedIntegrations(status: HybridStatus, id: string, useCoderhelm: boolean): string[] { - const now = new Set(status.integrations.filter((i) => i.id !== "github" && canUseCoderhelm(i) && i.uses_coderhelm).map((i) => i.id)); - if (useCoderhelm) now.add(id); - else now.delete(id); - return [...now]; +/** The settings change for one Other apps tool (GitHub follows its own mode). Only that tool changes. */ +export function appChoice(id: string, useCoderhelm: boolean): HybridSettingsPatch { + return { apps: { [id]: useCoderhelm ? "coderhelm" : "own" } }; } diff --git a/docs/components/install/wizard.tsx b/docs/components/install/wizard.tsx index 82a19d98..ba06e364 100644 --- a/docs/components/install/wizard.tsx +++ b/docs/components/install/wizard.tsx @@ -31,6 +31,11 @@ import { HYBRID_GITHUB_OUTCOMES, NAME_ZONE, SETUPS, + ALL_HOSTED_APPS, + ALL_OWN_APPS, + OTHER_APPS, + appsBody, + wantsHybrid, STEP_TIME, type Setup, cleanName, @@ -877,7 +882,7 @@ export function InstallWizard() { const [hyb, setHyb] = useState<{ error: { title: string; fix: string } | null; claimRefused: boolean; settingsSent: boolean; lastTry: number; busy: boolean }>({ error: null, claimRefused: false, settingsSent: false, lastTry: 0, busy: false }); const [newName, setNewName] = useState(''); const [hybridOutcome, setHybridOutcome] = useState(null); - const hybridWanted = !!s && (s.domainChoice === 'coderhelm' || s.githubChoice === 'hosted' || s.jiraChoice === 'hosted' || s.emailTransport === 'coderhelm'); + const hybridWanted = !!s && wantsHybrid(s); useEffect(() => { // A closed install (someone signed up) answers no setup calls: nothing to send. if (!s || !hybridWanted || !s.url || !setup || setup.closed || !s.setupToken || hyb.busy) return; @@ -892,7 +897,8 @@ export function InstallWizard() { path = '/settings'; // CoderHelm's Jira app: Link through CoderHelm turned on now, so the // install reports hybrid_jira and the Jira step can follow the link. - body = { ...body, github_mode: s.githubChoice, sharing: { enabled: s.sharing, payloads: false }, ...(s.jiraChoice === 'hosted' ? { jira_link: true } : {}) }; + // Other apps: each tool's choice, applied as the install registers. + body = { ...body, github_mode: s.githubChoice, sharing: { enabled: s.sharing, payloads: false }, apps: appsBody(s), ...(s.jiraChoice === 'hosted' ? { jira_link: true } : {}) }; } else if (s.domainChoice === 'coderhelm' && !nm && !hyb.claimRefused && cleanName(s.coderhelmName)) { path = '/name'; body = { ...body, name: cleanName(s.coderhelmName) }; @@ -993,8 +999,8 @@ export function InstallWizard() { const hybrid = s.setup === 'hybrid'; const pickSetup = (id: Setup) => update(id === 'hybrid' - ? { setup: 'hybrid', domainChoice: 'coderhelm', githubChoice: 'hosted', jiraChoice: 'hosted' } - : { setup: 'private', domainChoice: s.domainChoice === 'coderhelm' ? 'aws' : s.domainChoice, githubChoice: 'own', jiraChoice: 'own' }); + ? { setup: 'hybrid', domainChoice: 'coderhelm', githubChoice: 'hosted', jiraChoice: 'hosted', appChoices: { ...ALL_HOSTED_APPS } } + : { setup: 'private', domainChoice: s.domainChoice === 'coderhelm' ? 'aws' : s.domainChoice, githubChoice: 'own', jiraChoice: 'own', appChoices: { ...ALL_OWN_APPS } }); screen = (
@@ -1080,6 +1086,16 @@ export function InstallWizard() { title="Use CoderHelm’s Jira app" help="Link your Jira site through CoderHelm’s Jira app instead of setting up your own. Events come through CoderHelm, checked and re-signed; your install never holds the app’s secret and calls Jira through CoderHelm. Needs a team on app.coderhelm.com that runs the Jira app on your site." /> + {OTHER_APPS.map((a) => ( + update({ appChoices: { ...ALL_HOSTED_APPS, ...s.appChoices, [a.id]: v ? 'hosted' : 'own' } })} + testId={`hosted-${a.id}`} + title={a.title} + help={`${a.help} Nothing passes through CoderHelm until someone connects it.`} + /> + ))} update({ sharing: v })} diff --git a/docs/e2e/install.spec.ts b/docs/e2e/install.spec.ts index 9f83a9af..55c8143e 100644 --- a/docs/e2e/install.spec.ts +++ b/docs/e2e/install.spec.ts @@ -591,8 +591,8 @@ test('more options: domain, sender, sign-up and updates go to AWS; a bad hostnam await expect(page.getByLabel('Company email domain')).toHaveCount(0); await page.getByTestId('require-two-factor').check(); await page.getByTestId('auto-update').check(); - await page.getByLabel('Day').selectOption('daily'); - await page.getByLabel('Hour').selectOption('02:00'); + await page.getByLabel('Day', { exact: true }).selectOption('daily'); + await page.getByLabel('Hour', { exact: true }).selectOption('02:00'); await page.getByLabel('Time zone').fill('Europe/Berlin'); await pickModels(page); await page.getByTestId('launch').click(); @@ -958,6 +958,8 @@ test('hybrid: registers, sends the choices and claims the name by itself, then f await expect.poll(() => h.calls.map((c) => c.path)).toContain('/name'); const settings = h.calls.find((c) => c.path === '/settings')!; expect(settings.body).toMatchObject({ github_mode: 'hosted', sharing: { enabled: false, payloads: false } }); + // Every Other apps tool on CoderHelm's app, as the guide defaults them. + expect(settings.body.apps).toEqual({ jira: 'coderhelm', notion: 'coderhelm', confluence: 'coderhelm', google_drive: 'coderhelm' }); expect(h.calls.find((c) => c.path === '/name')!.body.name).toBe('example-co'); m.setup = withHybrid(setupDoc(HOSTED_GH), REG_OK, nameCheck('wait', 'cert_pending')); await expect(page.getByTestId('address-status')).toContainText('Waiting for AWS to issue the certificate'); @@ -1140,7 +1142,7 @@ test('hybrid Jira: the toggle sits next to GitHub, on by default, can be turned await page.locator('[data-setup="hybrid"]').click(); const options = page.getByTestId('hybrid-options'); await expect(jira).toBeChecked(); - await expect(options.locator('label')).toHaveText([/Use CoderHelm’s GitHub App/, /Use CoderHelm’s Jira app/, /Share delivery data/]); + await expect(options.locator('label')).toHaveText([/Use CoderHelm’s GitHub App/, /Use CoderHelm’s Jira app/, /Use CoderHelm’s Notion app/, /Use CoderHelm’s Confluence app/, /Use CoderHelm’s Google Drive app/, /Share delivery data/]); await expect(options.locator('label').nth(1)).toContainText('your install never holds the app’s secret'); await expect(options.locator('label').nth(1)).toContainText('Events come through CoderHelm, checked and re-signed'); // The whole row is the control, with the hand cursor. @@ -1165,6 +1167,34 @@ test('hybrid Jira: the toggle sits next to GitHub, on by default, can be turned await expect(page.getByTestId('hosted-jira')).toBeChecked(); }); +test('hybrid other apps: Notion, Confluence and Google Drive are on by default, each says what passes through CoderHelm, and fully private turns them off', async ({ page }) => { + await mock(page, newMock()); + await mockHybrid(page, newHybrid()); + await page.goto('/self-host/install/'); + const options = page.getByTestId('hybrid-options'); + for (const id of ['notion', 'confluence', 'google_drive']) await expect(page.getByTestId(`hosted-${id}`)).toBeChecked(); + const notion = options.locator('label', { hasText: 'Use CoderHelm’s Notion app' }); + await expect(notion).toContainText('CoderHelm keeps the sign-in (encrypted) and hands your install an access token when it syncs.'); + await expect(notion).toContainText('Nothing passes through CoderHelm until someone connects it.'); + await expect(options.locator('label', { hasText: 'Use CoderHelm’s Google Drive app' })).toContainText('read-only Drive access'); + await notion.click(); + await expect(page.getByTestId('hosted-notion')).not.toBeChecked(); + await expect(page.getByTestId('hosted-confluence')).toBeChecked(); + // Fully private hides them; hybrid again brings every one back on. + await page.locator('[data-setup="private"]').click(); + await expect(page.getByTestId('hosted-notion')).toHaveCount(0); + await page.locator('[data-setup="hybrid"]').click(); + for (const id of ['notion', 'confluence', 'google_drive']) await expect(page.getByTestId(`hosted-${id}`)).toBeChecked(); +}); + +test('hybrid other apps: the choices are applied to the install as it registers, a tool turned off as its own app', async ({ page }) => { + const m = newMock({ setup: withHybrid(setupDoc(NO_APP), REG_OK) }); + const h = newHybrid(); + await mockHybrid(page, h); + await seeded(page, m, { ...JIRA_STATE, jiraChoice: 'own', appChoices: { notion: 'hosted', confluence: 'own', google_drive: 'hosted' } }); + await expect.poll(() => h.calls.find((c) => c.path === '/settings')?.body.apps).toEqual({ jira: 'own', notion: 'coderhelm', confluence: 'own', google_drive: 'coderhelm' }); +}); + test('hybrid Jira: the guide turns on Link through CoderHelm with the setup key, and only when chosen', async ({ page, browser }) => { const m = newMock({ setup: withHybrid(setupDoc(NO_APP), REG_OK) }); const h = newHybrid(); diff --git a/docs/lib/install/core.ts b/docs/lib/install/core.ts index 2226addd..508cf0b8 100644 --- a/docs/lib/install/core.ts +++ b/docs/lib/install/core.ts @@ -66,11 +66,47 @@ export const SETUPS: { id: Setup; title: string; tag?: string; gets: string[]; t id: 'hybrid', title: 'Hybrid', tag: 'Easiest', - gets: ['yourname.coderhelm.com, set up for you', 'CoderHelm\u2019s GitHub App: install it and you\u2019re done', 'CoderHelm\u2019s Jira app for your Jira site, linked in a minute', 'Your code and data still stay in your AWS account'], + gets: ['yourname.coderhelm.com, set up for you', 'CoderHelm\u2019s GitHub App: install it and you\u2019re done', 'CoderHelm\u2019s Jira app for your Jira site, linked in a minute', 'CoderHelm\u2019s Notion, Confluence and Google Drive apps: sign in with one click', 'Your code and data still stay in your AWS account'], tradeoff: 'GitHub and Jira events pass through CoderHelm on their way to you (checked, re-signed, never stored past retries).', }, ]; +// ── Other apps: CoderHelm's app or the install's own, per tool ────────── + +/** The tools besides GitHub and Jira a hybrid install can use CoderHelm's app for. */ +export type OtherApp = 'notion' | 'confluence' | 'google_drive'; + +export type AppChoices = Record; + +/** + * Each tool's toggle under What CoderHelm sets up for you. The help is the + * line Settings, System, Hybrid, Other apps shows for "Through Coderhelm". + */ +export const OTHER_APPS: { id: OtherApp; title: string; help: string }[] = [ + { id: 'notion', title: 'Use CoderHelm\u2019s Notion app', help: 'You sign in through CoderHelm\u2019s Notion integration. CoderHelm keeps the sign-in (encrypted) and hands your install an access token when it syncs.' }, + { id: 'confluence', title: 'Use CoderHelm\u2019s Confluence app', help: 'You sign in through CoderHelm\u2019s Atlassian app. CoderHelm keeps the sign-in (encrypted) and hands your install access tokens that expire within the hour.' }, + { id: 'google_drive', title: 'Use CoderHelm\u2019s Google Drive app', help: 'You sign in through CoderHelm\u2019s Google app (read-only Drive access). CoderHelm keeps the sign-in (encrypted) and hands your install access tokens that expire within the hour.' }, +]; + +export const ALL_HOSTED_APPS: AppChoices = { notion: 'hosted', confluence: 'hosted', google_drive: 'hosted' }; +export const ALL_OWN_APPS: AppChoices = { notion: 'own', confluence: 'own', google_drive: 'own' }; + +/** + * The Other apps choices as the install takes them (`apps` on + * /api/setup/hybrid/settings): every tool, Jira included. A tool with no + * choice saved is CoderHelm's app, like the install's own default. + */ +export function appsBody(s: Partial>): Record<'jira' | OtherApp, 'coderhelm' | 'own'> { + const c = { ...ALL_HOSTED_APPS, ...s.appChoices }; + const one = (v: 'own' | 'hosted' | undefined) => (v === 'own' ? 'own' : 'coderhelm'); + return { jira: one(s.jiraChoice), notion: one(c.notion), confluence: one(c.confluence), google_drive: one(c.google_drive) }; +} + +/** Does any choice need the install registered with CoderHelm? */ +export function wantsHybrid(s: Partial>): boolean { + return s.domainChoice === 'coderhelm' || s.githubChoice === 'hosted' || s.jiraChoice === 'hosted' || s.emailTransport === 'coderhelm' || Object.values(s.appChoices ?? {}).includes('hosted'); +} + /** The suffix every CoderHelm address has. */ // ── Your data: start fresh, or move a team from hosted CoderHelm ──────── @@ -262,6 +298,12 @@ export interface InstallState { * through CoderHelm"). Older saved guides have none: their own. */ jiraChoice?: 'own' | 'hosted'; + /** + * Other apps, per tool (Settings, System, Hybrid, Other apps): CoderHelm's + * app or their own. Sent when the install registers. Older saved guides + * have none: they follow the setup they were saved with. + */ + appChoices?: AppChoices; /** The Jira site to link, as typed (example.atlassian.net). */ jiraSite?: string; /** They chose to link the Jira site later, in Settings. */ @@ -346,6 +388,7 @@ export function newState(over: Partial = {}): InstallState { coderhelmName: '', githubChoice: 'hosted', jiraChoice: 'hosted', + appChoices: { ...ALL_HOSTED_APPS }, jiraSite: '', jiraSkipped: false, dataChoice: 'fresh', @@ -1024,7 +1067,7 @@ export function parseStored(raw: string | null): InstallState | null { // Saved before the setup choice existed: that guide was fully private // (the old default), so the hybrid default never applies to it. const before = v.setup !== 'private' && v.setup !== 'hybrid' - ? { setup: 'private' as const, domainChoice: 'aws' as const, githubChoice: 'own' as const, jiraChoice: 'own' as const } + ? { setup: 'private' as const, domainChoice: 'aws' as const, githubChoice: 'own' as const, jiraChoice: 'own' as const, appChoices: { ...ALL_OWN_APPS } } : {}; const s: InstallState = { ...newState(), ...before, ...v }; // Saved before the Your data step existed: the guide goes on as it was. @@ -1038,6 +1081,12 @@ export function parseStored(raw: string | null): InstallState | null { if (v.jiraChoice !== 'own' && v.jiraChoice !== 'hosted') { s.jiraChoice = s.setup === 'hybrid' || s.githubChoice === 'hosted' ? 'hosted' : 'own'; } + // Saved before the Other apps choices: on for hybrid, like the install's default. + if (!v.appChoices || typeof v.appChoices !== 'object') { + s.appChoices = s.setup === 'hybrid' ? { ...ALL_HOSTED_APPS } : { ...ALL_OWN_APPS }; + } else { + s.appChoices = { ...ALL_HOSTED_APPS, ...v.appChoices }; + } return s; } catch { return null;