diff --git a/backend/windmill-api/src/folders.rs b/backend/windmill-api/src/folders.rs index 51fd4bac5c..6249548143 100644 --- a/backend/windmill-api/src/folders.rs +++ b/backend/windmill-api/src/folders.rs @@ -6,9 +6,11 @@ * LICENSE-AGPL for a copy of the license. */ +use std::sync::Arc; + use crate::{ db::{UserDB, DB}, - users::Authed, + users::{AuthCache, Authed, Tokened}, webhook_util::{WebhookMessage, WebhookShared}, }; use axum::{ @@ -144,8 +146,10 @@ lazy_static! { async fn create_folder( authed: Authed, + Tokened { token }: Tokened, Extension(user_db): Extension, Extension(webhook): Extension, + Extension(cache): Extension>, Path(w_id): Path, Json(ng): Json, ) -> Result { @@ -157,7 +161,7 @@ async fn create_folder( ))); } - check_name_conflict(&mut tx, &w_id, &ng.name).await?; + cache.invalidate(&w_id, token).await; let owner = username_to_permissioned_as(&authed.username); let owners = &ng.owners.unwrap_or(vec![owner.clone()]); diff --git a/backend/windmill-api/src/scripts.rs b/backend/windmill-api/src/scripts.rs index 5c147a1ed2..ac24770848 100644 --- a/backend/windmill-api/src/scripts.rs +++ b/backend/windmill-api/src/scripts.rs @@ -12,7 +12,7 @@ use windmill_audit::{audit_log, ActionKind}; use crate::{ db::{UserDB, DB}, schedule::clear_schedule, - users::{require_owner_of_path, Authed}, + users::{maybe_refresh_folders, require_owner_of_path, Authed}, webhook_util::{WebhookMessage, WebhookShared}, HTTP_CLIENT, }; @@ -190,6 +190,7 @@ async fn create_script( Json(ns): Json, ) -> Result<(StatusCode, String)> { let hash = ScriptHash(hash_script(&ns)); + // let authed = maybe_refresh_folders(&ns.path, &w_id, authed, &db).await; let mut tx = user_db.begin(&authed).await?; if sqlx::query_scalar!( diff --git a/frontend/src/lib/components/FlowBuilder.svelte b/frontend/src/lib/components/FlowBuilder.svelte index e2e3e3283b..76fbecc2b1 100644 --- a/frontend/src/lib/components/FlowBuilder.svelte +++ b/frontend/src/lib/components/FlowBuilder.svelte @@ -53,73 +53,78 @@ async function saveFlow(leave: boolean): Promise { loadingSave = true - const flow = cleanInputs($flowStore) - const { cron, args, enabled } = $scheduleStore - $dirtyStore = false - if (initialPath === '') { - localStorage.removeItem('flow') - await FlowService.createFlow({ - workspace: $workspaceStore!, - requestBody: { - path: flow.path, - summary: flow.summary, - description: flow.description ?? '', - value: flow.value, - schema: flow.schema + try { + const flow = cleanInputs($flowStore) + const { cron, args, enabled } = $scheduleStore + $dirtyStore = false + if (initialPath === '') { + localStorage.removeItem('flow') + await FlowService.createFlow({ + workspace: $workspaceStore!, + requestBody: { + path: flow.path, + summary: flow.summary, + description: flow.description ?? '', + value: flow.value, + schema: flow.schema + } + }) + if (enabled) { + await createSchedule(flow.path) } - }) - if (enabled) { - await createSchedule(flow.path) - } - } else { - localStorage.removeItem(`flow-${initialPath}`) - await FlowService.updateFlow({ - workspace: $workspaceStore!, - path: initialPath, - requestBody: { - path: flow.path, - summary: flow.summary, - description: flow.description ?? '', - value: flow.value, - schema: flow.schema - } - }) - const scheduleExists = await ScheduleService.existsSchedule({ - workspace: $workspaceStore ?? '', - path: flow.path - }) - if (scheduleExists) { - const schedule = await ScheduleService.getSchedule({ + } else { + localStorage.removeItem(`flow-${initialPath}`) + await FlowService.updateFlow({ + workspace: $workspaceStore!, + path: initialPath, + requestBody: { + path: flow.path, + summary: flow.summary, + description: flow.description ?? '', + value: flow.value, + schema: flow.schema + } + }) + const scheduleExists = await ScheduleService.existsSchedule({ workspace: $workspaceStore ?? '', path: flow.path }) - if (JSON.stringify(schedule.args) != JSON.stringify(args) || schedule.schedule != cron) { - await ScheduleService.updateSchedule({ + if (scheduleExists) { + const schedule = await ScheduleService.getSchedule({ workspace: $workspaceStore ?? '', - path: flow.path, - requestBody: { - schedule: formatCron(cron), - args - } + path: flow.path }) + if (JSON.stringify(schedule.args) != JSON.stringify(args) || schedule.schedule != cron) { + await ScheduleService.updateSchedule({ + workspace: $workspaceStore ?? '', + path: flow.path, + requestBody: { + schedule: formatCron(cron), + args + } + }) + } + if (enabled != schedule.enabled) { + await ScheduleService.setScheduleEnabled({ + workspace: $workspaceStore ?? '', + path: flow.path, + requestBody: { enabled } + }) + } + } else if (enabled) { + await createSchedule(flow.path) } - if (enabled != schedule.enabled) { - await ScheduleService.setScheduleEnabled({ - workspace: $workspaceStore ?? '', - path: flow.path, - requestBody: { enabled } - }) - } - } else if (enabled) { - await createSchedule(flow.path) } - } - loadingSave = false - if (leave) { - goto(`/flows/get/${$flowStore.path}?workspace_id=${$workspaceStore}`) - } else if (initialPath !== $flowStore.path) { - initialPath = $flowStore.path - goto(`/flows/edit/${$flowStore.path}?workspace_id=${$workspaceStore}`) + loadingSave = false + if (leave) { + goto(`/flows/get/${$flowStore.path}?workspace_id=${$workspaceStore}`) + } else if (initialPath !== $flowStore.path) { + initialPath = $flowStore.path + goto(`/flows/edit/${$flowStore.path}?workspace_id=${$workspaceStore}`) + } + } catch (err) { + sendUserToast(`The flow could not be saved: ${err.body}`, true) + loadingSave = false } } diff --git a/frontend/src/lib/components/Path.svelte b/frontend/src/lib/components/Path.svelte index eb3b2673b8..03744d7c03 100644 --- a/frontend/src/lib/components/Path.svelte +++ b/frontend/src/lib/components/Path.svelte @@ -1,3 +1,7 @@ + + - - { - newGroup.closeDrawer() - groupCreated = undefined - }} - > -
- - -
- {#if groupCreated} -
- - {/if} - - - - - - - -
- {:else if meta.ownerKind === 'group'} - {/if}