ソースを参照

admin role 最多可由两个用户拥有

reghao 1 年間 前
コミット
5b6dc12f5e

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

@@ -106,7 +106,7 @@ public class AccountServiceImpl implements AccountService {
     public Result updateAccountRole(AccountRole accountRole) {
         int userId = accountRole.getUserId();
         if (userId == 1) {
-            return Result.fail("admin 用户的 role 只能是 admin, 不能更改");
+            return Result.fail("admin 用户的 role 不能更改");
         }
 
         User userEntity = userRepository.findById(userId).orElse(null);
@@ -115,8 +115,9 @@ public class AccountServiceImpl implements AccountService {
         }
 
         Role role = accountRole.getRole();
-        if (role.getName().equals(RoleType.ROLE_ADMIN.name())) {
-            return Result.fail("只有 admin 用户才能拥有 admin role");
+        int total = userRepository.countByRole_id(role.getId());
+        if (total > 2) {
+            return Result.fail("admin role 最多只能有两个用户拥有");
         }
 
         userEntity.setRole(role);