From 1d5ce261093eaecbae4658d88e9aa5c5c3557c53 Mon Sep 17 00:00:00 2001 From: Zzm0809 <934230207@qq.com> Date: Tue, 19 Dec 2023 12:53:57 +0800 Subject: [PATCH] fix user admin delete bug --- .../main/java/org/dinky/service/impl/UserServiceImpl.java | 5 +++++ dinky-common/src/main/java/org/dinky/data/enums/Status.java | 1 + .../src/main/resources/i18n/messages_en_US.properties | 1 + .../src/main/resources/i18n/messages_zh_CN.properties | 1 + .../pages/AuthCenter/User/components/UserProTable/index.tsx | 2 +- 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java index 5c8bc20841..d5fe4abb9e 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java @@ -31,6 +31,7 @@ import org.dinky.data.enums.Status; import org.dinky.data.enums.UserType; import org.dinky.data.exception.AuthException; +import org.dinky.data.exception.BusException; import org.dinky.data.model.SysToken; import org.dinky.data.model.SystemConfiguration; import org.dinky.data.model.rbac.Menu; @@ -152,6 +153,10 @@ public Result modifyPassword(ModifyPasswordDTO modifyPasswordDTO) { @Override public Boolean removeUser(Integer id) { + User user = getById(id); + if (user.getSuperAdminFlag()) { + throw new BusException(Status.USER_SUPERADMIN_CANNOT_DELETE); + } return baseMapper.deleteById(id) > 0; } diff --git a/dinky-common/src/main/java/org/dinky/data/enums/Status.java b/dinky-common/src/main/java/org/dinky/data/enums/Status.java index ac3f2185d9..1e77d7f0b7 100644 --- a/dinky-common/src/main/java/org/dinky/data/enums/Status.java +++ b/dinky-common/src/main/java/org/dinky/data/enums/Status.java @@ -124,6 +124,7 @@ public enum Status { KICK_OUT(10024, "kick.out"), TOKEN_FREEZED(10025, "token.freezed"), NO_PREFIX(10026, "no.prefix"), + USER_SUPERADMIN_CANNOT_DELETE(10027, "user.superadmin.cannot.delete"), // role ROLE_ALREADY_EXISTS(10101, "role.already.exists"), diff --git a/dinky-common/src/main/resources/i18n/messages_en_US.properties b/dinky-common/src/main/resources/i18n/messages_en_US.properties index f9e16b4975..f8fcd47744 100644 --- a/dinky-common/src/main/resources/i18n/messages_en_US.properties +++ b/dinky-common/src/main/resources/i18n/messages_en_US.properties @@ -7,6 +7,7 @@ ldap.user.duplicat=The ldap matches to multiple user data git.branch.not.found=Git Branch Not Found copy.success=Copy Successfully user.superadmin.cannot.disable=User SuperAdmin Cannot Disable +user.superadmin.cannot.delete=User SuperAdmin Cannot Delete ds.work.flow.not.save=Please Save Workflow First schedule.status.unknown=Unknown Status: {0} user.binding.role.delete.all=User Binding Role Delete All diff --git a/dinky-common/src/main/resources/i18n/messages_zh_CN.properties b/dinky-common/src/main/resources/i18n/messages_zh_CN.properties index dff82a03a5..ff7459310f 100644 --- a/dinky-common/src/main/resources/i18n/messages_zh_CN.properties +++ b/dinky-common/src/main/resources/i18n/messages_zh_CN.properties @@ -7,6 +7,7 @@ ldap.user.duplicat=ldap匹配到多个用户数据 git.branch.not.found=获取不到分支信息 copy.success=复制成功 user.superadmin.cannot.disable=超级管理员用户不能停用 +user.superadmin.cannot.delete=超级管理员用户不能删除 ds.work.flow.not.save=请先保存工作流 schedule.status.unknown=未知状态: {0} user.binding.role.delete.all=用户绑定角色删除所有 diff --git a/dinky-web/src/pages/AuthCenter/User/components/UserProTable/index.tsx b/dinky-web/src/pages/AuthCenter/User/components/UserProTable/index.tsx index c67eb68fd6..0025063a97 100644 --- a/dinky-web/src/pages/AuthCenter/User/components/UserProTable/index.tsx +++ b/dinky-web/src/pages/AuthCenter/User/components/UserProTable/index.tsx @@ -276,7 +276,7 @@ const UserProTable = () => { , <> - {access.isAdmin && !record.isDelete && ( + {access.isAdmin && !record.isDelete && !record.superAdminFlag && ( handleDeleteUser(record)}