fix: add list resource types names

This commit is contained in:
Ruben Fiszel
2023-09-07 01:09:10 +02:00
parent cb3f6510ff
commit 29db0ca1d5
5 changed files with 57 additions and 4 deletions
+27
View File
@@ -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
+1 -2
View File
@@ -536,8 +536,7 @@ struct IGroup {
name: String,
emails: Option<Vec<String>>,
}
async fn list_igroups(authed: ApiAuthed, Extension(db): Extension<DB>) -> JsonResult<Vec<IGroup>> {
require_super_admin(&db, &authed.email).await?;
async fn list_igroups(Extension(db): Extension<DB>) -> JsonResult<Vec<IGroup>> {
let mut tx: Transaction<'_, Postgres> = db.begin().await?;
let groups = sqlx::query_as!(
+27
View File
@@ -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<String>,
resource_type_exclude: Option<String>,
}
#[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<UserDB>,
) -> JsonResult<Vec<NamePath>> {
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::<Vec<_>>();
tx.commit().await?;
Ok(Json(rows))
}
async fn list_resources(
authed: ApiAuthed,
Query(lq): Query<ListResourceQuery>,
@@ -255,7 +255,7 @@
<svelte:fragment slot="actions">
<Button
color="blue"
disabled={!property.name || !property.selectedType || error != ''}
disabled={!property.name || error != ''}
on:click={() => {
dispatch('save', property)
}}
@@ -114,13 +114,13 @@ export async function eval_like(
if (typeof key !== 'string') {
throw new Error('Invalid key')
}
target[key] = value
let o = worldStore?.newOutput('state', key, value)
if (isSerializable(value)) {
o?.set(value, true)
} else {
o?.set('Not serializable object usable only by frontend scripts', true)
}
target[key] = value
return true
}
})