From 29db0ca1d555564e9b06ecd8e04206c12ce08cf5 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Thu, 7 Sep 2023 01:09:10 +0200 Subject: [PATCH] fix: add list resource types names --- backend/windmill-api/openapi.yaml | 27 +++++++++++++++++++ backend/windmill-api/src/groups.rs | 3 +-- backend/windmill-api/src/resources.rs | 27 +++++++++++++++++++ .../src/lib/components/SchemaModal.svelte | 2 +- .../apps/components/helpers/eval.ts | 2 +- 5 files changed, 57 insertions(+), 4 deletions(-) diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index dd8bd571ca..9eec9d82fc 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -2004,6 +2004,33 @@ paths: items: $ref: "#/components/schemas/ListableResource" + /w/{workspace}/resources/list_names/{name}: + get: + summary: list resource names + operationId: listResourceNames + tags: + - resource + parameters: + - $ref: "#/components/parameters/WorkspaceId" + - $ref: "#/components/parameters/Name" + responses: + "200": + description: resource list names + content: + application/json: + schema: + type: array + items: + type: object + properties: + name: + type: string + path: + type: string + required: + - name + - path + /w/{workspace}/resources/type/create: post: summary: create resource_type diff --git a/backend/windmill-api/src/groups.rs b/backend/windmill-api/src/groups.rs index f7f0b674dc..b557cdfbf7 100644 --- a/backend/windmill-api/src/groups.rs +++ b/backend/windmill-api/src/groups.rs @@ -536,8 +536,7 @@ struct IGroup { name: String, emails: Option>, } -async fn list_igroups(authed: ApiAuthed, Extension(db): Extension) -> JsonResult> { - require_super_admin(&db, &authed.email).await?; +async fn list_igroups(Extension(db): Extension) -> JsonResult> { let mut tx: Transaction<'_, Postgres> = db.begin().await?; let groups = sqlx::query_as!( diff --git a/backend/windmill-api/src/resources.rs b/backend/windmill-api/src/resources.rs index 73e237e6ae..a5f91d1496 100644 --- a/backend/windmill-api/src/resources.rs +++ b/backend/windmill-api/src/resources.rs @@ -31,6 +31,7 @@ use windmill_common::{ pub fn workspaced_service() -> Router { Router::new() .route("/list", get(list_resources)) + .route("/list_names/:type", get(list_names)) .route("/get/*path", get(get_resource)) .route("/exists/*path", get(exists_resource)) .route("/get_value/*path", get(get_resource_value)) @@ -117,6 +118,32 @@ pub struct ListResourceQuery { resource_type: Option, resource_type_exclude: Option, } + +#[derive(Serialize, FromRow)] +pub struct NamePath { + name: String, + path: String, +} +async fn list_names( + authed: ApiAuthed, + Path((w_id, rt)): Path<(String, String)>, + Extension(user_db): Extension, +) -> JsonResult> { + let mut tx = user_db.begin(&authed).await?; + let rows = sqlx::query!( + "SELECT value->>'name' as name, path from resource WHERE resource_type = $1 AND workspace_id = $2", + rt, + &w_id + ) + .fetch_all(&mut *tx) + .await? + .into_iter() + .filter_map(|x| x.name.map(|name| NamePath { name, path: x.path })) + .collect::>(); + tx.commit().await?; + Ok(Json(rows)) +} + async fn list_resources( authed: ApiAuthed, Query(lq): Query, diff --git a/frontend/src/lib/components/SchemaModal.svelte b/frontend/src/lib/components/SchemaModal.svelte index 6bf0c5a0c7..a420a3ff05 100644 --- a/frontend/src/lib/components/SchemaModal.svelte +++ b/frontend/src/lib/components/SchemaModal.svelte @@ -255,7 +255,7 @@