From af579811a9bb9a3eb84140650981d779d47bd0a3 Mon Sep 17 00:00:00 2001 From: Ninjdai Date: Tue, 5 Aug 2025 15:39:49 +0200 Subject: [PATCH] feat: option to add a corresponding owner when creating users in CLI --- src/utils/cli.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/utils/cli.rs b/src/utils/cli.rs index 0c1ce3e..55722a6 100644 --- a/src/utils/cli.rs +++ b/src/utils/cli.rs @@ -1,11 +1,11 @@ use std::{fmt::Display, sync::Arc}; use argon2::{password_hash::{SaltString}, Argon2, PasswordHasher}; -use inquire::{min_length, Confirm, Password, Select, Text}; +use inquire::{min_length, prompt_text, Confirm, Password, Select, Text}; use password_hash::rand_core::OsRng; use sea_orm::{ActiveModelTrait, ActiveValue::{NotSet, Set}, ColumnTrait, DatabaseConnection, EntityTrait, ModelTrait, QueryFilter}; -use crate::entities::{prelude::User, user::{self, ActiveModel}}; +use crate::entities::{owner, prelude::User, user::{self, ActiveModel}}; #[derive(Debug, Copy, Clone)] enum Action { @@ -66,7 +66,21 @@ pub async fn manage_users(db: Arc) { username: Set(username), hashed_password: Set(hash_password(password)) }; - let _ = new_user.insert(db.as_ref()).await; + let res = new_user.insert(db.as_ref()).await.unwrap(); + + if Confirm::new("Add an owner corresponding to this user ?").with_default(true).prompt().is_ok_and(|choice| choice==true) { + let first_name = prompt_text("First Name: ").unwrap(); + let last_name = prompt_text("Last Name: ").unwrap(); + let contact = prompt_text("Contact: ").unwrap(); + let new_owner = owner::ActiveModel { + id: NotSet, + user_id: Set(res.id), + first_name: Set(first_name), + last_name: Set(last_name), + contact: Set(contact) + }; + let _ = new_owner.insert(db.as_ref()).await.unwrap(); + } } }, Action::Delete => {