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 <noreply@anthropic.com>

* fix: keep share and first-deploy out of embedded editors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: show a public or guest app's links after its first deploy

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ruben Fiszel
2026-10-30 04:17:04 +01:00
committed by GitHub
co-authored by Claude Opus 5.5
parent fd2846913b
commit 981baeda90
12 changed files with 434 additions and 165 deletions
+14 -3
View File
@@ -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}
<ShareDialog bind:this={shareDialog} />
<FirstDeployDialog bind:this={firstDeployDialog} />
{/if}
@@ -1867,6 +1870,14 @@
{@render previewButtons()}
{/if}
{#if offersSharing}
<ShareButton
deployed={!neverDeployed}
iconOnly={compactTopbar}
unifiedSize={headerBtnSize}
onclick={openShare}
/>
{/if}
<DeployButton
bind:this={deployButton}
on:save={async ({ detail }) => await handleSaveFlow(detail)}
@@ -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}
<ShareDialog bind:this={shareDialog} />
<FirstDeployDialog bind:this={firstDeployDialog} />
{/if}
@@ -2327,7 +2330,7 @@
{#if ownsPageHeader}
<OpenInSessionButton source={headerSessionOpen()} />
{/if}
{#if ownsPageHeader && !phoneTopbar}
{#if offersSharing && !phoneTopbar}
<ShareButton
deployed={!neverDeployed}
iconOnly={compactTopbar}
@@ -79,6 +79,7 @@
import { updatePolicy } from './appPolicy'
import { appDraftSettings, withoutSharedPolicySettings } from './appDraftSettings'
import ShareDialog from '$lib/components/itemSettings/ShareDialog.svelte'
import { showAppLinks } from '$lib/components/itemSettings/AppLinksModal.svelte'
import FirstDeployDialog, {
applyFirstDeployMembers
} from '$lib/components/itemSettings/FirstDeployDialog.svelte'
@@ -254,6 +255,9 @@
// `runtime.itemDeployed`, which discards the fork draft + reloads
// the preview to the deployed version.
const inSessionPane = !!getContext('aiChatManager')
// Share and the first-deploy dialog belong to Windmill's own editors: an embedding host can
// lock the path, which the dialog would let the user change.
const offersSharing = $derived(ownsPageHeader || inSessionPane)
// The header's buttons render under the page header, not under this component, so the contexts
// they look up have to travel with them. The app's own two carry everything the canvas toggles,
@@ -536,13 +540,14 @@
}
deploymentMsg = message ?? ''
firstDeployMembers = {}
if (newApp && ownsPageHeader) {
if (newApp && firstDeployDialog) {
// The dialog also asks who the app runs on behalf of, for the path it chose.
const choice = await firstDeployDialog?.ask({
const choice = await firstDeployDialog.ask({
kind: 'app',
summary: $summary,
path: newEditedPath,
appMode: accessModeOf(policy),
customPath,
runAs: {
email: policy.on_behalf_of_email,
permissionedAs: policy.on_behalf_of,
@@ -553,6 +558,7 @@
$summary = choice.summary
newEditedPath = choice.path
policy.execution_mode = choice.appMode
customPath = choice.customPath
if (choice.runAs) {
policy.on_behalf_of_email = choice.runAs.email
policy.on_behalf_of = choice.runAs.permissionedAs
@@ -602,8 +608,13 @@
// `$appPath` — its `draft_{uuid}` is a poor create signal.
if (newApp) {
const members = firstDeployMembers
if (await createApp(newEditedPath)) {
await applyFirstDeployMembers($workspaceStore!, 'app', newEditedPath, members)
const workspace = $workspaceStore!
const path = newEditedPath
if (await createApp(path)) {
await applyFirstDeployMembers(workspace, 'app', path, members)
if (offersSharing) {
showAppLinks({ workspace, path, mode: accessModeOf(policy), customPath })
}
}
} else {
await handleUpdateApp(newEditedPath)
@@ -961,6 +972,16 @@
})
let customPath = $state(savedApp?.custom_path)
/** Share and the settings drawer write who can open the deployed app and its custom URL at
* once: the editor follows, so its next deploy and diff see them. */
function applyAppAccess(row: { policy: Policy; custom_path?: string | null }) {
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
}
}
let labels = $state(untrack(() => initialLabels))
$effect(() => {
@@ -1040,20 +1061,12 @@
bind:pathError
bind:newEditedPath
bind:labels
bind:customPath
onAppChanged={applyAppAccess}
/>
{#if ownsPageHeader}
<ShareDialog
bind:this={shareDialog}
onAppChanged={(row) => {
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}
<ShareDialog bind:this={shareDialog} onAppChanged={applyAppAccess} />
<FirstDeployDialog bind:this={firstDeployDialog} />
{/if}
@@ -1423,7 +1436,7 @@
Settings
</Button>
</div>
{#if ownsPageHeader}
{#if offersSharing}
<ShareButton deployed={!newApp} iconOnly={compactTopbar} onclick={openShare} />
{/if}
{/if}
@@ -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(() => {})
}
})
</script>
{#snippet sandboxHint()}
@@ -149,6 +176,40 @@
</div>
</Section>
<Section label="Who can open the app">
<div class="flex flex-col gap-2">
{#if deployedPath}
{#if deployedApp}
<span class="text-xs text-secondary">
Changes here apply to the deployed app right away.
</span>
<DeployedAppAccess
workspace={opWs ?? ''}
bind:app={deployedApp}
reload={loadDeployedApp}
{onAppChanged}
/>
{:else}
<span class="text-xs text-secondary">Loading…</span>
{/if}
{:else}
<AppAccessSection
workspace={opWs ?? ''}
appPath={newEditedPath}
{rawApp}
mode={accessModeOf(policy)}
onModeChange={(m) => {
policy.execution_mode = m
}}
{customPath}
onCustomPathChange={(p) => {
customPath = p ?? undefined
}}
/>
{/if}
</div>
</Section>
<Section label="Permissions">
{#snippet labelExtra()}
<SettingIcons
@@ -15,7 +15,7 @@
import { isCloudHosted } from '$lib/cloud'
import { canUserBypassRuleKind, protectionRulesState } from '$lib/workspaceProtectionRules.svelte'
import { useOperatingUser } from '$lib/components/operatingWorkspace.svelte'
import { customPathError, type AppAccessMode } from './appAccess'
import { customPathError, customUrlBaseOf, secretUrlOf, type AppAccessMode } from './appAccess'
interface Props {
workspace: string
@@ -24,11 +24,12 @@
rawApp?: boolean
mode: AppAccessMode
onModeChange: (mode: AppAccessMode) => void | Promise<void>
/** Links, embedding and the custom URL, which exist only for a deployed app. */
deployed?: {
customPath: string | undefined
onCustomPathChange: (customPath: string | null) => Promise<void>
}
/** 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<void>
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}
</div>
</div>
@@ -266,7 +263,16 @@
<Loader2 size={16} class="animate-spin" />
{/if}
</Label>
{:else if mode != 'publisher'}
<Label label="Secret URL">
<span class="text-xs text-secondary">
The first deploy creates an unguessable link to this app. Copy it from Share or Settings
once the app is deployed.
</span>
</Label>
{/if}
{#if onCustomPathChange}
<Label
label="Custom URL"
for="customPath"
@@ -274,7 +280,7 @@
tooltip="Serve the app at a path you pick, on top of its link."
>
{#snippet action()}
{#if !deployed.customPath && !editingCustomPath}
{#if !customPath && !editingCustomPath}
<Button
variant="default"
unifiedSize="sm"
@@ -328,13 +334,20 @@
Cancel
</Button>
</div>
{:else if deployed.customPath}
{:else if customPath}
<div class="flex flex-row gap-1 items-center">
<div class="grow min-w-0">
<ClipboardPanel
content={customUrlEmbed ? toEmbedSnippet(fullCustomUrl) : fullCustomUrl}
size="md"
/>
{#if deployed}
<ClipboardPanel
content={customUrlEmbed ? toEmbedSnippet(fullCustomUrl) : fullCustomUrl}
size="md"
/>
{:else}
<div class="flex flex-col gap-0.5">
<span class="text-xs text-primary truncate">{fullCustomUrl}</span>
<span class="text-2xs text-secondary">Served once the app is deployed.</span>
</div>
{/if}
</div>
{#if mayEditCustomPath}
<Button
@@ -364,7 +377,9 @@
<span class="text-2xs text-secondary">Only workspace admins can set a custom URL.</span>
{/if}
</Label>
{/if}
{#if deployed}
{#if embedMode && mode == 'guest' && guestJwtBase && guestsAvailable}
<Label label="Embed for your own authenticated users (guest JWT)">
<div class="text-xs text-secondary">
@@ -0,0 +1,100 @@
<script lang="ts" module>
import type { AppAccessMode } from './appAccess'
type AppLinks = {
workspace: string
path: string
mode: AppAccessMode
customPath: string | undefined
}
let shown: AppLinks | undefined = $state()
/**
* Show the links of an app just created open to guests or to anyone, which reach it only
* through its secret or custom URL. Mounted once in the logged layout rather than in the editor,
* which the post-create navigation to the app's new path can remount.
*/
export function showAppLinks(links: AppLinks) {
if (links.mode === 'publisher') return
shown = links
}
</script>
<script lang="ts">
import { Button } from '$lib/components/common'
import Modal from '$lib/components/common/modal/Modal.svelte'
import Label from '$lib/components/Label.svelte'
import ClipboardPanel from '$lib/components/details/ClipboardPanel.svelte'
import { AppService, SettingService } from '$lib/gen'
import { Loader2 } from 'lucide-svelte'
import { customUrlBaseOf, secretUrlOf } from './appAccess'
let secretUrl: string | undefined = $state()
let customUrl: string | undefined = $state()
let error: string | undefined = $state()
$effect(() => {
const links = shown
secretUrl = undefined
customUrl = undefined
error = undefined
if (!links) return
AppService.getPublicSecretOfApp({ workspace: links.workspace, path: links.path })
.then((s) => {
if (shown === links) secretUrl = secretUrlOf(links.workspace, s)
})
.catch((e) => {
if (shown === links) error = `Could not read the secret URL: ${e?.body ?? e}`
})
if (links.customPath) {
const customPath = links.customPath
SettingService.getGlobal({ key: 'app_workspaced_route' })
.then((s) => (s as boolean) ?? false)
.catch(() => false)
.then((workspaced) => {
if (shown === links) customUrl = customUrlBaseOf(links.workspace, workspaced) + customPath
})
}
})
let name = $derived(shown?.path.split('/').pop() ?? '')
let link = $derived(shown?.customPath ? 'one of these links' : 'this link')
</script>
<Modal
bind:open={() => !!shown, (v) => (v ? undefined : (shown = undefined))}
title="{name} is deployed"
description={shown?.mode === 'anonymous'
? `Anyone with ${link} can open it without signing in.`
: `Anyone your identity provider authenticates can open it with ${link}, without a Windmill account.`}
kind="X"
class="sm:max-w-xl"
>
<div class="flex flex-col gap-6">
<Label label="Secret URL">
{#if secretUrl}
<ClipboardPanel content={secretUrl} size="md" />
{:else if error}
<span class="text-xs text-red-600 dark:text-red-400">{error}</span>
{:else}
<Loader2 size={16} class="animate-spin" />
{/if}
</Label>
{#if shown?.customPath}
<Label label="Custom URL">
{#if customUrl}
<ClipboardPanel content={customUrl} size="md" />
{:else}
<Loader2 size={16} class="animate-spin" />
{/if}
</Label>
{/if}
<span class="text-xs text-secondary">
You can find {shown?.customPath ? 'both' : 'it'} again in Share.
</span>
<div class="flex flex-row justify-end">
<Button variant="accent" unifiedSize="md" onclick={() => (shown = undefined)}>Done</Button>
</div>
</div>
</Modal>
@@ -0,0 +1,107 @@
<script lang="ts">
import type { AppWithLastVersion } from '$lib/gen'
import { sendUserToast } from '$lib/toast'
import { useOperatingUser } from '$lib/components/operatingWorkspace.svelte'
import { useEditRights, useRoleCapabilities } from '$lib/operatorWriteRights'
import AppAccessSection from './AppAccessSection.svelte'
import {
accessModeOf,
modeChangeRefusal,
updateDeployedAppAccess,
type AppAccessMode
} from './appAccess'
import { canPreserveOnBehalfOf } from './onBehalfOf'
interface Props {
workspace: string
/** The deployed row, rewritten here after each change. */
app: AppWithLastVersion
/** Re-reads the row, after a refused change. */
reload: () => Promise<void>
/** Called after a write to the app row, with the row as it now is. */
onAppChanged?: (row: AppWithLastVersion) => void
}
let { workspace, app = $bindable(), reload, onAppChanged }: Props = $props()
const operatingUser = useOperatingUser()
const editRights = useEditRights()
const roleCaps = useRoleCapabilities()
let busy = $state(false)
let name = $derived(app.path.split('/').pop() ?? app.path)
let runAs = $derived(app.policy.on_behalf_of ?? app.policy.on_behalf_of_email)
// Who can open the app is part of its policy, which only someone who can edit the app may
// rewrite.
let canWrite = $derived(
editRights.canEditItem(app.raw_app ? 'raw_app' : 'app', app.path, app.extra_perms)
)
let refusal = $derived(
modeChangeRefusal(app.policy, {
username: operatingUser.current?.username,
canPreserveRunAs: canPreserveOnBehalfOf(operatingUser.current),
composeOnly: $roleCaps.apps === 'compose'
})
)
const ACCESS_MODE_LABELS: Record<AppAccessMode, string> = {
publisher: 'Members',
guest: 'Guests',
anonymous: 'Public'
}
async function change(
change: { execution_mode: AppAccessMode } | { custom_path: string | null }
) {
busy = true
try {
app = await updateDeployedAppAccess(workspace, app.path, change)
onAppChanged?.(app)
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 reload()
} finally {
busy = false
}
}
</script>
{#if !canWrite}
<span class="text-xs text-secondary">
Only people who can edit this app can change who can open it.
</span>
{:else if refusal}
<span class="text-xs text-secondary">
{#if refusal === 'unsandboxed'}
This app is not sandboxed yet. Deploy it so it is sandboxed, then change who can open it.
{:else if refusal === 'builder_run_as'}
This app runs on behalf of {runAs}. Pick yourself in the editor's Settings › Permissions and
deploy it, then change who can open it. An admin can change it without taking the app over.
{:else}
This app runs on behalf of {runAs}. Deploy it so it runs on behalf of you, then change who can
open it. An admin or a member of <code>wm_deployers</code> can change it without taking the app
over.
{/if}
</span>
{/if}
{#key app.path}
<AppAccessSection
{workspace}
appPath={app.path}
rawApp={app.raw_app}
mode={accessModeOf(app.policy)}
onModeChange={(m) => change({ execution_mode: m })}
deployed
customPath={app.custom_path ?? undefined}
onCustomPathChange={(p) => change({ custom_path: p })}
disabled={busy || !canWrite || !!refusal}
/>
{/key}
@@ -11,6 +11,8 @@
members: Record<string, boolean>
/** Apps only. */
appMode?: AppAccessMode
/** Apps only. */
customPath?: string
message: string
/** The user the item runs on behalf of as the dialog leaves it, when the caller passed one
* in: the second step can change it or turn it off, and the deploy asks nothing more. */
@@ -68,6 +70,7 @@
let dirtyPath = $state(false)
let members: Record<string, boolean> = $state({})
let appMode = $state<AppAccessMode>('publisher')
let customPath: string | undefined = $state()
let message = $state('')
/** Where the item's run-as user is looked up; unset when the caller asks nothing about it. */
let runAsWorkspace: string | undefined = $state()
@@ -127,6 +130,7 @@
/** The caller picked the path, so it does not follow the summary. */
pathChosen?: boolean
appMode?: AppAccessMode
customPath?: string
/** The user the item holds to run on behalf of, which the second step confirms. */
runAs?: {
email: string | undefined
@@ -153,6 +157,7 @@
path = !dirtyPath && name ? [...segments.slice(0, -1), name].join('/') : opts.path
members = {}
appMode = opts.appMode ?? 'publisher'
customPath = opts.customPath
message = ''
open = true
return new Promise((r) => (resolve = r))
@@ -184,6 +189,7 @@
path,
members: $state.snapshot(members),
appMode: isApp ? appMode : undefined,
customPath: isApp ? customPath : undefined,
message,
runAs:
runAsWorkspace !== undefined
@@ -281,6 +287,10 @@
onModeChange={(m) => {
appMode = m
}}
{customPath}
onCustomPathChange={(p) => {
customPath = p ?? undefined
}}
/>
</section>
{/if}
@@ -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<ShareKind>('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<AppAccessMode, string> = {
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
}
}
</script>
<!-- Closed by Escape, the backdrop, the close button or Cancel: a deploy waiting on it does not go
@@ -339,40 +288,15 @@
<section class="flex flex-col gap-2">
<h3 class="text-sm font-semibold text-emphasis">Who can open the app</h3>
{#if app}
{#if !canWriteApp}
<span class="text-xs text-secondary">
Only people who can edit this app can change who can open it.
</span>
{:else if modeRefusal}
<span class="text-xs text-secondary">
{#if modeRefusal === 'unsandboxed'}
This app is not sandboxed yet. Deploy it so it is sandboxed, then change who can
open it.
{:else if modeRefusal === 'builder_run_as'}
This app runs on behalf of {runAs}. Pick yourself in the editor's Settings ›
Permissions and deploy it, then change who can open it. An admin can change it
without taking the app over.
{:else}
This app runs on behalf of {runAs}. Deploy it so it runs on behalf of you, then
change who can open it. An admin or a member of <code>wm_deployers</code> can change
it without taking the app over.
{/if}
</span>
{/if}
{#key path}
<AppAccessSection
workspace={$operatingWorkspace!}
appPath={path}
rawApp={kind === 'raw_app' || app.raw_app}
mode={accessModeOf(app.policy)}
onModeChange={(m) => changeApp({ execution_mode: m })}
deployed={{
customPath: app.custom_path ?? undefined,
onCustomPathChange: (p) => changeApp({ custom_path: p })
}}
disabled={appBusy || !canWriteApp || !!modeRefusal}
/>
{/key}
<DeployedAppAccess
workspace={$operatingWorkspace!}
bind:app
reload={loadApp}
onAppChanged={(row) => {
onAppChanged?.(row)
onChange?.()
}}
/>
{:else}
<span class="text-xs text-secondary">Loading…</span>
{/if}
@@ -1,9 +1,20 @@
import { AppService, type AppWithLastVersion, type Policy } from '$lib/gen'
import { isCloudHosted } from '$lib/cloud'
export type AppAccessMode = 'publisher' | 'guest' | 'anonymous'
export const CUSTOM_PATH_RE = /^[\w-]+(\/[\w-]+)*$/
/** What a custom path is appended to. The workspace is in it on the shared cloud and wherever the
* instance setting `app_workspaced_route` is on. */
export function customUrlBaseOf(workspace: string, workspacedRoute: boolean): string {
return `${window.location.origin}/a/${isCloudHosted() || workspacedRoute ? workspace + '/' : ''}`
}
export function secretUrlOf(workspace: string, secret: string): string {
return `${window.location.origin}/public/${workspace}/${secret}`
}
/** The access a policy grants, on the three rungs the Share dialog offers. `viewer` runs the
* app as its viewer, which a guest cannot be, so it shows as members-only. */
export function accessModeOf(policy: Policy | undefined): AppAccessMode {
@@ -38,6 +38,7 @@
WandSparkles
} from 'lucide-svelte'
import ShareDialog from '$lib/components/itemSettings/ShareDialog.svelte'
import { showAppLinks } from '$lib/components/itemSettings/AppLinksModal.svelte'
import FirstDeployDialog, {
applyFirstDeployMembers
} from '$lib/components/itemSettings/FirstDeployDialog.svelte'
@@ -274,6 +275,9 @@
onSavedNewAppPath
}: Props = $props()
// Share and the first-deploy dialog belong to Windmill's own editors: an embedding host can
// lock the path, which the dialog would let the user change.
const offersSharing = $derived(ownsPageHeader || inSessionPane)
const isNewApp = $derived(newApp || appPath == '')
// Only the app's first deploy takes the folder's default user.
const folderDefault = useFolderDefaultPermissionedAs(
@@ -745,13 +749,14 @@
}
deploymentMsg = message
firstDeployMembers = {}
if (isNewApp && ownsPageHeader) {
if (isNewApp && firstDeployDialog) {
// The dialog also asks who the app runs on behalf of, for the path it chose.
const choice = await firstDeployDialog?.ask({
const choice = await firstDeployDialog.ask({
kind: 'raw_app',
summary,
path: newEditedPath,
appMode: accessModeOf(policy),
customPath,
runAs: {
email: policy.on_behalf_of_email,
permissionedAs: policy.on_behalf_of,
@@ -762,6 +767,7 @@
summary = choice.summary
newEditedPath = choice.path
policy.execution_mode = choice.appMode
customPath = choice.customPath
if (choice.runAs) {
policy.on_behalf_of_email = choice.runAs.email
policy.on_behalf_of = choice.runAs.permissionedAs
@@ -809,8 +815,12 @@
if (isNewApp) {
const members = firstDeployMembers
const workspace = opWorkspace!
if (await createApp(newEditedPath)) {
await applyFirstDeployMembers(workspace, 'raw_app', newEditedPath, members)
const path = newEditedPath
if (await createApp(path)) {
await applyFirstDeployMembers(workspace, 'raw_app', path, members)
if (offersSharing) {
showAppLinks({ workspace, path, mode: accessModeOf(policy), customPath })
}
}
} else {
await handleUpdateApp(newEditedPath)
@@ -948,6 +958,16 @@
])
let customPath = $state(savedApp?.custom_path)
/** Share and the settings drawer write who can open the deployed app and its custom URL at
* once: the editor follows, so its next deploy and diff see them. */
function applyAppAccess(row: { policy: Policy; custom_path?: string | null }) {
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
}
}
// Derived, so a draft synced in from another session reaches the header; an edit here overrides
// the value until the next one arrives.
let labels = $derived(initialLabels)
@@ -1013,20 +1033,12 @@
bind:pathError
bind:newEditedPath
bind:labels
bind:customPath
onAppChanged={applyAppAccess}
/>
{#if ownsPageHeader}
<ShareDialog
bind:this={shareDialog}
onAppChanged={(row) => {
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}
<ShareDialog bind:this={shareDialog} onAppChanged={applyAppAccess} />
<FirstDeployDialog bind:this={firstDeployDialog} />
{/if}
@@ -1334,7 +1346,7 @@
{/if}
{/snippet}
</OpenInSessionButton>
{#if ownsPageHeader && !phoneTopbar}
{#if offersSharing && !phoneTopbar}
<ShareButton
deployed={!neverDeployed}
iconOnly={compactTopbar}
@@ -104,6 +104,7 @@
import { migrateUserDraftsToDb } from '$lib/userDraftDbMigration'
import { pruneMeaninglessDrafts } from '$lib/userDraftPrune'
import DraftMigrationErrorModal from '$lib/components/DraftMigrationErrorModal.svelte'
import AppLinksModal from '$lib/components/itemSettings/AppLinksModal.svelte'
import InstanceBanner from '$lib/components/InstanceBanner.svelte'
import InstanceUiSync from '$lib/components/InstanceUiSync.svelte'
import { onDestroy, setContext, untrack } from 'svelte'
@@ -1407,6 +1408,7 @@ outside this layout, and their shortcut must reopen the URL that is their creden
/>
{/if}
<DraftMigrationErrorModal />
<AppLinksModal />
{#if page.status == 404}
<CenteredModal title="Page not found, redirecting you to login" loading={true}></CenteredModal>
{:else if $userStore}