From 23563b6b36466c074cbda01901a71e314c2bf77d Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Mon, 19 Feb 2024 14:44:14 +0100 Subject: [PATCH] fix(app): make custom components available in public apps --- backend/windmill-api/src/resources.rs | 9 ++------- .../apps/components/display/AppCustomComponent.svelte | 6 ++---- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/backend/windmill-api/src/resources.rs b/backend/windmill-api/src/resources.rs index ea06523a9c..3095fcd713 100644 --- a/backend/windmill-api/src/resources.rs +++ b/backend/windmill-api/src/resources.rs @@ -370,24 +370,19 @@ async fn explain_resource_perm_error( } async fn custom_component( - authed: ApiAuthed, - Extension(user_db): Extension, + Extension(db): Extension, Path((w_id, name)): Path<(String, String)>, ) -> Result { - let mut tx = user_db.begin(&authed).await?; - let cc_o = sqlx::query_scalar!( "SELECT value->>'js' FROM resource WHERE path = $1 AND workspace_id = $2", format!("f/app_custom/{name}"), &w_id ) - .fetch_optional(&mut *tx) + .fetch_optional(&db) .await? .flatten(); - tx.commit().await?; - let cc = not_found_if_none(cc_o, "Custom Component", name)?; let res = Response::builder().header(header::CONTENT_TYPE, "text/javascript"); diff --git a/frontend/src/lib/components/apps/components/display/AppCustomComponent.svelte b/frontend/src/lib/components/apps/components/display/AppCustomComponent.svelte index 5a5f65bb87..4382c9d1c8 100644 --- a/frontend/src/lib/components/apps/components/display/AppCustomComponent.svelte +++ b/frontend/src/lib/components/apps/components/display/AppCustomComponent.svelte @@ -19,7 +19,6 @@ import { sendUserToast } from '$lib/toast' import type { AppInput } from '../../inputType' import { RunnableWrapper } from '../helpers' - import { workspaceStore } from '$lib/stores' import type { CustomComponentConfig } from '../../editor/component' import { Loader2 } from 'lucide-svelte' @@ -29,7 +28,7 @@ export let customComponent: CustomComponentConfig let divId = `custom-component-${id}` - const { worldStore } = getContext('AppViewerContext') + const { worldStore, workspace } = getContext('AppViewerContext') const outputs = initOutput($worldStore, id, { result: undefined, @@ -75,7 +74,7 @@ //@ts-ignore await import( /* @vite-ignore */ - `/api/w/${$workspaceStore ?? 'NO_W'}/resources_u/custom_component/${customComponent.name}` + `/api/w/${workspace ?? 'NO_W'}/resources_u/custom_component/${customComponent.name}` ) loaded = true try { @@ -105,7 +104,6 @@ - {#if render}