mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-21 00:02:23 +00:00
fix: Safeguard prevents button from deleting non-fork workspaces (#6795)
* Fix: Safeguard to prevent `delete fork` button from deleting non-fork workspaces * fix typo * Consistent prefix
This commit is contained in:
@@ -1718,6 +1718,11 @@ paths:
|
||||
- workspace
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/WorkspaceId"
|
||||
- name: only_delete_forks
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
type: boolean
|
||||
responses:
|
||||
"200":
|
||||
description: status
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::db::ApiAuthed;
|
||||
use crate::workspaces::{check_w_id_conflict, CREATE_WORKSPACE_REQUIRE_SUPERADMIN, WM_FORK_PREFIX};
|
||||
use crate::{db::DB, utils::require_super_admin};
|
||||
|
||||
use axum::extract::Query;
|
||||
use axum::{
|
||||
extract::{Extension, Path},
|
||||
Json,
|
||||
@@ -415,10 +416,16 @@ pub(crate) async fn change_workspace_id(
|
||||
))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub(crate) struct DeleteWorkspaceQuery {
|
||||
pub(crate) only_delete_forks: Option<bool>,
|
||||
}
|
||||
|
||||
pub(crate) async fn delete_workspace(
|
||||
Extension(db): Extension<DB>,
|
||||
Path(w_id): Path<String>,
|
||||
authed: ApiAuthed,
|
||||
Query(dwq): Query<DeleteWorkspaceQuery>,
|
||||
) -> Result<String> {
|
||||
let w_id = match w_id.as_str() {
|
||||
"starter" => Err(Error::BadRequest(
|
||||
@@ -429,6 +436,13 @@ pub(crate) async fn delete_workspace(
|
||||
)),
|
||||
_ => Ok(w_id),
|
||||
}?;
|
||||
|
||||
if dwq.only_delete_forks.unwrap_or(false) && !w_id.starts_with(WM_FORK_PREFIX) {
|
||||
return Err(Error::BadRequest(
|
||||
"Cannot delete this workspace because it is not a workspace fork.".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
let mut tx = db.begin().await?;
|
||||
if !(w_id.starts_with(WM_FORK_PREFIX) && is_workspace_owner(&authed, &w_id, &mut tx).await?) {
|
||||
require_super_admin(&db, &authed.email).await?;
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
}
|
||||
|
||||
async function deleteFork() {
|
||||
await WorkspaceService.deleteWorkspace({ workspace: $workspaceStore ?? '' })
|
||||
await WorkspaceService.deleteWorkspace({ workspace: $workspaceStore ?? '', onlyDeleteForks: true })
|
||||
sendUserToast('You deleted the workspace')
|
||||
clearStores()
|
||||
goto('/user/workspaces')
|
||||
@@ -364,7 +364,7 @@
|
||||
}
|
||||
]
|
||||
: []),
|
||||
...($workspaceStore?.startsWith('wm-fork')
|
||||
...($workspaceStore?.startsWith('wm-fork-')
|
||||
? [
|
||||
{
|
||||
label: 'Delete Forked Workspace',
|
||||
|
||||
Reference in New Issue
Block a user