diff --git a/frontend/src/lib/components/apps/editor/AppEditorHeader.svelte b/frontend/src/lib/components/apps/editor/AppEditorHeader.svelte index 0825e56b54..e5613a71a1 100644 --- a/frontend/src/lib/components/apps/editor/AppEditorHeader.svelte +++ b/frontend/src/lib/components/apps/editor/AppEditorHeader.svelte @@ -467,27 +467,20 @@ } } - async function setPublishState(message: string) { + async function setPublishState(message?: string) { policy = await updatePolicy($app, policy) await AppService.updateApp({ workspace: $workspaceStore!, path: $appPath, requestBody: { policy } }) - sendUserToast(message) - } - - async function setAccessMode(mode: NonNullable) { - await AppService.updateApp({ - workspace: $workspaceStore!, - path: $appPath, - requestBody: { execution_mode: mode } - }) - sendUserToast( - mode == 'anonymous' - ? 'App require no login to be accessed' - : 'App require login and read-access' - ) + if (message) { + sendUserToast(message) + } else if (policy.execution_mode == 'anonymous') { + sendUserToast('App require no login to be accessed') + } else { + sendUserToast('App require login and read-access') + } } async function save() { @@ -955,7 +948,6 @@ {newApp} {policy} {setPublishState} - {setAccessMode} appPath={$appPath} {onLatest} {headUnknown} diff --git a/frontend/src/lib/components/apps/editor/AppEditorHeaderDeploy.svelte b/frontend/src/lib/components/apps/editor/AppEditorHeaderDeploy.svelte index 79cd27c3fc..6118f6626d 100644 --- a/frontend/src/lib/components/apps/editor/AppEditorHeaderDeploy.svelte +++ b/frontend/src/lib/components/apps/editor/AppEditorHeaderDeploy.svelte @@ -11,7 +11,7 @@ import ClipboardPanel from '$lib/components/details/ClipboardPanel.svelte' import { untrack } from 'svelte' import { AppService, SettingService, WorkspaceService } from '$lib/gen' - import type { GuestUsage, Policy } from '$lib/gen' + import type { GuestUsage } from '$lib/gen' import ToggleButtonGroup from '$lib/components/common/toggleButton-v2/ToggleButtonGroup.svelte' import ToggleButton from '$lib/components/common/toggleButton-v2/ToggleButton.svelte' import Path from '$lib/components/Path.svelte' @@ -43,7 +43,6 @@ let { policy, setPublishState, - setAccessMode, appPath, customPath = $bindable(), onLatest, @@ -63,9 +62,7 @@ operatingWorkspace = undefined }: { policy: any - setPublishState: (message: string) => void - /** Changes who may open the deployed app, leaving the rest of its deployed policy as is. */ - setAccessMode: (mode: NonNullable) => Promise + setPublishState: (message?: string) => void appPath: string customPath: string | undefined onLatest: boolean @@ -148,26 +145,14 @@ }) }) - // One change at a time: a failed request puts back the mode it replaced, which would - // overwrite a newer selection that already succeeded. - let accessModePending = $state(false) - async function onAccessModeChange(mode: string | undefined) { - if (mode === undefined || mode === accessMode || accessModePending) return - const previous = policy.execution_mode + function onAccessModeChange(mode: string | undefined) { + if (mode === undefined || mode === accessMode) return policy.execution_mode = mode - // Same as sandbox: a not-yet-deployed app has no row to update, so - // `setAccessMode` would 404. The mode is carried by the first deploy's + // Same as sandbox: a not-yet-deployed app has no row to PATCH, so + // `setPublishState` would 404. The mode is carried by the first deploy's // policy; persist incrementally only once the app exists. - if (savedApp && !newApp && !modeChangesOnDeploy) { - accessModePending = true - try { - await setAccessMode(mode as NonNullable) - } catch (e) { - policy.execution_mode = previous - throw e - } finally { - accessModePending = false - } + if (savedApp && !newApp) { + setPublishState() } } let canPreserve = $derived(!!actingUser?.is_admin || !!actingUser?.is_super_admin || isDeployer) @@ -176,11 +161,6 @@ let onBehalfOfChoice: OnBehalfOfChoice = $state(undefined) let customOnBehalfOfEmail: string = $state('') let myOnBehalfOf = $derived(actingUser?.username ? `u/${actingUser.username}` : undefined) - // The server refuses to change the mode alone of an app that runs as someone else unless the - // caller may keep that identity, and always for a builder; for them it changes on deploy. - let modeChangesOnDeploy = $derived( - !!savedOnBehalfOf && savedOnBehalfOf !== myOnBehalfOf && (!canPreserve || composeOnlyApps) - ) // Without the right to preserve, the backend runs the redeployed app as the deployer whatever // the policy says, as it does for "me". let deployOnBehalfOf = $derived.by(() => { @@ -538,7 +518,7 @@ onAccessModeChange(e.detail)} - disabled={!savedApp || accessModePending} + disabled={!savedApp} > {#snippet children({ item })} - {#if savedApp && !newApp && modeChangesOnDeploy} -
- This app runs as {savedOnBehalfOf}, so a change here takes effect when - you deploy. -
- {/if}
{#if policy.execution_mode == 'anonymous'} Anyone holding the secret URL below can open this app without signing in. diff --git a/frontend/src/lib/components/raw_apps/RawAppEditorHeader.svelte b/frontend/src/lib/components/raw_apps/RawAppEditorHeader.svelte index 5c0484e7a8..bc14c298e9 100644 --- a/frontend/src/lib/components/raw_apps/RawAppEditorHeader.svelte +++ b/frontend/src/lib/components/raw_apps/RawAppEditorHeader.svelte @@ -663,7 +663,7 @@ }) } - async function setPublishState(message: string) { + async function setPublishState(message?: string) { const nextPolicy = await policyWithTriggerables() await AppService.updateApp({ workspace: opWorkspace!, @@ -671,20 +671,13 @@ requestBody: { policy: nextPolicy } }) policy.triggerables_v2 = nextPolicy.triggerables_v2 - sendUserToast(message) - } - - async function setAccessMode(mode: NonNullable) { - await AppService.updateApp({ - workspace: opWorkspace!, - path: appPath, - requestBody: { execution_mode: mode } - }) - sendUserToast( - mode == 'anonymous' - ? 'App require no login to be accessed' - : 'App require login and read-access' - ) + if (message) { + sendUserToast(message) + } else if (policy.execution_mode == 'anonymous') { + sendUserToast('App require no login to be accessed') + } else { + sendUserToast('App require login and read-access') + } } async function save() { @@ -901,7 +894,6 @@ {newApp} {policy} {setPublishState} - {setAccessMode} {appPath} {onLatest} {headUnknown}