|
@@ -106,7 +106,7 @@ public class AccountServiceImpl implements AccountService {
|
|
|
public Result updateAccountRole(AccountRole accountRole) {
|
|
public Result updateAccountRole(AccountRole accountRole) {
|
|
|
int userId = accountRole.getUserId();
|
|
int userId = accountRole.getUserId();
|
|
|
if (userId == 1) {
|
|
if (userId == 1) {
|
|
|
- return Result.fail("admin 用户的 role 只能是 admin, 不能更改");
|
|
|
|
|
|
|
+ return Result.fail("admin 用户的 role 不能更改");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
User userEntity = userRepository.findById(userId).orElse(null);
|
|
User userEntity = userRepository.findById(userId).orElse(null);
|
|
@@ -115,8 +115,9 @@ public class AccountServiceImpl implements AccountService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Role role = accountRole.getRole();
|
|
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);
|
|
userEntity.setRole(role);
|