From fb7391a29ca96764eab3eb22d16ffc102218ad16 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Tue, 6 Aug 2024 23:41:11 +0200 Subject: [PATCH] edit-db-perm: ensure user exists before applying changes --- src/cli/database_command.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cli/database_command.rs b/src/cli/database_command.rs index 372bf64..998524e 100644 --- a/src/cli/database_command.rs +++ b/src/cli/database_command.rs @@ -11,7 +11,7 @@ use crate::core::{ database_operations::{ apply_permission_diffs, db_priv_field_human_readable_name, diff_permissions, yn, DatabasePrivileges, DATABASE_PRIVILEGE_FIELDS, - }, + }, user_operations::user_exists, }; // TODO: Support batch creation/dropping,showing of databases, @@ -519,6 +519,13 @@ pub async fn edit_permissions( .context("Could not parse permission data from editor")? }; + for row in permissions_to_change.iter() { + if !user_exists(&row.user, conn).await? { + // TODO: allow user to return and correct their mistake + anyhow::bail!("User {} does not exist", row.user); + } + } + let diffs = diff_permissions(permission_data, &permissions_to_change).await; if diffs.is_empty() { -- 2.44.2