From 981baeda90e758feecda7f89a6f83d0aa479fb00 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Fri, 30 Oct 2026 04:17:04 +0100 Subject: [PATCH] fix: share and first deploy in ai sessions, app access in settings (#12112) * fix: offer share and first-deploy in ai sessions and app access in settings Co-Authored-By: Claude Opus 5.5 * fix: keep share and first-deploy out of embedded editors Co-Authored-By: Claude Opus 5.5 * feat: show a public or guest app's links after its first deploy Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- .../src/lib/components/FlowBuilder.svelte | 17 ++- .../src/lib/components/ScriptBuilder.svelte | 11 +- .../apps/editor/AppEditorHeader.svelte | 47 +++++--- .../apps/editor/AppSettingsDrawer.svelte | 63 ++++++++++- .../itemSettings/AppAccessSection.svelte | 85 ++++++++------ .../itemSettings/AppLinksModal.svelte | 100 ++++++++++++++++ .../itemSettings/DeployedAppAccess.svelte | 107 ++++++++++++++++++ .../itemSettings/FirstDeployDialog.svelte | 10 ++ .../itemSettings/ShareDialog.svelte | 100 ++-------------- .../lib/components/itemSettings/appAccess.ts | 11 ++ .../raw_apps/RawAppEditorHeader.svelte | 46 +++++--- .../src/routes/(root)/(logged)/+layout.svelte | 2 + 12 files changed, 434 insertions(+), 165 deletions(-) create mode 100644 frontend/src/lib/components/itemSettings/AppLinksModal.svelte create mode 100644 frontend/src/lib/components/itemSettings/DeployedAppAccess.svelte diff --git a/frontend/src/lib/components/FlowBuilder.svelte b/frontend/src/lib/components/FlowBuilder.svelte index a18d93893e..d61996c3db 100644 --- a/frontend/src/lib/components/FlowBuilder.svelte +++ b/frontend/src/lib/components/FlowBuilder.svelte @@ -371,6 +371,9 @@ // in the shared /sessions URL under the session's own workspace identity, so // presence keyed on that URL leaks a phantom self-badge. Hide it here. const inSessionPane = !!getContext('aiChatManager') + // Share and the first-deploy dialog belong to Windmill's own editors: an embedding host (the + // SDK, the flow drawer) can lock the path, which the dialog would let the user change. + const offersSharing = $derived(ownsPageHeader || inSessionPane) setFlowPanelPlacementTelemetry(!inSessionPane) @@ -507,9 +510,9 @@ async function handleSaveFlow(deploymentMsg?: string) { pendingFirstDeploy = undefined - if (ownsPageHeader && neverDeployed) { + if (neverDeployed && firstDeployDialog) { // The dialog also asks who the flow runs on behalf of, for the path it chose. - const choice = await firstDeployDialog?.ask({ + const choice = await firstDeployDialog.ask({ kind: 'flow', summary: flowStore.val.summary ?? '', path: $pathStore, @@ -1721,7 +1724,7 @@ {@render children?.()} -{#if ownsPageHeader} +{#if offersSharing} {/if} @@ -1867,6 +1870,14 @@ {@render previewButtons()} {/if} + {#if offersSharing} + + {/if} await handleSaveFlow(detail)} diff --git a/frontend/src/lib/components/ScriptBuilder.svelte b/frontend/src/lib/components/ScriptBuilder.svelte index fdbf402ae1..8b847c7c8b 100644 --- a/frontend/src/lib/components/ScriptBuilder.svelte +++ b/frontend/src/lib/components/ScriptBuilder.svelte @@ -697,9 +697,9 @@ // Every deploy path of the full-page editor comes through here, the message popover and // "Deploy & Stay here" included. pendingFirstDeploy = undefined - if (ownsPageHeader && neverDeployed) { + if (neverDeployed && firstDeployDialog) { // The dialog also asks who the script runs on behalf of, for the path it chose. - const choice = await firstDeployDialog?.ask({ + const choice = await firstDeployDialog.ask({ kind: 'script', summary: script.summary, path: script.path, @@ -1098,6 +1098,9 @@ // details page itself, so it switches the tab instead of leaving. Diff is exposed // as a standalone top-bar button (rendered independently of the pane), not here. const inSessionPane = !!getContext('aiChatManager') + // Share and the first-deploy dialog belong to Windmill's own editors: an embedding host (the + // SDK) can lock the path, which the dialog would let the user change. + const offersSharing = $derived(ownsPageHeader || inSessionPane) /** Names the version on the deployed side of the diff. Without it the reader is * shown two panes and told nothing about what the left one is — which matters @@ -1584,7 +1587,7 @@ onCanceled={() => (perpetualRunsToConfirm = undefined)} /> -{#if ownsPageHeader} +{#if offersSharing} {/if} @@ -2327,7 +2330,7 @@ {#if ownsPageHeader} {/if} - {#if ownsPageHeader && !phoneTopbar} + {#if offersSharing && !phoneTopbar} initialLabels)) $effect(() => { @@ -1040,20 +1061,12 @@ bind:pathError bind:newEditedPath bind:labels + bind:customPath + onAppChanged={applyAppAccess} /> -{#if ownsPageHeader} - { - policy.execution_mode = row.policy.execution_mode - customPath = row.custom_path ?? undefined - if (savedApp) { - savedApp.policy = { ...savedApp.policy, execution_mode: row.policy.execution_mode } - savedApp.custom_path = row.custom_path ?? undefined - } - }} - /> +{#if offersSharing} + {/if} @@ -1423,7 +1436,7 @@ Settings - {#if ownsPageHeader} + {#if offersSharing} {/if} {/if} diff --git a/frontend/src/lib/components/apps/editor/AppSettingsDrawer.svelte b/frontend/src/lib/components/apps/editor/AppSettingsDrawer.svelte index 2f6d480f86..dd332a8f93 100644 --- a/frontend/src/lib/components/apps/editor/AppSettingsDrawer.svelte +++ b/frontend/src/lib/components/apps/editor/AppSettingsDrawer.svelte @@ -19,6 +19,10 @@ import { FRONTEND_SDK_SCOPES, sdkScopesToConfirm } from '$lib/components/raw_apps/sdkScopes' import { logFeatureUsage } from '$lib/utils/featureUsage' import { useOperatingWorkspace } from '$lib/components/operatingWorkspace.svelte' + import AppAccessSection from '$lib/components/itemSettings/AppAccessSection.svelte' + import DeployedAppAccess from '$lib/components/itemSettings/DeployedAppAccess.svelte' + import { accessModeOf } from '$lib/components/itemSettings/appAccess' + import { AppService, type AppWithLastVersion } from '$lib/gen' const operatingWorkspaceStore = useOperatingWorkspace() const roleCaps = useRoleCapabilities() @@ -37,7 +41,9 @@ labels = $bindable(), rawApp = false, newApp = false, - operatingWorkspace = undefined + operatingWorkspace = undefined, + customPath = $bindable(), + onAppChanged }: { open: boolean /** Mutated in place; deployed with the app, like every other setting here. */ @@ -57,6 +63,10 @@ /** Workspace the app is deployed to. The path and on-behalf-of lookups target it; * defaults to the operating workspace. */ operatingWorkspace?: string + /** Taken by the first deploy. A deployed app's custom URL is written at once instead. */ + customPath?: string | undefined + /** Called after a write to the deployed app row, with the row as it now is. */ + onAppChanged?: (row: AppWithLastVersion) => void } = $props() let body: HTMLElement | undefined = $state() @@ -73,6 +83,23 @@ let path: Path | undefined = $state(undefined) let dirtyPath = $state(false) + + // Who can open a deployed app is not deployed with it: it is read from, and written to, the + // deployed row, as in Share. + let deployedPath = $derived(newApp ? undefined : savedApp?.path) + let deployedApp: AppWithLastVersion | undefined = $state() + async function loadDeployedApp() { + const asked = deployedPath + if (!asked || !opWs) return + const row = await AppService.getAppLiteByPath({ workspace: opWs, path: asked }) + if (deployedPath === asked) deployedApp = row + } + $effect(() => { + if (open && deployedPath) { + deployedApp = undefined + loadDeployedApp().catch(() => {}) + } + }) {#snippet sandboxHint()} @@ -149,6 +176,40 @@ +
+
+ {#if deployedPath} + {#if deployedApp} + + Changes here apply to the deployed app right away. + + + {:else} + Loading… + {/if} + {:else} + { + policy.execution_mode = m + }} + {customPath} + onCustomPathChange={(p) => { + customPath = p ?? undefined + }} + /> + {/if} +
+
+
{#snippet labelExtra()} void | Promise - /** Links, embedding and the custom URL, which exist only for a deployed app. */ - deployed?: { - customPath: string | undefined - onCustomPathChange: (customPath: string | null) => Promise - } + /** The link, the secret URL and embedding, which exist only once the app is deployed. */ + deployed?: boolean + customPath?: string | undefined + /** Shows the custom URL. On a deployed app it writes at once; before the first deploy it is + * taken by the create. */ + onCustomPathChange?: (customPath: string | null) => void | Promise disabled?: boolean } @@ -38,7 +39,9 @@ rawApp = false, mode, onModeChange, - deployed, + deployed = false, + customPath, + onCustomPathChange, disabled = false }: Props = $props() @@ -84,10 +87,12 @@ WorkspaceService.getGuestUsage({ workspace }) .then((u) => (guestUsage = u)) .catch(() => (guestUsage = undefined)) + if (onCustomPathChange) { + SettingService.getGlobal({ key: 'app_workspaced_route' }) + .then((s) => (globalWorkspacedRoute = (s as boolean) ?? false)) + .catch(() => (globalWorkspacedRoute = false)) + } if (!deployed) return - SettingService.getGlobal({ key: 'app_workspaced_route' }) - .then((s) => (globalWorkspacedRoute = (s as boolean) ?? false)) - .catch(() => (globalWorkspacedRoute = false)) AppService.getPublicSecretOfApp({ workspace, path: appPath }) .then((s) => (secretUrl = s)) .catch(() => (secretUrl = undefined)) @@ -95,9 +100,7 @@ load() let embedMode = $state(false) - let secretUrlHref = $derived( - secretUrl ? `${window.location.origin}/public/${workspace}/${secretUrl}` : undefined - ) + let secretUrlHref = $derived(secretUrl ? secretUrlOf(workspace, secretUrl) : undefined) let appUrl = $derived( `${window.location.origin}/${rawApp ? 'apps_raw' : 'apps'}/get/${appPath}?workspace=${workspace}` ) @@ -110,41 +113,35 @@ // Shown to admins on EE; the dialog's own writes disable the controls rather than hide them. let mayEditCustomPath = $derived(!!$enterpriseLicense && isAdmin) let canSaveCustomPath = $derived( - !disabled && - !savingCustomPath && - customPathInput !== '' && - customPathInput !== deployed?.customPath + !disabled && !savingCustomPath && customPathInput !== '' && customPathInput !== customPath ) // The Embed toggle only shows outside Members, so it must not linger on from another mode. let customUrlEmbed = $derived(embedMode && mode != 'publisher') - let customUrlBase = $derived( - `${window.location.origin}/a/${isCloudHosted() || globalWorkspacedRoute ? workspace + '/' : ''}` - ) - let fullCustomUrl = $derived(customUrlBase + (deployed?.customPath ?? '')) + let customUrlBase = $derived(customUrlBaseOf(workspace, globalWorkspacedRoute)) + let fullCustomUrl = $derived(customUrlBase + (customPath ?? '')) // The guest JWT rides on the custom URL when set, else on the secret URL. - let guestJwtBase = $derived(deployed?.customPath ? fullCustomUrl : secretUrlHref) + let guestJwtBase = $derived(customPath ? fullCustomUrl : secretUrlHref) function editCustomPath() { - customPathInput = deployed?.customPath ?? '' + customPathInput = customPath ?? '' customPathErr = undefined editingCustomPath = true } async function saveCustomPath(next: string | null) { - if (!deployed || savingCustomPath) return + if (!onCustomPathChange || savingCustomPath) return savingCustomPath = true try { - customPathErr = - next === null ? undefined : await customPathError(workspace, next, deployed.customPath) + customPathErr = next === null ? undefined : await customPathError(workspace, next, customPath) if (customPathErr) return - await deployed.onCustomPathChange(next) + await onCustomPathChange(next) } catch (err) { customPathErr = `Could not check whether the path is free: ${err}` } finally { savingCustomPath = false } // A refused write leaves the deployed path as it was: keep the field open to retry. - if ((deployed.customPath ?? null) === next) editingCustomPath = false + if ((customPath ?? null) === next) editingCustomPath = false } function toEmbedSnippet(url: string): string { @@ -221,7 +218,7 @@ {/if} {/if} {:else} - The people with access above, signed in to Windmill. + The people with access to the app, signed in to Windmill. {/if} @@ -266,7 +263,16 @@ {/if} + {:else if mode != 'publisher'} + + {/if} + {#if onCustomPathChange}
{/if} diff --git a/frontend/src/lib/components/itemSettings/ShareDialog.svelte b/frontend/src/lib/components/itemSettings/ShareDialog.svelte index 5934fe14f9..fc419855c9 100644 --- a/frontend/src/lib/components/itemSettings/ShareDialog.svelte +++ b/frontend/src/lib/components/itemSettings/ShareDialog.svelte @@ -15,20 +15,9 @@ type AppWithLastVersion, type Folder } from '$lib/gen' - import { sendUserToast } from '$lib/toast' - import { - useOperatingUser, - useOperatingWorkspace - } from '$lib/components/operatingWorkspace.svelte' + import { useOperatingWorkspace } from '$lib/components/operatingWorkspace.svelte' import ItemAccessList from './ItemAccessList.svelte' - import AppAccessSection from './AppAccessSection.svelte' - import { - accessModeOf, - modeChangeRefusal, - updateDeployedAppAccess, - type AppAccessMode - } from './appAccess' - import { canPreserveOnBehalfOf } from './onBehalfOf' + import DeployedAppAccess from './DeployedAppAccess.svelte' import { accessLostByMove, folderOfPath, @@ -39,7 +28,7 @@ import Label from '$lib/components/Label.svelte' import ClipboardPanel from '$lib/components/details/ClipboardPanel.svelte' import { logShareOpen, type ShareOpenSource } from './sharingTelemetry' - import { useEditRights, useRoleCapabilities } from '$lib/operatorWriteRights' + import { useEditRights } from '$lib/operatorWriteRights' interface Props { /** Called after a write to the app row, with the row as it now is. */ @@ -51,9 +40,7 @@ let { onAppChanged, onChange }: Props = $props() const operatingWorkspace = useOperatingWorkspace() - const operatingUser = useOperatingUser() const editRights = useEditRights() - const roleCaps = useRoleCapabilities() let open = $state(false) let kind = $state('flow') @@ -70,7 +57,6 @@ let answerDeploy: ((deploy: boolean) => void) | undefined = undefined let app: AppWithLastVersion | undefined = $state() - let appBusy = $state(false) /** Who the deployed flow or script runs as, and whether the user may change it, once read. An * app's run-as user is in its policy. */ let runnableIdentity: { runAs: string | undefined; canEdit: boolean } | undefined = $state() @@ -84,14 +70,6 @@ let canWriteApp = $derived( !!app && editRights.canEditItem(app.raw_app ? 'raw_app' : 'app', app.path, app.extra_perms) ) - let modeRefusal = $derived( - app && - modeChangeRefusal(app.policy, { - username: operatingUser.current?.username, - canPreserveRunAs: canPreserveOnBehalfOf(operatingUser.current), - composeOnly: $roleCaps.apps === 'compose' - }) - ) let itemUrl = $derived( `${window.location.origin}/${kind === 'flow' ? 'flows' : 'scripts'}/get/${path}?workspace=${$operatingWorkspace}` ) @@ -271,35 +249,6 @@ } }) - const ACCESS_MODE_LABELS: Record = { - publisher: 'Members', - guest: 'Guests', - anonymous: 'Public' - } - - async function changeApp( - change: { execution_mode: AppAccessMode } | { custom_path: string | null } - ) { - appBusy = true - try { - app = await updateDeployedAppAccess($operatingWorkspace!, path, change) - onAppChanged?.(app) - onChange?.() - sendUserToast( - 'execution_mode' in change - ? `Who can open ${name} changed to ${ACCESS_MODE_LABELS[change.execution_mode]}` - : change.custom_path - ? `Custom URL of ${name} set to ${change.custom_path}` - : `Custom URL of ${name} removed` - ) - } catch (err) { - sendUserToast(`Could not change the app's access: ${err?.body ?? err}`, true) - // Re-read so the controls show what is deployed, not the choice that was refused. - await loadApp() - } finally { - appBusy = false - } - }