Skip to content

Commit

Permalink
feat: add delete flows
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed Feb 22, 2023
1 parent 2213500 commit e81f7bd
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 11 deletions.
17 changes: 17 additions & 0 deletions backend/windmill-api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2716,6 +2716,23 @@ paths:
schema:
type: string

/w/{workspace}/flows/delete/{path}:
delete:
summary: delete flow by path
operationId: deleteFlowByPath
tags:
- flow
parameters:
- $ref: "#/components/parameters/WorkspaceId"
- $ref: "#/components/parameters/ScriptPath"
responses:
"200":
description: flow delete
content:
text/plain:
schema:
type: string

/w/{workspace}/apps/list:
get:
summary: list all available apps
Expand Down
42 changes: 39 additions & 3 deletions backend/windmill-api/src/flows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use sql_builder::prelude::*;

use axum::{
extract::{Extension, Path, Query},
routing::{get, post},
routing::{delete, get, post},
Json, Router,
};
use sql_builder::SqlBuilder;
Expand Down Expand Up @@ -41,6 +41,7 @@ pub fn workspaced_service() -> Router {
.route("/create", post(create_flow))
.route("/update/*path", post(update_flow))
.route("/archive/*path", post(archive_flow_by_path))
.route("/delete/*path", delete(delete_flow_by_path))
.route("/get/*path", get(get_flow_by_path))
.route("/exists/*path", get(exists_flow_by_path))
.route("/list_paths", get(list_paths))
Expand Down Expand Up @@ -446,8 +447,7 @@ async fn exists_flow_by_path(
let path = path.to_path();

let exists = sqlx::query_scalar!(
"SELECT EXISTS(SELECT 1 FROM flow WHERE path = $1 AND (workspace_id = $2 OR workspace_id \
= 'starter'))",
"SELECT EXISTS(SELECT 1 FROM flow WHERE path = $1 AND workspace_id = $2)",
path,
w_id
)
Expand Down Expand Up @@ -494,6 +494,42 @@ async fn archive_flow_by_path(
Ok(format!("Flow {path} archived"))
}

async fn delete_flow_by_path(
authed: Authed,
Extension(user_db): Extension<UserDB>,
Extension(webhook): Extension<WebhookShared>,
Path((w_id, path)): Path<(String, StripPath)>,
) -> Result<String> {
let path = path.to_path();
let mut tx = user_db.begin(&authed).await?;

sqlx::query!(
"DELETE FROM flow WHERE path = $1 AND workspace_id = $2",
path,
&w_id
)
.execute(&mut tx)
.await?;

audit_log(
&mut tx,
&authed.username,
"flows.delete",
ActionKind::Delete,
&w_id,
Some(path),
Some([("workspace", w_id.as_str())].into()),
)
.await?;
tx.commit().await?;
webhook.send_message(
w_id.clone(),
WebhookMessage::DeleteFlow { workspace: w_id, path: path.to_owned() },
);

Ok(format!("Flow {path} deleted"))
}

#[cfg(test)]
mod tests {

Expand Down
1 change: 1 addition & 0 deletions backend/windmill-api/src/webhook_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub enum WebhookMessage {
CreateFlow { workspace: String, path: String },
UpdateFlow { workspace: String, old_path: String, new_path: String },
ArchiveFlow { workspace: String, path: String },
DeleteFlow { workspace: String, path: String },
CreateFolder { workspace: String, name: String },
UpdateFolder { workspace: String, name: String },
DeleteFolder { workspace: String, name: String },
Expand Down
1 change: 0 additions & 1 deletion backend/windmill-api/src/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use axum::{
routing::{delete, get, post},
Json, Router,
};
use serde_json::to_string_pretty;
use stripe::CustomerId;
use windmill_audit::{audit_log, ActionKind};
use windmill_common::{
Expand Down
5 changes: 1 addition & 4 deletions cli/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ export class FlowFile implements Resource, PushDiffs {
path: remotePath,
})
) {
console.log({
workspace: workspace,
path: remotePath,
})
console.log(
colors.bold.yellow(
`Applying ${diffs.length} diffs to existing flow... ${remotePath}`,
Expand Down Expand Up @@ -126,6 +122,7 @@ export class FlowFile implements Resource, PushDiffs {
path: remotePath,
});
} catch {

remote = undefined;
}
await this.pushDiffs(
Expand Down
1 change: 0 additions & 1 deletion cli/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ async function push(opts: GlobalOptions & { raw: boolean, yes: boolean }) {
remotePath = parts[0];
}
}
console.log(diffs)
return file.pushDiffs(workspace, remotePath, diffs);
}
}
Expand Down
22 changes: 21 additions & 1 deletion frontend/src/lib/components/common/table/FlowRow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
faFileExport,
faList,
faPlay,
faShare
faShare,
faTrashAlt
} from '@fortawesome/free-solid-svg-icons'
import { MoreVertical } from 'lucide-svelte'
import { createEventDispatcher } from 'svelte'
Expand All @@ -43,6 +44,16 @@
sendUserToast(`Could not archive this flow ${err.body}`, true)
}
}
async function deleteFlow(path: string): Promise<void> {
try {
await FlowService.deleteFlowByPath({ workspace: $workspaceStore!, path })
dispatch('change')
sendUserToast(`Deleted flow ${path}`)
} catch (err) {
sendUserToast(`Could not delete this flow ${err.body}`, true)
}
}
let scheduleEditor: ScheduleEditor
</script>

Expand Down Expand Up @@ -166,6 +177,15 @@
},
type: 'delete',
disabled: !canWrite
},
{
displayName: 'Delete',
icon: faTrashAlt,
action: () => {
path ? deleteFlow(path) : null
},
type: 'delete',
disabled: !canWrite
}
]}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
faCodeFork,
faClipboard,
faChevronUp,
faChevronDown
faChevronDown,
faTrash
} from '@fortawesome/free-solid-svg-icons'
import Tooltip from '$lib/components/Tooltip.svelte'
Expand Down Expand Up @@ -85,6 +86,12 @@
loadFlow()
}
async function deleteFlow(): Promise<void> {
await FlowService.deleteFlowByPath({ workspace: $workspaceStore!, path })
sendUserToast('Flow deleted')
goto('/')
}
async function setScheduleEnabled(path: string, enabled: boolean): Promise<void> {
try {
await ScheduleService.setScheduleEnabled({
Expand Down Expand Up @@ -416,6 +423,16 @@
>
Archive
</Button>
<Button
on:click={() => flow?.path && deleteFlow()}
variant="border"
color="red"
size="md"
startIcon={{ icon: faTrash }}
disabled={flow.archived || !can_write}
>
Delete
</Button>
</div>
{/if}
</div>
Expand Down

0 comments on commit e81f7bd

Please sign in to comment.