diff --git a/backend/src/resources.rs b/backend/src/resources.rs index 1f343abb9e..c366eda69a 100644 --- a/backend/src/resources.rs +++ b/backend/src/resources.rs @@ -283,10 +283,16 @@ async fn update_resource( if let Some(ndesc) = ns.description { sqlb.set_str("description", ndesc); } + + sqlb.returning("path"); + let mut tx = user_db.begin(&authed).await?; let sql = sqlb.sql().map_err(|e| Error::InternalErr(e.to_string()))?; - sqlx::query(&sql).execute(&mut tx).await?; + let npath_o: Option = sqlx::query_scalar(&sql).fetch_optional(&mut tx).await?; + + let npath = crate::utils::not_found_if_none(npath_o, "Resource", path)?; + audit_log( &mut tx, &authed.username, @@ -299,7 +305,7 @@ async fn update_resource( .await?; tx.commit().await?; - Ok(format!("resource {} updated (npath: {:?})", path, ns.path)) + Ok(format!("resource {} updated (npath: {:?})", path, npath)) } async fn list_resource_types( diff --git a/backend/src/variables.rs b/backend/src/variables.rs index 05a6b0e36e..22a5f7d1a7 100644 --- a/backend/src/variables.rs +++ b/backend/src/variables.rs @@ -356,7 +356,6 @@ async fn delete_variable( async fn update_variable( authed: Authed, Extension(user_db): Extension, - Extension(db): Extension, Path((w_id, path)): Path<(String, StripPath)>, Json(ns): Json, ) -> Result { @@ -404,9 +403,14 @@ async fn update_variable( } sqlb.set_str("is_secret", nbool); } + sqlb.returning("path"); + let sql = sqlb.sql().map_err(|e| Error::InternalErr(e.to_string()))?; - sqlx::query(&sql).execute(&db).await?; + let npath_o: Option = sqlx::query_scalar(&sql).fetch_optional(&mut tx).await?; + + let npath = crate::utils::not_found_if_none(npath_o, "Variable", path)?; + audit_log( &mut tx, &authed.username, @@ -419,7 +423,7 @@ async fn update_variable( .await?; tx.commit().await?; - Ok(format!("variable {} updated (npath: {:?})", path, ns.path)) + Ok(format!("variable {} updated (npath: {:?})", path, npath)) } pub async fn build_crypt<'c>( diff --git a/deno-client/mod.ts b/deno-client/mod.ts index 06b5ccaaa7..c3d4fc40c9 100644 --- a/deno-client/mod.ts +++ b/deno-client/mod.ts @@ -69,14 +69,13 @@ export function getInternalStatePath(suffix?: string): string { */ export async function setResource(path: string, value: any, initializeToTypeIfNotExist?: string): Promise { const conf = createConf() - try { - await new ResourceApi(conf).updateResource(conf.workspace_id, path, { value }) - } catch (e) { - if (initializeToTypeIfNotExist && e.code === 404) { - await new ResourceApi(conf).createResource(conf.workspace_id, { path, value, resourceType: initializeToTypeIfNotExist }) - } else { - throw e - } + const resourceApi = new ResourceApi(conf) + if (await resourceApi.existsResource(conf.workspace_id, path)) { + await resourceApi.updateResource(conf.workspace_id, path, { value }) + } else if (initializeToTypeIfNotExist) { + await resourceApi.createResource(conf.workspace_id, { path, value, resourceType: initializeToTypeIfNotExist }) + } else { + throw Error(`Resoucr at path ${path} does not exist and no type was provided to initialize it`) } } diff --git a/frontend/src/lib/components/FlowEditor.svelte b/frontend/src/lib/components/FlowEditor.svelte index e663308422..f21b147b5d 100644 --- a/frontend/src/lib/components/FlowEditor.svelte +++ b/frontend/src/lib/components/FlowEditor.svelte @@ -37,7 +37,11 @@ let jsonValue: string = '' async function loadSchedule() { - try { + const existsSchedule = await ScheduleService.existsSchedule({ + workspace: $workspaceStore ?? '', + path: initialPath + }) + if (existsSchedule) { const schedule = await ScheduleService.getSchedule({ workspace: $workspaceStore ?? '', path: initialPath @@ -46,8 +50,6 @@ scheduleCron = schedule.schedule scheduleArgs = scheduleArgs console.log(schedule.enabled, schedule.schedule) - } catch (e) { - console.log(`no primary schedule found for ${initialPath}`) } } diff --git a/frontend/src/lib/components/SchemaForm.svelte b/frontend/src/lib/components/SchemaForm.svelte index aeebf64c0a..c5dc25f3d8 100644 --- a/frontend/src/lib/components/SchemaForm.svelte +++ b/frontend/src/lib/components/SchemaForm.svelte @@ -61,105 +61,109 @@
{#if Object.keys(schema?.properties ?? {}).length > 0} {#each Object.keys(schema?.properties ?? {}) as argName, index} - {#if inputTransform && args[argName] != undefined} -
0 ? 'mt-8' : ''} /> -
-
- - {#if propertiesTypes[argName] === InputTransform.type.STATIC && args[argName].type === InputTransform.type.JAVASCRIPT} - - {'${...}'} - - {/if} -
- { - if (e.detail === InputTransform.type.JAVASCRIPT) { - args[argName].expr = getDefaultExpr(i ?? -1, argName, args[argName].value) - args[argName].value = undefined - } else { - args[argName].expr = undefined - args[argName].value = undefined - } - - args[argName].type = e.detail - }} - /> -
-
- - {#if propertiesTypes[argName] === undefined || propertiesTypes[argName] === InputTransform.type.STATIC} - { - const toAppend = `\$\{${event.detail}}` - args[argName].value = `${args[argName].value ?? ''}${toAppend}` - setPropertyType(argName, args[argName].value, false) - }} - > - { - Object.keys(overlays).forEach((k) => { - if (k == argName) { - overlays[k].focus() - } else { - overlays[k].unfocus() - } - }) - }} - label={argName} - bind:description={schema.properties[argName].description} - bind:value={args[argName].value} - type={schema.properties[argName].type} - required={schema.required.includes(argName)} - bind:pattern={schema.properties[argName].pattern} - bind:valid={inputCheck[argName]} - defaultValue={schema.properties[argName].default} - bind:enum_={schema.properties[argName].enum} - bind:format={schema.properties[argName].format} - contentEncoding={schema.properties[argName].contentEncoding} - bind:itemsType={schema.properties[argName].items} - displayHeader={false} - bind:inputCat={inputCats[argName]} - numberAsString={true} - on:input={(e) => { - if (hasOverlay(inputCats[argName])) { - setPropertyType(argName, e.detail.rawValue, e.detail.isRaw) - } - }} - /> - - {:else if propertiesTypes[argName] === InputTransform.type.JAVASCRIPT} - {#if args[argName].expr != undefined} -
- 0 ? 'mt-8' : ''} /> +
+
+ + {#if propertiesTypes[argName] === InputTransform.type.STATIC && args[argName].type === InputTransform.type.JAVASCRIPT} + + {'${...}'} + + {/if}
- + { + if (e.detail === InputTransform.type.JAVASCRIPT) { + args[argName].expr = getDefaultExpr(i ?? -1, argName, args[argName].value) + args[argName].value = undefined + } else { + args[argName].expr = undefined + args[argName].value = undefined + } + + args[argName].type = e.detail + }} + /> +
+
+ + {#if propertiesTypes[argName] === undefined || propertiesTypes[argName] === InputTransform.type.STATIC} + { + const toAppend = `\$\{${event.detail}}` + args[argName].value = `${args[argName].value ?? ''}${toAppend}` + setPropertyType(argName, args[argName].value, false) + }} + > + { + Object.keys(overlays).forEach((k) => { + if (k == argName) { + overlays[k].focus() + } else { + overlays[k].unfocus() + } + }) + }} + label={argName} + bind:description={schema.properties[argName].description} + bind:value={args[argName].value} + type={schema.properties[argName].type} + required={schema.required.includes(argName)} + bind:pattern={schema.properties[argName].pattern} + bind:valid={inputCheck[argName]} + defaultValue={schema.properties[argName].default} + bind:enum_={schema.properties[argName].enum} + bind:format={schema.properties[argName].format} + contentEncoding={schema.properties[argName].contentEncoding} + bind:itemsType={schema.properties[argName].items} + displayHeader={false} + bind:inputCat={inputCats[argName]} + numberAsString={true} + on:input={(e) => { + if (hasOverlay(inputCats[argName])) { + setPropertyType(argName, e.detail.rawValue, e.detail.isRaw) + } + }} + /> + + {:else if propertiesTypes[argName] === InputTransform.type.JAVASCRIPT} + {#if args[argName].expr != undefined} +
+ +
+ + {/if} + {:else} +

Not recognized arg type {args[argName].type}

{/if} {:else} -

Not recognized arg type {args[argName].type}

+

Arg at {argName} is undefined

{/if} {:else} {/if} -
- {#if variable.is_secret} + {#if variable.is_secret} +
- {:else} - variable (max 3000 characters) +
+ {:else} +
+ Variable (max 3000 characters) - {/if} -
+
+ {/if}
Description diff --git a/frontend/src/routes/variables.svelte b/frontend/src/routes/variables.svelte index 98276ca2d4..64570c38c2 100644 --- a/frontend/src/routes/variables.svelte +++ b/frontend/src/routes/variables.svelte @@ -7,7 +7,7 @@