diff --git a/backend/.sqlx/query-61e9662fe42506131222412ab3de48cf6485dea10aa3a2f97c0fd6322a0cb17f.json b/backend/.sqlx/query-61e9662fe42506131222412ab3de48cf6485dea10aa3a2f97c0fd6322a0cb17f.json deleted file mode 100644 index 3271f312c8..0000000000 --- a/backend/.sqlx/query-61e9662fe42506131222412ab3de48cf6485dea10aa3a2f97c0fd6322a0cb17f.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "DELETE FROM schedule WHERE path = $1 AND workspace_id = $2", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Text", - "Text" - ] - }, - "nullable": [] - }, - "hash": "61e9662fe42506131222412ab3de48cf6485dea10aa3a2f97c0fd6322a0cb17f" -} diff --git a/backend/windmill-api/src/schedule.rs b/backend/windmill-api/src/schedule.rs index d31382bdc9..d39ad75b2f 100644 --- a/backend/windmill-api/src/schedule.rs +++ b/backend/windmill-api/src/schedule.rs @@ -581,14 +581,37 @@ async fn delete_schedule( let path = path.to_path(); clear_schedule(&mut tx, path, &w_id).await?; - - sqlx::query!( - "DELETE FROM schedule WHERE path = $1 AND workspace_id = $2", + let exists = sqlx::query_scalar!( + "SELECT 1 FROM schedule WHERE path = $1 AND workspace_id = $2", path, w_id ) - .execute(&mut *tx) - .await?; + .fetch_optional(&mut *tx) + .await? + .flatten(); + + if exists.is_none() { + return Err(windmill_common::error::Error::NotFound(format!( + "Schedule {} not found", + path + ))); + } + + let del = sqlx::query_scalar!( + "DELETE FROM schedule WHERE path = $1 AND workspace_id = $2 RETURNING 1", + path, + w_id + ) + .fetch_optional(&mut *tx) + .await? + .flatten(); + + if del.is_none() { + return Err(windmill_common::error::Error::NotAuthorized(format!( + "Not authorized to delete schedule {}", + path + ))); + } handle_deployment_metadata( &authed.email, diff --git a/frontend/src/lib/components/DropdownV2.svelte b/frontend/src/lib/components/DropdownV2.svelte index ad64c8bb0e..ceeeb64a03 100644 --- a/frontend/src/lib/components/DropdownV2.svelte +++ b/frontend/src/lib/components/DropdownV2.svelte @@ -47,7 +47,10 @@ class={twMerge( 'px-4 py-2 text-primary hover:bg-surface-hover hover:text-primary cursor-pointer text-xs transition-all', 'flex flex-row gap-2 items-center', - item?.type === 'delete' && 'text-red-500 hover:bg-red-100 hover:text-red-500' + item?.disabled && 'text-gray-400 cursor-not-allowed', + item?.type === 'delete' && + !item?.disabled && + 'text-red-500 hover:bg-red-100 hover:text-red-500' )} > {#if item.icon}