diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 9f9ed36d07..d0233bf7ed 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -4094,7 +4094,7 @@ dependencies = [ [[package]] name = "windmill-api" -version = "1.54.0" +version = "1.55.0" dependencies = [ "anyhow", "argon2", @@ -4145,7 +4145,7 @@ dependencies = [ [[package]] name = "windmill-api-client" -version = "1.54.0" +version = "1.55.0" dependencies = [ "base64", "chrono", @@ -4160,7 +4160,7 @@ dependencies = [ [[package]] name = "windmill-audit" -version = "1.54.0" +version = "1.55.0" dependencies = [ "chrono", "serde", @@ -4173,7 +4173,7 @@ dependencies = [ [[package]] name = "windmill-common" -version = "1.54.0" +version = "1.55.0" dependencies = [ "anyhow", "axum", @@ -4197,7 +4197,7 @@ dependencies = [ [[package]] name = "windmill-parser" -version = "1.54.0" +version = "1.55.0" dependencies = [ "serde", "serde_json", @@ -4205,7 +4205,7 @@ dependencies = [ [[package]] name = "windmill-parser-bash" -version = "1.54.0" +version = "1.55.0" dependencies = [ "anyhow", "itertools", @@ -4219,7 +4219,7 @@ dependencies = [ [[package]] name = "windmill-parser-go" -version = "1.54.0" +version = "1.55.0" dependencies = [ "anyhow", "itertools", @@ -4231,7 +4231,7 @@ dependencies = [ [[package]] name = "windmill-parser-py" -version = "1.54.0" +version = "1.55.0" dependencies = [ "anyhow", "itertools", @@ -4246,7 +4246,7 @@ dependencies = [ [[package]] name = "windmill-parser-ts" -version = "1.54.0" +version = "1.55.0" dependencies = [ "anyhow", "deno_core", @@ -4260,7 +4260,7 @@ dependencies = [ [[package]] name = "windmill-queue" -version = "1.54.0" +version = "1.55.0" dependencies = [ "anyhow", "chrono", @@ -4283,7 +4283,7 @@ dependencies = [ [[package]] name = "windmill-worker" -version = "1.54.0" +version = "1.55.0" dependencies = [ "anyhow", "async-recursion", diff --git a/backend/migrations/20221207103910_admins_workspace.down.sql b/backend/migrations/20221207103910_admins_workspace.down.sql new file mode 100644 index 0000000000..d2f607c5b8 --- /dev/null +++ b/backend/migrations/20221207103910_admins_workspace.down.sql @@ -0,0 +1 @@ +-- Add down migration script here diff --git a/backend/migrations/20221207103910_admins_workspace.up.sql b/backend/migrations/20221207103910_admins_workspace.up.sql new file mode 100644 index 0000000000..43c7b599a2 --- /dev/null +++ b/backend/migrations/20221207103910_admins_workspace.up.sql @@ -0,0 +1,9 @@ +INSERT INTO workspace(id, name, owner) VALUES + ('admins', 'Admins', 'admin@windmill.dev'); + +INSERT INTO workspace_settings (workspace_id) VALUES + ('admins'); + +INSERT INTO workspace_key + (workspace_id, kind, key) + VALUES ('admins', 'cloud', md5(random()::text) || md5(random()::text)) \ No newline at end of file diff --git a/backend/migrations/20221207125219_admins_hub_sync.down.sql b/backend/migrations/20221207125219_admins_hub_sync.down.sql new file mode 100644 index 0000000000..d2f607c5b8 --- /dev/null +++ b/backend/migrations/20221207125219_admins_hub_sync.down.sql @@ -0,0 +1 @@ +-- Add down migration script here diff --git a/backend/migrations/20221207125219_admins_hub_sync.up.sql b/backend/migrations/20221207125219_admins_hub_sync.up.sql new file mode 100644 index 0000000000..d7017f690f --- /dev/null +++ b/backend/migrations/20221207125219_admins_hub_sync.up.sql @@ -0,0 +1,20 @@ +INSERT INTO script(workspace_id, created_by, content, schema, summary, description, path, hash, language, lock) VALUES ( +'admins', +'system', +'import wmill from "https://deno.land/x/wmill@v1.55.0/main.ts"; + +export async function main() { + await run( + "workspace", "add", "__automation", "starter", Deno.env.get("WM_BASE_URL") + "/", "--token", Deno.env.get("WM_TOKEN")); + + await run("hub", "pull"); +} + +async function run(...cmd: string[]) { + console.log("Running \"" + cmd.join('' '') + "\""); + await wmill.parse(cmd); +}', +'{"$schema":"https://json-schema.org/draft/2020-12/schema","properties":{},"required":[],"type":"object"}', +'Syncronize Hub Resource types with starter workspace', +'Basic administrative script to sync latest resource types from hub. Recommended to run at least once. On a schedule by default.', +'u/admin/hub_sync', -28028598712388162, 'deno', ''); \ No newline at end of file diff --git a/backend/sqlx-data.json b/backend/sqlx-data.json index c8cdb89461..8382069786 100644 --- a/backend/sqlx-data.json +++ b/backend/sqlx-data.json @@ -1980,87 +1980,6 @@ }, "query": "SELECT EXISTS(SELECT 1 FROM usr WHERE workspace_id = $1 AND username = $2)" }, - "71b953191b3175a32a22f803205a5fd3dedef1baa0993afad08109ab5bf62fe9": { - "describe": { - "columns": [ - { - "name": "workspace_id", - "ordinal": 0, - "type_info": "Varchar" - }, - { - "name": "path", - "ordinal": 1, - "type_info": "Varchar" - }, - { - "name": "value", - "ordinal": 2, - "type_info": "Jsonb" - }, - { - "name": "description", - "ordinal": 3, - "type_info": "Text" - }, - { - "name": "resource_type", - "ordinal": 4, - "type_info": "Varchar" - }, - { - "name": "extra_perms", - "ordinal": 5, - "type_info": "Jsonb" - }, - { - "name": "is_expired", - "ordinal": 6, - "type_info": "Bool" - }, - { - "name": "refresh_error", - "ordinal": 7, - "type_info": "Text" - }, - { - "name": "is_linked", - "ordinal": 8, - "type_info": "Bool" - }, - { - "name": "is_oauth?", - "ordinal": 9, - "type_info": "Bool" - }, - { - "name": "account", - "ordinal": 10, - "type_info": "Int4" - } - ], - "nullable": [ - false, - false, - true, - true, - false, - false, - null, - true, - null, - false, - true - ], - "parameters": { - "Left": [ - "Text", - "Text" - ] - } - }, - "query": "SELECT resource.*, (now() > account.expires_at) as is_expired, account.refresh_error,\n variable.path IS NOT NULL as is_linked,\n variable.is_oauth as \"is_oauth?\",\n variable.account\n FROM resource\n LEFT JOIN variable ON variable.path = resource.path AND variable.workspace_id = resource.workspace_id\n LEFT JOIN account ON variable.account = account.id AND account.workspace_id = resource.workspace_id\n WHERE resource.path = $1 AND (resource.workspace_id = $2 OR resource.workspace_id = 'starter')" - }, "765c18d77412cbb4474f4074d583b9b44681f3b9f58754662ac07a3a3470a3c5": { "describe": { "columns": [ @@ -3373,6 +3292,93 @@ }, "query": "\n UPDATE capture\n SET payload = $3\n WHERE workspace_id = $1\n AND path = $2\n " }, + "b9e968d522558b8ca2bd24d345768ba864a766e10dd79864b9d601254bb2d612": { + "describe": { + "columns": [ + { + "name": "workspace_id", + "ordinal": 0, + "type_info": "Varchar" + }, + { + "name": "path", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "value", + "ordinal": 2, + "type_info": "Jsonb" + }, + { + "name": "description", + "ordinal": 3, + "type_info": "Text" + }, + { + "name": "resource_type", + "ordinal": 4, + "type_info": "Varchar" + }, + { + "name": "extra_perms", + "ordinal": 5, + "type_info": "Jsonb" + }, + { + "name": "is_expired", + "ordinal": 6, + "type_info": "Bool" + }, + { + "name": "is_refreshed", + "ordinal": 7, + "type_info": "Bool" + }, + { + "name": "refresh_error", + "ordinal": 8, + "type_info": "Text" + }, + { + "name": "is_linked", + "ordinal": 9, + "type_info": "Bool" + }, + { + "name": "is_oauth?", + "ordinal": 10, + "type_info": "Bool" + }, + { + "name": "account", + "ordinal": 11, + "type_info": "Int4" + } + ], + "nullable": [ + false, + false, + true, + true, + false, + false, + null, + null, + true, + null, + false, + true + ], + "parameters": { + "Left": [ + "Text", + "Text" + ] + } + }, + "query": "SELECT resource.*, (now() > account.expires_at) as is_expired, account.refresh_token != '' as is_refreshed,\n account.refresh_error,\n variable.path IS NOT NULL as is_linked,\n variable.is_oauth as \"is_oauth?\",\n variable.account\n FROM resource\n LEFT JOIN variable ON variable.path = resource.path AND variable.workspace_id = resource.workspace_id\n LEFT JOIN account ON variable.account = account.id AND account.workspace_id = resource.workspace_id\n WHERE resource.path = $1 AND (resource.workspace_id = $2 OR resource.workspace_id = 'starter')" + }, "bb56e61c7cfb09c0a28fb3226dfe91704c70d9fe15eda18e6889adfd7496f80b": { "describe": { "columns": [ diff --git a/backend/windmill-api/src/workspaces.rs b/backend/windmill-api/src/workspaces.rs index 094128f604..6fad06f1aa 100644 --- a/backend/windmill-api/src/workspaces.rs +++ b/backend/windmill-api/src/workspaces.rs @@ -426,6 +426,15 @@ async fn delete_workspace( Path(w_id): Path, Authed { is_admin, username, email, .. }: Authed, ) -> Result { + let w_id = match w_id.as_str() { + "starter" => Err(Error::BadRequest( + "starter workspace cannot be deleted".to_string(), + )), + "admins" => Err(Error::BadRequest( + "admins workspace cannot be deleted".to_string(), + )), + _ => Ok(w_id), + }?; require_admin(is_admin, &username)?; let mut tx = db.begin().await?; sqlx::query!("UPDATE workspace SET deleted = true WHERE id = $1", &w_id) diff --git a/frontend/src/lib/components/sidebar/WorkspaceMenu.svelte b/frontend/src/lib/components/sidebar/WorkspaceMenu.svelte index dd4b026529..dc884654cc 100644 --- a/frontend/src/lib/components/sidebar/WorkspaceMenu.svelte +++ b/frontend/src/lib/components/sidebar/WorkspaceMenu.svelte @@ -1,5 +1,5 @@