From 60fd3816a74cabbad309d1320fb21121001e0b8d Mon Sep 17 00:00:00 2001
From: liuxinhao <liuxinhao@kylinos.com.cn>
Date: Wed, 19 Jan 2022 15:22:48 +0800
Subject: [PATCH] fix(create user): the user was created successfully, but the
 property setting failed. The user will not be deleted
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- 创建用户成功，设置属性失败不删除用户，弹窗警告用户

Closes #47439

Signed-off-by: liuxinhao <liuxinhao@kylinos.com.cn>
---
 src/hard-worker.cpp                           |  6 +-
 .../advance-settings.cpp                      |  2 +-
 .../create-user-page/create-user-page.cpp     | 10 ++-
 translations/kiran-cpanel-account.zh_CN.ts    | 85 ++++++++++---------
 4 files changed, 58 insertions(+), 45 deletions(-)

diff --git a/src/hard-worker.cpp b/src/hard-worker.cpp
index 89ac041..3ab232c 100644
--- a/src/hard-worker.cpp
+++ b/src/hard-worker.cpp
@@ -110,7 +110,10 @@ void HardWorker::doCreateUser(QString userName,
     KLOG_INFO() << QString("create user(%1) is done").arg(userName);
     emit sigCreateUserDnoe(userObjPath, "");
     return;
+
 failed:
+    //NOTE:创建用户成功，设置用户属性失败时，不再删除用户
+#if 0
     if (!userObjPath.isEmpty())
     {
         KSDAccountsUserProxy userInterface(ACCOUNTS_DBUS_NAME,
@@ -125,13 +128,14 @@ failed:
             KLOG_WARNING() << "create user failed,delete user:" << reply.error();
         }
     }
+#endif
     QString errMsg = errMsgPrefix;
     if (!errMsgDetail.isEmpty())
     {
         errMsg.append(",");
         errMsg.append(errMsgDetail);
     }
-    emit sigCreateUserDnoe("", errMsg);
+    emit sigCreateUserDnoe(userObjPath, errMsg);
 }
 
 void HardWorker::doUpdatePasswd(QString objPath,
diff --git a/src/pages/advance-settings-page/advance-settings.cpp b/src/pages/advance-settings-page/advance-settings.cpp
index 3fd7900..244cf00 100644
--- a/src/pages/advance-settings-page/advance-settings.cpp
+++ b/src/pages/advance-settings-page/advance-settings.cpp
@@ -58,7 +58,7 @@ void AdvanceSettings::setInfo(QString userName, AdvanceSettingsInfo &info)
     }
     else
     {
-        ui->edit_loginShell->clear();
+        ui->edit_loginShell->setText(DEFAULT_SHELL);
     }
 
     ///缓存账用户信息，当特殊用户Home目录设置关闭时，重新生成Home目录路径
diff --git a/src/pages/create-user-page/create-user-page.cpp b/src/pages/create-user-page/create-user-page.cpp
index 69092a6..7f3956e 100644
--- a/src/pages/create-user-page/create-user-page.cpp
+++ b/src/pages/create-user-page/create-user-page.cpp
@@ -241,11 +241,15 @@ void CreateUserPage::handlerCreateNewUserIsDone(QString userPath,
 {
     emit sigIsBusyChanged(false);
     ui->btn_confirm->setBusy(false);
-    if (!errMsg.isEmpty())
+    if (!errMsg.isEmpty() && userPath.isEmpty())
     {
-        KiranMessageBox::message(nullptr, tr("Error"),
-                                 errMsg, KiranMessageBox::Yes | KiranMessageBox::No);
+        KiranMessageBox::message(nullptr, tr("Error"),errMsg, KiranMessageBox::Ok);
     }
+    else if(!errMsg.isEmpty() && !userPath.isEmpty())
+    {
+        KiranMessageBox::message(nullptr,tr("Warning"),errMsg,KiranMessageBox::Ok);
+    }
+
     if (!userPath.isEmpty())
     {
         emit sigRequestSetCurrentUser(userPath);
diff --git a/translations/kiran-cpanel-account.zh_CN.ts b/translations/kiran-cpanel-account.zh_CN.ts
index 9a48aef..6b430c9 100644
--- a/translations/kiran-cpanel-account.zh_CN.ts
+++ b/translations/kiran-cpanel-account.zh_CN.ts
@@ -76,8 +76,8 @@
         <translation>取消</translation>
     </message>
     <message>
-        <location filename="../src/pages/advance-settings-page/advance-settings.cpp" line="129"/>
-        <location filename="../src/pages/advance-settings-page/advance-settings.cpp" line="139"/>
+        <location filename="../src/pages/advance-settings-page/advance-settings.cpp" line="130"/>
+        <location filename="../src/pages/advance-settings-page/advance-settings.cpp" line="140"/>
         <source>Automatically generated by system</source>
         <translation>由系统自动生成</translation>
     </message>
@@ -89,17 +89,17 @@
         <translation>指定用户目录</translation>
     </message>
     <message>
-        <location filename="../src/pages/advance-settings-page/advance-settings.cpp" line="171"/>
+        <location filename="../src/pages/advance-settings-page/advance-settings.cpp" line="172"/>
         <source>Please enter the correct path</source>
         <translation>请输入正确的路径</translation>
     </message>
     <message>
-        <location filename="../src/pages/advance-settings-page/advance-settings.cpp" line="179"/>
+        <location filename="../src/pages/advance-settings-page/advance-settings.cpp" line="180"/>
         <source>Please enter specify user Id</source>
         <translation>请输入用户ID</translation>
     </message>
     <message>
-        <location filename="../src/pages/advance-settings-page/advance-settings.cpp" line="187"/>
+        <location filename="../src/pages/advance-settings-page/advance-settings.cpp" line="188"/>
         <source>Please enter the correct home directory</source>
         <translation>请输入正确的用户目录</translation>
     </message>
@@ -212,12 +212,12 @@
         <translation type="vanished">账户类型</translation>
     </message>
     <message>
-        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="83"/>
+        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="84"/>
         <source>standard</source>
         <translation>普通用户</translation>
     </message>
     <message>
-        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="84"/>
+        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="85"/>
         <source>administrator</source>
         <translation>管理员</translation>
     </message>
@@ -298,51 +298,56 @@
         <translation type="vanished">请输入用户名</translation>
     </message>
     <message>
-        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="107"/>
+        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="108"/>
         <source>Please enter user name first</source>
         <translation>请输入用户名</translation>
     </message>
     <message>
-        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="141"/>
+        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="142"/>
         <source>Please enter your user name</source>
         <translation>请输入用户名</translation>
     </message>
     <message>
-        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="157"/>
+        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="158"/>
         <source>user name cannot be a pure number</source>
         <translation>用户名不能全为数字</translation>
     </message>
     <message>
-        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="164"/>
+        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="165"/>
         <source>user name already exists</source>
         <translation>用户名已存在</translation>
     </message>
     <message>
-        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="176"/>
+        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="177"/>
         <source>Please enter your password</source>
         <translation type="unfinished">请输入密码</translation>
     </message>
     <message>
-        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="183"/>
+        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="184"/>
         <source>Please enter the password again</source>
         <translation>请再次输入密码</translation>
     </message>
     <message>
-        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="190"/>
+        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="191"/>
         <source>The password you enter must be the same as the former one</source>
         <translation>两次密码不相同，请核对后，再次输入</translation>
     </message>
     <message>
-        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="200"/>
-        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="235"/>
+        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="211"/>
+        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="247"/>
         <source>Error</source>
         <translation>错误</translation>
     </message>
     <message>
-        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="200"/>
+        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="211"/>
         <source>Password encryption failed</source>
         <translation>密码加密失败</translation>
     </message>
+    <message>
+        <location filename="../src/pages/create-user-page/create-user-page.cpp" line="251"/>
+        <source>Warning</source>
+        <translation type="unfinished">警告</translation>
+    </message>
 </context>
 <context>
     <name>FaceEnrollDialog</name>
@@ -520,17 +525,17 @@
         <translation type="vanished">设置用户属性失败</translation>
     </message>
     <message>
-        <location filename="../src/hard-worker.cpp" line="147"/>
+        <location filename="../src/hard-worker.cpp" line="151"/>
         <source> update password failed</source>
         <translation>更新密码失败</translation>
     </message>
     <message>
-        <location filename="../src/hard-worker.cpp" line="173"/>
+        <location filename="../src/hard-worker.cpp" line="177"/>
         <source>icon file</source>
         <translation>头像</translation>
     </message>
     <message>
-        <location filename="../src/hard-worker.cpp" line="184"/>
+        <location filename="../src/hard-worker.cpp" line="188"/>
         <source>userName type</source>
         <translation>用户名</translation>
     </message>
@@ -539,12 +544,12 @@
         <translation type="vanished">账户类型</translation>
     </message>
     <message>
-        <location filename="../src/hard-worker.cpp" line="195"/>
+        <location filename="../src/hard-worker.cpp" line="199"/>
         <source>locked</source>
         <translation>启用状态</translation>
     </message>
     <message>
-        <location filename="../src/hard-worker.cpp" line="203"/>
+        <location filename="../src/hard-worker.cpp" line="207"/>
         <source>Failed to update user properties,%1</source>
         <translation>更新用户属性失败，%1</translation>
     </message>
@@ -553,7 +558,7 @@
         <translation type="vanished">更新用户属性失败(%1)</translation>
     </message>
     <message>
-        <location filename="../src/hard-worker.cpp" line="226"/>
+        <location filename="../src/hard-worker.cpp" line="230"/>
         <source>Failed to delete user,%1</source>
         <translation>删除用户失败，%1</translation>
     </message>
@@ -837,12 +842,12 @@
         <translation>取消</translation>
     </message>
     <message>
-        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="141"/>
+        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="143"/>
         <source>standard</source>
         <translation>普通用户</translation>
     </message>
     <message>
-        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="142"/>
+        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="144"/>
         <source>administrator</source>
         <translation>管理员</translation>
     </message>
@@ -851,65 +856,65 @@
         <translation type="vanished">账户信息更新成功</translation>
     </message>
     <message>
-        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="326"/>
+        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="338"/>
         <source>Password updated successfully</source>
         <translation>密码更新成功</translation>
     </message>
     <message>
-        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="332"/>
+        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="344"/>
         <source>The directory and files under the user&apos;s home directory are deleted with the user.Are you sure you want to delete the user(%1)?</source>
         <translation>用户目录下的目录和文件会随用户一起删除，确定要删除%1用户吗？</translation>
     </message>
     <message>
-        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="335"/>
+        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="347"/>
         <source>Warning</source>
         <translation>警告</translation>
     </message>
     <message>
-        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="217"/>
+        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="219"/>
         <source>Please enter the new user password</source>
         <translation>请输入新密码</translation>
     </message>
     <message>
-        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="225"/>
+        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="227"/>
         <source>Please enter the password again</source>
         <translation>请再次输入密码</translation>
     </message>
     <message>
-        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="231"/>
+        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="233"/>
         <source>The password you enter must be the same as the former one</source>
         <translation>两次密码不相同，请核对后，再次输入</translation>
     </message>
     <message>
-        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="242"/>
+        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="244"/>
         <source>Please enter the current user password</source>
         <translation>请输入当前密码</translation>
     </message>
     <message>
-        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="248"/>
+        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="250"/>
         <source>The current password is incorrect</source>
         <translation>当前密码错误，请再次输入</translation>
     </message>
     <message>
-        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="255"/>
+        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="257"/>
         <source>The new password cannot be the same as the current password</source>
         <translation>新密码不能和旧密码相同，请重新输入</translation>
     </message>
     <message>
-        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="264"/>
-        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="301"/>
-        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="320"/>
-        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="354"/>
+        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="276"/>
+        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="313"/>
+        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="332"/>
+        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="366"/>
         <source>Error</source>
         <translation>错误</translation>
     </message>
     <message>
-        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="264"/>
+        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="276"/>
         <source>Password encryption failed</source>
         <translation>密码加密失败</translation>
     </message>
     <message>
-        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="306"/>
+        <location filename="../src/pages/user-info-page/user-info-page.cpp" line="318"/>
         <source>user information updated successfully</source>
         <translation>用户信息更新成功</translation>
     </message>
-- 
2.27.0

