From 0be1a3a09d13c430ed72ba56b2475ece84266cf8 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Thu, 14 Nov 2024 13:12:40 +0100 Subject: [PATCH] feat: allow setting password and login type from superadmin UI --- ...76f06c6077c619c0ab1ac4edf633b22df98c3.json | 23 ----- ...67e6eb876792ec8f83e9b03c2fb46bb12e0b9.json | 15 +++ ...087775a721a6ee7ae35b03fd4ce3563ea3838.json | 23 ----- ...610c021a0a5b63ffe5afd7878385c8af6bc6c.json | 24 ----- backend/ee-repo-ref.txt | 2 +- backend/windmill-api/openapi.yaml | 65 +++++++++++++ backend/windmill-api/src/users.rs | 56 ++++++++++- backend/windmill-api/src/users_ee.rs | 1 + .../ChangeInstanceUsernameInner.svelte | 6 +- .../lib/components/InstanceNameEditor.svelte | 93 ++++++++++++++++++- .../lib/components/SuperadminSettings.svelte | 4 + 11 files changed, 234 insertions(+), 78 deletions(-) delete mode 100644 backend/.sqlx/query-0f04f42a596b6759a84ba7d26ea76f06c6077c619c0ab1ac4edf633b22df98c3.json create mode 100644 backend/.sqlx/query-349396e8fdd96d45875110bc06767e6eb876792ec8f83e9b03c2fb46bb12e0b9.json delete mode 100644 backend/.sqlx/query-3e539fef054ad31bc1736e27276087775a721a6ee7ae35b03fd4ce3563ea3838.json delete mode 100644 backend/.sqlx/query-cd40b9c552d76664a552457c4a9610c021a0a5b63ffe5afd7878385c8af6bc6c.json diff --git a/backend/.sqlx/query-0f04f42a596b6759a84ba7d26ea76f06c6077c619c0ab1ac4edf633b22df98c3.json b/backend/.sqlx/query-0f04f42a596b6759a84ba7d26ea76f06c6077c619c0ab1ac4edf633b22df98c3.json deleted file mode 100644 index bf47f131c4..0000000000 --- a/backend/.sqlx/query-0f04f42a596b6759a84ba7d26ea76f06c6077c619c0ab1ac4edf633b22df98c3.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "SELECT flow_status AS \"_id!: Json>\" FROM queue WHERE id = $1 AND workspace_id = $2 LIMIT 1", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "_id!: Json>", - "type_info": "Jsonb" - } - ], - "parameters": { - "Left": [ - "Uuid", - "Text" - ] - }, - "nullable": [ - true - ] - }, - "hash": "0f04f42a596b6759a84ba7d26ea76f06c6077c619c0ab1ac4edf633b22df98c3" -} diff --git a/backend/.sqlx/query-349396e8fdd96d45875110bc06767e6eb876792ec8f83e9b03c2fb46bb12e0b9.json b/backend/.sqlx/query-349396e8fdd96d45875110bc06767e6eb876792ec8f83e9b03c2fb46bb12e0b9.json new file mode 100644 index 0000000000..032f287093 --- /dev/null +++ b/backend/.sqlx/query-349396e8fdd96d45875110bc06767e6eb876792ec8f83e9b03c2fb46bb12e0b9.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE password SET login_type = $1 WHERE email = $2", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Varchar", + "Text" + ] + }, + "nullable": [] + }, + "hash": "349396e8fdd96d45875110bc06767e6eb876792ec8f83e9b03c2fb46bb12e0b9" +} diff --git a/backend/.sqlx/query-3e539fef054ad31bc1736e27276087775a721a6ee7ae35b03fd4ce3563ea3838.json b/backend/.sqlx/query-3e539fef054ad31bc1736e27276087775a721a6ee7ae35b03fd4ce3563ea3838.json deleted file mode 100644 index f193758557..0000000000 --- a/backend/.sqlx/query-3e539fef054ad31bc1736e27276087775a721a6ee7ae35b03fd4ce3563ea3838.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "SELECT raw_flow->'modules'->($1)->'value'->>'type' = 'flow' FROM queue WHERE id = $2", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "?column?", - "type_info": "Bool" - } - ], - "parameters": { - "Left": [ - "Text", - "Uuid" - ] - }, - "nullable": [ - null - ] - }, - "hash": "3e539fef054ad31bc1736e27276087775a721a6ee7ae35b03fd4ce3563ea3838" -} diff --git a/backend/.sqlx/query-cd40b9c552d76664a552457c4a9610c021a0a5b63ffe5afd7878385c8af6bc6c.json b/backend/.sqlx/query-cd40b9c552d76664a552457c4a9610c021a0a5b63ffe5afd7878385c8af6bc6c.json deleted file mode 100644 index 382caea08a..0000000000 --- a/backend/.sqlx/query-cd40b9c552d76664a552457c4a9610c021a0a5b63ffe5afd7878385c8af6bc6c.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "SELECT raw_flow->'modules'->($1)::int AS \"_id: Json>\" FROM queue WHERE id = $2 AND workspace_id = $3 LIMIT 1", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "_id: Json>", - "type_info": "Jsonb" - } - ], - "parameters": { - "Left": [ - "Int4", - "Uuid", - "Text" - ] - }, - "nullable": [ - null - ] - }, - "hash": "cd40b9c552d76664a552457c4a9610c021a0a5b63ffe5afd7878385c8af6bc6c" -} diff --git a/backend/ee-repo-ref.txt b/backend/ee-repo-ref.txt index f3e6e24f4e..498ca96e9b 100644 --- a/backend/ee-repo-ref.txt +++ b/backend/ee-repo-ref.txt @@ -1 +1 @@ -e3df64af864f9d3546a97ff21f719c553e34ff1c \ No newline at end of file +0d9c8813acd28848515c736e7b684220b5a785a3 \ No newline at end of file diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index 97d98d3d6b..2f59c0c91c 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -283,6 +283,71 @@ paths: text/plain: schema: type: string + + /users/set_password_of/{user}: + post: + summary: set password for a specific user (require super admin) + operationId: setPasswordForUser + tags: + - user + parameters: + - name: user + in: path + required: true + schema: + type: string + requestBody: + description: set password + required: true + content: + application/json: + schema: + type: object + properties: + password: + type: string + required: + - password + responses: + "200": + description: password set + content: + text/plain: + schema: + type: string + + /users/set_login_type/{user}: + post: + summary: set login type for a specific user (require super admin) + operationId: setLoginTypeForUser + tags: + - user + parameters: + - name: user + in: path + required: true + schema: + type: string + requestBody: + description: set login type + required: true + content: + application/json: + schema: + type: object + properties: + login_type: + type: string + required: + - login_type + responses: + "200": + description: login type set + content: + text/plain: + schema: + type: string + /users/create: post: diff --git a/backend/windmill-api/src/users.rs b/backend/windmill-api/src/users.rs index 380084d524..bf95a632b1 100644 --- a/backend/windmill-api/src/users.rs +++ b/backend/windmill-api/src/users.rs @@ -90,6 +90,9 @@ pub fn global_service() -> Router { .route("/accept_invite", post(accept_invite)) .route("/list_as_super_admin", get(list_users_as_super_admin)) .route("/setpassword", post(set_password)) + .route("/set_password_of/:user", post(set_password_of_user)) + .route("/set_login_type/:user", post(set_login_type)) + .route("/create", post(create_user)) .route("/update/:user", post(update_user)) .route("/delete/:user", delete(delete_user)) @@ -866,6 +869,12 @@ pub struct EditPassword { pub password: String, } +#[derive(Deserialize)] +pub struct EditLoginType { + pub login_type: String, +} + + #[derive(FromRow, Serialize)] pub struct TruncatedToken { pub label: Option, @@ -2028,7 +2037,52 @@ async fn set_password( authed: ApiAuthed, Json(ep): Json, ) -> Result { - crate::users_ee::set_password(db, argon2, authed, ep).await + let email = authed.email.clone(); + crate::users_ee::set_password(db, argon2, authed, &email, ep).await +} + +async fn set_password_of_user( + Extension(db): Extension, + Extension(argon2): Extension>>, + Path(email): Path, + authed: ApiAuthed, + Json(ep): Json, +) -> Result { + require_super_admin(&db, &authed.email).await?; + crate::users_ee::set_password(db, argon2, authed, &email, ep).await +} + +async fn set_login_type( + Extension(db): Extension, + Path(email): Path, + authed: ApiAuthed, + Json(et): Json, +) -> Result { + require_super_admin(&db, &authed.email).await?; + let mut tx = db.begin().await?; + + sqlx::query!( + "UPDATE password SET login_type = $1 WHERE email = $2", + et.login_type, + email + ) + .execute(&mut *tx) + .await?; + + audit_log( + &mut *tx, + &authed, + "users.set_login_type", + ActionKind::Update, + "global", + Some(&email), + None, + ) + .await?; + + tx.commit().await?; + Ok(format!("login type of {} updated to {}", email, et.login_type)) + } async fn login( diff --git a/backend/windmill-api/src/users_ee.rs b/backend/windmill-api/src/users_ee.rs index e0f15a9317..65a2a2ed17 100644 --- a/backend/windmill-api/src/users_ee.rs +++ b/backend/windmill-api/src/users_ee.rs @@ -27,6 +27,7 @@ pub async fn set_password( _db: DB, _argon2: Arc>, _authed: ApiAuthed, + _user_email: &str, _ep: EditPassword, ) -> Result { Err(Error::InternalErr( diff --git a/frontend/src/lib/components/ChangeInstanceUsernameInner.svelte b/frontend/src/lib/components/ChangeInstanceUsernameInner.svelte index a321f4ac1d..1690dcd4f3 100644 --- a/frontend/src/lib/components/ChangeInstanceUsernameInner.svelte +++ b/frontend/src/lib/components/ChangeInstanceUsernameInner.svelte @@ -72,11 +72,13 @@
+ {#if isConflict} {isConflict ? 'Fix username conflict' : 'Change username'}Fix username conflict + {/if} - {isConflict ? 'Auto-generated instance username' : 'New username'} {/if} diff --git a/frontend/src/lib/components/SuperadminSettings.svelte b/frontend/src/lib/components/SuperadminSettings.svelte index 1670a51086..e47466a02a 100644 --- a/frontend/src/lib/components/SuperadminSettings.svelte +++ b/frontend/src/lib/components/SuperadminSettings.svelte @@ -276,9 +276,13 @@
{ + listUsers(activeOnly) + }} on:save={(e) => { updateName(e.detail, email) }}