From a1fec7c4b70e415cec3daae03cae799363be66d2 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Fri, 30 Dec 2022 16:59:04 +0100 Subject: [PATCH] fix init edit on variable editor --- backend/windmill-api/src/resources.rs | 10 +++++----- backend/windmill-api/src/variables.rs | 8 ++++---- frontend/src/lib/components/VariableEditor.svelte | 7 ++++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/backend/windmill-api/src/resources.rs b/backend/windmill-api/src/resources.rs index 878fb5b8de..de000f9f3a 100644 --- a/backend/windmill-api/src/resources.rs +++ b/backend/windmill-api/src/resources.rs @@ -364,11 +364,6 @@ async fn update_resource( let mut tx = user_db.begin(&authed).await?; - let sql = sqlb.sql().map_err(|e| Error::InternalErr(e.to_string()))?; - let npath_o: Option = sqlx::query_scalar(&sql).fetch_optional(&mut tx).await?; - - let npath = not_found_if_none(npath_o, "Resource", path)?; - if let Some(npath) = ns.path { if npath != path { check_path_conflict(&mut tx, &w_id, &npath).await?; @@ -387,6 +382,11 @@ async fn update_resource( } } + let sql = sqlb.sql().map_err(|e| Error::InternalErr(e.to_string()))?; + let npath_o: Option = sqlx::query_scalar(&sql).fetch_optional(&mut tx).await?; + + let npath = not_found_if_none(npath_o, "Resource", path)?; + audit_log( &mut tx, &authed.username, diff --git a/backend/windmill-api/src/variables.rs b/backend/windmill-api/src/variables.rs index 09dc5ba73c..39af0de251 100644 --- a/backend/windmill-api/src/variables.rs +++ b/backend/windmill-api/src/variables.rs @@ -370,10 +370,6 @@ async fn update_variable( } sqlb.returning("path"); - let sql = sqlb.sql().map_err(|e| Error::InternalErr(e.to_string()))?; - - let npath_o: Option = sqlx::query_scalar(&sql).fetch_optional(&mut tx).await?; - if let Some(npath) = ns.path { if npath != path { check_path_conflict(&mut tx, &w_id, &npath).await?; @@ -391,6 +387,10 @@ async fn update_variable( } } + let sql = sqlb.sql().map_err(|e| Error::InternalErr(e.to_string()))?; + + let npath_o: Option = sqlx::query_scalar(&sql).fetch_optional(&mut tx).await?; + let npath = not_found_if_none(npath_o, "Variable", path)?; audit_log( diff --git a/frontend/src/lib/components/VariableEditor.svelte b/frontend/src/lib/components/VariableEditor.svelte index 2b8769a136..7e768d6393 100644 --- a/frontend/src/lib/components/VariableEditor.svelte +++ b/frontend/src/lib/components/VariableEditor.svelte @@ -49,11 +49,11 @@ drawer.openDrawer() } - export async function editVariable(path: string): Promise { + export async function editVariable(edit_path: string): Promise { edit = true const getV = await VariableService.getVariable({ workspace: $workspaceStore ?? '', - path, + path: edit_path, decryptSecret: false }) can_write = @@ -64,7 +64,8 @@ is_secret: getV.is_secret, description: getV.description ?? '' } - initialPath = path + initialPath = edit_path + path = edit_path drawer.openDrawer() }