diff --git a/docs/release-control/v6/internal/subsystems/cloud-paid.md b/docs/release-control/v6/internal/subsystems/cloud-paid.md index 2a4cd84e6f..79530e44b3 100644 --- a/docs/release-control/v6/internal/subsystems/cloud-paid.md +++ b/docs/release-control/v6/internal/subsystems/cloud-paid.md @@ -15,6 +15,24 @@ ## Purpose +### Client creation uses one native form submission + +The existing MSP Add client form submits through its account-scoped submit +handler, so Enter in the name field and activating Add client use the same +request. Empty input uses native required-field validation; whitespace-only +names still return focus without a write. Cancel remains a non-submit button, +and unrelated workspace handoff forms retain their ordinary submission. + +Each account admits one pending create request. Its name and action controls +are disabled and the form reports busy until the request settles. A failed +request preserves the name, clears busy state and restores explicit retry; +there is no automatic create retry. Existing account permissions, API payload, +workspace identity, licence checks and the created-client onboarding view are +unchanged. Normal portal controller, runtime, view and shell tests cover these +boundaries. Comparable desktop/phone captures and native-bundle browser checks +cover Enter, pointer activation, pending duplicates, failure and deliberate retry; +they do not establish live licensing, TLS or installed client recovery. + ### Control-plane account responses are not HTTP-cacheable by default `CPSecurityHeaders`, which wraps the registered control-plane routes in the diff --git a/frontend-modern/browser-verification/00286a132c918a52.json b/frontend-modern/browser-verification/00286a132c918a52.json new file mode 100644 index 0000000000..2750c4a2f7 --- /dev/null +++ b/frontend-modern/browser-verification/00286a132c918a52.json @@ -0,0 +1,52 @@ +{ + "version": 1, + "base_sha": "90d1b0b059328fdbdd3af0a15457a78dfb52f70d", + "verified_at": "2026-11-04T02:28:35.733119Z", + "result": "passed", + "changed_paths": [ + "internal/cloudcp/portal/dist/build_manifest.json", + "internal/cloudcp/portal/dist/portal_app.js", + "internal/cloudcp/portal/frontend/src/account_controller.ts", + "internal/cloudcp/portal/frontend/src/account_runtime.ts", + "internal/cloudcp/portal/frontend/src/account_view.ts", + "internal/cloudcp/portal/frontend/src/shell_view.ts" + ], + "content_sha256": { + "internal/cloudcp/portal/frontend/src/account_controller.ts": "df24a72c8597254c648727a7638fce0384619c0c9e4d52a7a3173d61e8c97518", + "internal/cloudcp/portal/frontend/src/account_runtime.ts": "4c1842a3d5b6adaaadf84f8c3f4521a2af526baa33eb104f0ebfc0e1ac2d7a4b", + "internal/cloudcp/portal/frontend/src/account_view.ts": "078f0c755458ae1ca217df3d2d553b740e79b060b507b570bf1785594fe45863", + "internal/cloudcp/portal/frontend/src/shell_view.ts": "e294badf253f548c7bd7bf064899d91d6b3d9efb22c12469c99126c919036f04", + "internal/cloudcp/portal/dist/portal_app.js": "9938de1205e37e4277497ce47c42856d16c71345fb77788edc9d49fc3c858714", + "internal/cloudcp/portal/dist/build_manifest.json": "3880cef49389eafdd65c92583888c30d696f290514aab8c90c667e0b28c6ba68" + }, + "routes": [ + "/portal (native embedded template, bundle and CSS; synthetic provider bootstrap and account APIs)" + ], + "viewports": [ + { + "width": 1440, + "height": 1000 + }, + { + "width": 390, + "height": 844 + } + ], + "states": [ + "Comparable light-theme before/after native portal: filled name, after Enter, pending, failed request, created-client onboarding. All twenty retained captures were opened with the native image tool.", + "The unchanged parent sends no request on Enter; the final bundle sends one. Form controls are disabled and aria-busy is true while pending; an additional submit event starts no duplicate request. Failure clears the spinner and busy state, retains the name and restores explicit retry.", + "No status, per-client distinction or existing control is removed, aggregated or moved behind disclosure. Created-client identity, counts, setup instructions and selected row remain visible.", + "Playwright 1.56.1 matches tests/integration lock; Chromium 141.0.7390.37. Before 19 checks, final 31 checks. Real frontend request/response flow with safe fixtures; not an installed control-plane, TLS, licence or original client recovery claim." + ], + "interactions": [ + "Enter in the existing Client name field, pointer submit, controlled HTTP 503, deliberate Enter retry and successful bootstrap refresh/select of the created client.", + "Duplicate submit while the first create is pending; pointer still creates once; Cancel makes no additional request; read-only account has no create control.", + "No horizontal overflow at desktop or 390px; no page exception. Same fixture, en-GB locale, UTC, viewport and light theme for comparable captures. Filled and Enter pairs use identical keyboard interaction; pending/failure/created parent controls use pointer because parent Enter does nothing." + ], + "evidence": [ + "BROWSER-BEFORE.json", + "BROWSER-AFTER.json", + "CAPTURES.md", + "RECEIPTS.md" + ] +} diff --git a/internal/cloudcp/portal/dist/build_manifest.json b/internal/cloudcp/portal/dist/build_manifest.json index 6ac79dc517..ae0d586b6c 100644 --- a/internal/cloudcp/portal/dist/build_manifest.json +++ b/internal/cloudcp/portal/dist/build_manifest.json @@ -1,5 +1,5 @@ { - "source_hash": "b7a70a05954be41554248af9cff592b702f874d2c5a03256ae3a84d100e7bded", + "source_hash": "1c3413c286253b16c71d15d35377f78d12a05623a0dd306d48d140a104e1fbce", "build_inputs": [ "package.json", "tsconfig.json", diff --git a/internal/cloudcp/portal/dist/portal_app.js b/internal/cloudcp/portal/dist/portal_app.js index b1e989da97..96e8d99f46 100644 --- a/internal/cloudcp/portal/dist/portal_app.js +++ b/internal/cloudcp/portal/dist/portal_app.js @@ -712,6 +712,10 @@ var spinner = getElement("ws-spinner-" + accountID); if (!form) return; form.classList.toggle("visible", entry.addWorkspaceOpen); + form.setAttribute("aria-busy", String(entry.createWorkspace.pending)); + form.querySelectorAll("input, button").forEach(function(control) { + control.disabled = entry.createWorkspace.pending; + }); if (spinner) { spinner.hidden = !entry.createWorkspace.pending; } @@ -809,6 +813,15 @@ // src/account_controller.ts function installAccountController(deps) { + document.addEventListener("submit", function(event) { + var form = event.target; + if (!(form instanceof HTMLFormElement) || form.getAttribute("data-account-form") !== "create-workspace") return; + event.preventDefault(); + var accountID = form.getAttribute("data-account-id") || ""; + if (!accountID) return; + deps.setShellSection("workspaces"); + void deps.runtime.createWorkspace(accountID); + }); document.addEventListener("click", function(event) { var target = asHTMLElement(event.target); if (!target) return; @@ -845,11 +858,6 @@ event.preventDefault(); void deps.runtime.inviteMember(accountID); return; - case "create-workspace": - event.preventDefault(); - deps.setShellSection("workspaces"); - void deps.runtime.createWorkspace(accountID); - return; case "select-workspace": event.preventDefault(); deps.setShellSection("workspaces"); @@ -1520,6 +1528,7 @@ return "Your plan limit for " + entity + " is reached" + counts + ". Remove a " + (clientLanguage ? "client" : "workspace") + " or move to a bigger plan to add more."; } var createWorkspace = async function(accountID) { + if (deps.store.getAccountState().byAccountID[accountID]?.createWorkspace.pending) return; var nameEl = getElement("ws-name-" + accountID); if (!nameEl) return; var name = nameEl.value.trim(); @@ -1537,7 +1546,7 @@ deps.store.updateAccountState(function(accountState) { var entry = ensurePortalAccountUIEntry(accountState, accountID); resetMutationState(entry.createWorkspace); - }, { notify: false }); + }); return; } var createdWorkspaceID = created && typeof created.id === "string" ? created.id : ""; @@ -1564,7 +1573,7 @@ deps.store.updateAccountState(function(accountState) { var entry = ensurePortalAccountUIEntry(accountState, accountID); failMutationState(entry.createWorkspace, message); - }, { notify: false }); + }); deps.showToast(message, true); } }; @@ -3687,7 +3696,7 @@ workspaceHeaderActions += '"; } if (account.kind === "msp") { - addWorkspaceForm = '
'; + addWorkspaceForm = '
'; } workspaceManagement = '"; } diff --git a/internal/cloudcp/portal/frontend/src/account_controller.test.ts b/internal/cloudcp/portal/frontend/src/account_controller.test.ts index f7d348bf90..e4a6025ee0 100644 --- a/internal/cloudcp/portal/frontend/src/account_controller.test.ts +++ b/internal/cloudcp/portal/frontend/src/account_controller.test.ts @@ -35,7 +35,7 @@ describe('account controller', function() { '' + '' + '' + - '' + + '
' + '' + '' + '' + @@ -62,8 +62,28 @@ describe('account controller', function() { document.getElementById('invite')?.dispatchEvent(new MouseEvent('click', { bubbles: true })); expect(runtime.inviteMember).toHaveBeenCalledWith('acct_1'); - document.getElementById('create')?.dispatchEvent(new MouseEvent('click', { bubbles: true })); + (document.getElementById('create') as HTMLButtonElement).click(); expect(runtime.createWorkspace).toHaveBeenCalledWith('acct_1'); + expect(runtime.createWorkspace).toHaveBeenCalledTimes(1); + + // The submit event, not a key handler or button-only click, owns creation. + var submit = new Event('submit', { bubbles: true, cancelable: true }); + document.getElementById('create-form')?.dispatchEvent(submit); + expect(submit.defaultPrevented).toBe(true); + expect(runtime.createWorkspace).toHaveBeenCalledTimes(2); + + var handoff = document.createElement('form'); + document.body.appendChild(handoff); + var handoffSubmit = new Event('submit', { bubbles: true, cancelable: true }); + handoff.dispatchEvent(handoffSubmit); + expect(handoffSubmit.defaultPrevented).toBe(false); + expect(runtime.createWorkspace).toHaveBeenCalledTimes(2); + + document.getElementById('create-form')?.setAttribute('data-account-id', ''); + var missingAccount = new Event('submit', { bubbles: true, cancelable: true }); + document.getElementById('create-form')?.dispatchEvent(missingAccount); + expect(missingAccount.defaultPrevented).toBe(true); + expect(runtime.createWorkspace).toHaveBeenCalledTimes(2); document.getElementById('select')?.dispatchEvent(new MouseEvent('click', { bubbles: true })); expect(runtime.selectWorkspace).toHaveBeenCalledWith('acct_1', 'ws_1'); diff --git a/internal/cloudcp/portal/frontend/src/account_controller.ts b/internal/cloudcp/portal/frontend/src/account_controller.ts index 626ad0d053..8100635936 100644 --- a/internal/cloudcp/portal/frontend/src/account_controller.ts +++ b/internal/cloudcp/portal/frontend/src/account_controller.ts @@ -7,6 +7,16 @@ export interface AccountControllerDeps { } export function installAccountController(deps: AccountControllerDeps): void { + document.addEventListener('submit', function(event) { + var form = event.target; + if (!(form instanceof HTMLFormElement) || form.getAttribute('data-account-form') !== 'create-workspace') return; + event.preventDefault(); + var accountID = form.getAttribute('data-account-id') || ''; + if (!accountID) return; + deps.setShellSection('workspaces'); + void deps.runtime.createWorkspace(accountID); + }); + document.addEventListener('click', function(event) { var target = asHTMLElement(event.target); if (!target) return; @@ -44,11 +54,6 @@ export function installAccountController(deps: AccountControllerDeps): void { event.preventDefault(); void deps.runtime.inviteMember(accountID); return; - case 'create-workspace': - event.preventDefault(); - deps.setShellSection('workspaces'); - void deps.runtime.createWorkspace(accountID); - return; case 'select-workspace': event.preventDefault(); deps.setShellSection('workspaces'); diff --git a/internal/cloudcp/portal/frontend/src/account_runtime.test.ts b/internal/cloudcp/portal/frontend/src/account_runtime.test.ts index 37cf6fbee8..840d574765 100644 --- a/internal/cloudcp/portal/frontend/src/account_runtime.test.ts +++ b/internal/cloudcp/portal/frontend/src/account_runtime.test.ts @@ -126,6 +126,46 @@ describe('account runtime', function() { expect((document.getElementById('ws-spinner-acct_1') as HTMLElement).hidden).toBe(true); }); + it('admits one create request and restores the named form for explicit retry after failure', async function() { + deps.store.setBootstrap({ authenticated: true, email: 'owner@example.com', accounts: [{ + id: 'acct_1', name: 'Example MSP', kind: 'msp', kind_label: 'MSP', role: 'owner', + can_manage: true, has_billing: false, members: [], workspaces: [], + }] }); + var rejectRequests: Array<(error: Error) => void> = []; + vi.stubGlobal('fetch', vi.fn().mockImplementation(function() { + return new Promise(function(_resolve, reject) { rejectRequests.push(reject); }); + })); + document.body.innerHTML = '
'; + var first = runtime.createWorkspace('acct_1'); + await flushAsync(); + var duplicate = runtime.createWorkspace('acct_1'); + await flushAsync(); + var requestCount = vi.mocked(fetch).mock.calls.length; + var pendingDisabled = (document.getElementById('ws-name-acct_1') as HTMLInputElement).disabled; + rejectRequests.forEach(function(reject) { reject(new Error('Temporary failure')); }); + await Promise.all([first, duplicate]); + expect(requestCount).toBe(1); + expect(pendingDisabled).toBe(true); + expect(deps.store.getAccountState().byAccountID.acct_1.createWorkspace.pending).toBe(false); + expect((document.getElementById('ws-spinner-acct_1') as HTMLElement).hidden).toBe(true); + expect((document.getElementById('ws-name-acct_1') as HTMLInputElement).disabled).toBe(false); + expect((document.getElementById('ws-name-acct_1') as HTMLInputElement).value).toBe('Acme Clinic'); + expect(deps.showToast).toHaveBeenCalledWith('Failed to create workspace.', true); + expect(fetch).toHaveBeenCalledTimes(1); + vi.mocked(fetch).mockRejectedValueOnce(new Error('Deliberate retry failure')); + await runtime.createWorkspace('acct_1'); + expect(fetch).toHaveBeenCalledTimes(2); + expect(deps.store.getAccountState().byAccountID.acct_1.createWorkspace.pending).toBe(false); + }); + + it('does not submit a whitespace-only client name', async function() { + vi.stubGlobal('fetch', vi.fn()); + document.body.innerHTML = ''; + await runtime.createWorkspace('acct_1'); + expect(fetch).not.toHaveBeenCalled(); + expect(document.activeElement?.id).toBe('ws-name-acct_1'); + }); + it('selects a workspace and routes explicit workspace actions through the management panel', async function() { vi.stubGlobal('fetch', vi.fn().mockResolvedValue(jsonResponse({}))); var confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(true); diff --git a/internal/cloudcp/portal/frontend/src/account_runtime.ts b/internal/cloudcp/portal/frontend/src/account_runtime.ts index 7d0bf77672..23a27d47c5 100644 --- a/internal/cloudcp/portal/frontend/src/account_runtime.ts +++ b/internal/cloudcp/portal/frontend/src/account_runtime.ts @@ -193,6 +193,7 @@ export function installAccountRuntime(deps: AccountRuntimeDeps): AccountRuntime } var createWorkspace = async function(accountID: string): Promise { + if (deps.store.getAccountState().byAccountID[accountID]?.createWorkspace.pending) return; var nameEl = getElement('ws-name-' + accountID); if (!nameEl) return; var name = nameEl.value.trim(); @@ -210,7 +211,7 @@ export function installAccountRuntime(deps: AccountRuntimeDeps): AccountRuntime deps.store.updateAccountState(function(accountState) { var entry = ensurePortalAccountUIEntry(accountState, accountID); resetMutationState(entry.createWorkspace); - }, { notify: false }); + }); return; } var createdWorkspaceID = created && typeof created.id === 'string' ? created.id : ''; @@ -237,7 +238,7 @@ export function installAccountRuntime(deps: AccountRuntimeDeps): AccountRuntime deps.store.updateAccountState(function(accountState) { var entry = ensurePortalAccountUIEntry(accountState, accountID); failMutationState(entry.createWorkspace, message); - }, { notify: false }); + }); deps.showToast(message, true); } }; diff --git a/internal/cloudcp/portal/frontend/src/account_view.test.ts b/internal/cloudcp/portal/frontend/src/account_view.test.ts index 85e5e349fc..e6d2c60baf 100644 --- a/internal/cloudcp/portal/frontend/src/account_view.test.ts +++ b/internal/cloudcp/portal/frontend/src/account_view.test.ts @@ -103,8 +103,8 @@ describe('account view', function() { it('renders add-workspace visibility from account UI state', function() { document.body.innerHTML = - '
' + - ''; + '
' + + '
'; renderAddWorkspaceSection('acct_1', createEntry({ addWorkspaceOpen: true })); expect(document.getElementById('add-ws-form-acct_1')?.classList.contains('visible')).toBe(true); @@ -115,6 +115,15 @@ describe('account view', function() { createWorkspace: { pending: true, error: '' }, })); expect((document.getElementById('ws-spinner-acct_1') as HTMLElement).hidden).toBe(false); + expect(document.querySelector('#add-ws-form-acct_1')?.getAttribute('aria-busy')).toBe('true'); + expect((document.querySelector('#add-ws-form-acct_1 input') as HTMLInputElement).disabled).toBe(true); + expect(Array.from(document.querySelectorAll('#add-ws-form-acct_1 button')).every(function(button) { return button.disabled; })).toBe(true); + + renderAddWorkspaceSection('acct_1', createEntry({ addWorkspaceOpen: true, createWorkspace: { pending: false, error: 'Try again' } })); + expect((document.querySelector('#add-ws-form-acct_1 input') as HTMLInputElement).disabled).toBe(false); + expect((document.querySelector('#add-ws-form-acct_1 input') as HTMLInputElement).value).toBe('Acme Clinic'); + expect(Array.from(document.querySelectorAll('#add-ws-form-acct_1 button')).every(function(button) { return !button.disabled; })).toBe(true); + expect(document.querySelector('#add-ws-form-acct_1')?.getAttribute('aria-busy')).toBe('false'); renderAddWorkspaceSection('acct_1', createEntry({ addWorkspaceOpen: false })); expect(document.getElementById('add-ws-form-acct_1')?.classList.contains('visible')).toBe(false); diff --git a/internal/cloudcp/portal/frontend/src/account_view.ts b/internal/cloudcp/portal/frontend/src/account_view.ts index 718b8ed227..34b1bbffe7 100644 --- a/internal/cloudcp/portal/frontend/src/account_view.ts +++ b/internal/cloudcp/portal/frontend/src/account_view.ts @@ -465,6 +465,10 @@ export function renderAddWorkspaceSection(accountID: string, entry: PortalAccoun var spinner = getElement('ws-spinner-' + accountID); if (!form) return; form.classList.toggle('visible', entry.addWorkspaceOpen); + form.setAttribute('aria-busy', String(entry.createWorkspace.pending)); + form.querySelectorAll('input, button').forEach(function(control) { + control.disabled = entry.createWorkspace.pending; + }); if (spinner) { spinner.hidden = !entry.createWorkspace.pending; } diff --git a/internal/cloudcp/portal/frontend/src/shell_view.test.ts b/internal/cloudcp/portal/frontend/src/shell_view.test.ts index a715b7cb07..51c7010a2b 100644 --- a/internal/cloudcp/portal/frontend/src/shell_view.test.ts +++ b/internal/cloudcp/portal/frontend/src/shell_view.test.ts @@ -64,6 +64,27 @@ function createContext(overrides: Partial = {}): ShellViewCont } describe('shell view', function() { + it('renders native client creation forms without intercepting workspace handoffs', function() { + var account = { + id: 'acct_1', name: 'Example MSP', kind: 'msp', kind_label: 'MSP', + role: 'owner', can_manage: true, has_billing: false, members: [], workspaces: [], + }; + var root = document.createElement('div'); + root.innerHTML = renderAuthenticatedPortalHTML(createContext({ bootstrap: createBootstrap({ accounts: [account] }) })); + var form = root.querySelector('#add-ws-form-acct_1') as HTMLFormElement; + expect(form).toBeInstanceOf(HTMLFormElement); + expect(form.getAttribute('data-account-form')).toBe('create-workspace'); + expect(form.getAttribute('data-account-id')).toBe('acct_1'); + expect(form.querySelector('input')?.required).toBe(true); + expect(form.querySelector('button.btn-primary')?.getAttribute('type')).toBe('submit'); + expect(form.querySelector('button.btn-secondary')?.getAttribute('type')).toBe('button'); + expect(form.querySelector('[data-action="create-workspace"]')).toBeNull(); + expect(form.querySelector('form')).toBeNull(); + + root.innerHTML = renderAuthenticatedPortalHTML(createContext({ bootstrap: createBootstrap({ accounts: [{ ...account, role: 'read_only', can_manage: false }] }) })); + expect(root.querySelector('[data-account-form="create-workspace"]')).toBeNull(); + }); + it('renders authenticated header with account email and sign-out button', function() { var html = renderHeaderHTML(createContext()); diff --git a/internal/cloudcp/portal/frontend/src/shell_view.ts b/internal/cloudcp/portal/frontend/src/shell_view.ts index 8ab1f97c51..bcceef6e6e 100644 --- a/internal/cloudcp/portal/frontend/src/shell_view.ts +++ b/internal/cloudcp/portal/frontend/src/shell_view.ts @@ -1106,7 +1106,9 @@ function renderAccountWorkspaceSection(account: PortalAccountSummary, accountAPI if (account.kind === 'msp') { addWorkspaceForm = - '
' + '' + '' + + '" placeholder="Acme Corp" maxlength="80" autocomplete="off" required>' + '
' + - '' + + '' + '' + @@ -1126,7 +1126,7 @@ function renderAccountWorkspaceSection(account: PortalAccountSummary, accountAPI escapeAttr(account.id) + '" hidden>
' + '
' + - ''; + ''; } workspaceManagement = '