From 332bb5d5fa3dd33bd9731d7d171f9d810fdcf81e Mon Sep 17 00:00:00 2001 From: Guilhem Lemouel Date: Mon, 2 Nov 2026 01:49:58 -0800 Subject: [PATCH] fix: refuse a service account name already pending in the tab Co-Authored-By: Claude Opus 5.5 --- .../components/access/NewServiceAccountForm.svelte | 12 +++++++++--- .../lib/components/access/serviceAccounts.svelte.ts | 7 +++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/components/access/NewServiceAccountForm.svelte b/frontend/src/lib/components/access/NewServiceAccountForm.svelte index b10450571d..a4d20265db 100644 --- a/frontend/src/lib/components/access/NewServiceAccountForm.svelte +++ b/frontend/src/lib/components/access/NewServiceAccountForm.svelte @@ -6,7 +6,7 @@ import { FolderService, UserService } from '$lib/gen' import { Database, Folder, Info, KeyRound } from 'lucide-svelte' import { detectNeeds, type NeedsSource, type RunnableKind } from './detectNeeds' - import { setPendingServiceAccount, type Grant } from './serviceAccounts.svelte' + import { pendingUsernames, setPendingServiceAccount, type Grant } from './serviceAccounts.svelte' let { workspace, @@ -41,6 +41,8 @@ /** Whether the item's folder already names default users; unknown until loaded. */ let folderHasDefaults: boolean | undefined = $state(undefined) let usernames: string[] = $state([]) + // Another item in this tab may already plan to create a name; reusing it would merge both. + const pendingNames = $derived(pendingUsernames(workspace)) let folderNames: string[] = $state([]) let detecting = $state(true) let detectionErrors: string[] = $state([]) @@ -55,7 +57,9 @@ folderNames = folders const wanted = initialName?.trim() ? base : `${base.replace(/[^a-zA-Z0-9_]/g, '_')}_bot` let candidate = wanted - for (let i = 2; users.includes(candidate); i++) candidate = `${wanted}_${i}` + const pendingAtStart = pendingUsernames(workspace) + for (let i = 2; users.includes(candidate) || pendingAtStart.includes(candidate); i++) + candidate = `${wanted}_${i}` name = candidate if (itemFolder) { rows = [ @@ -105,7 +109,9 @@ ? 'Letters, digits and _ only' : usernames.includes(name) ? `u/${name} already exists` - : undefined + : pendingNames.includes(name) + ? `u/${name} is already waiting to be created at deploy` + : undefined ) const principal = $derived(`u/${name}`) const chosen = $derived(rows.filter((r) => r.checked)) diff --git a/frontend/src/lib/components/access/serviceAccounts.svelte.ts b/frontend/src/lib/components/access/serviceAccounts.svelte.ts index c79f55643c..5cf5d6c4b1 100644 --- a/frontend/src/lib/components/access/serviceAccounts.svelte.ts +++ b/frontend/src/lib/components/access/serviceAccounts.svelte.ts @@ -49,6 +49,13 @@ export function getPendingServiceAccount( return permissionedAs ? pending.get(key(workspace, permissionedAs)) : undefined } +/** Usernames this tab plans to create in `workspace`, which a new account must not reuse. */ +export function pendingUsernames(workspace: string): string[] { + return [...pending.entries()] + .filter(([k]) => k.startsWith(`${workspace}:`)) + .map(([, a]) => a.username) +} + /** Clears a run-as that names a placeholder email this tab no longer holds an account for, as a * draft saved before its deploy does after a reload: the server knows no such user. */ export function dropStalePending(