Pārlūkot izejas kodu

更新 AccountServiceImpl#updateAccountRole 方法中对拥有 admin role 用户数量的统计

reghao 1 gadu atpakaļ
vecāks
revīzija
813f41f339

+ 6 - 3
mgr/src/main/java/cn/reghao/devops/mgr/admin/account/service/impl/AccountServiceImpl.java

@@ -114,9 +114,12 @@ public class AccountServiceImpl implements AccountService {
         }
 
         Role role = accountRole.getRole();
-        int total = userRepository.countByRole_id(role.getId());
-        if (total > 2) {
-            return Result.fail("admin role 最多只能有两个用户拥有");
+        int id = role.getId();
+        if (id == 1) {
+            int total = userRepository.countByRole_id(role.getId());
+            if (total >= 2) {
+                return Result.fail("系统最多允许 2 个用户拥有 admin role");
+            }
         }
 
         userEntity.setRole(role);