fix 修复 移除超级管理员角色后新增角色分配校验,避免无角色分配时报错

This commit is contained in:
疯狂的狮子Li
2026-03-06 13:08:05 +08:00
parent d190b89681
commit 9bf8ae5583

View File

@@ -497,6 +497,11 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
roleList.remove(SystemConstants.SUPER_ADMIN_ID);
}
// 移除超管角色后若无剩余角色,说明仅选了超管角色且不允许分配,显式报错
if (roleList.isEmpty()) {
throw new ServiceException("不允许为普通用户分配超级管理员角色,请至少选择一个其他角色");
}
// 校验是否有权限访问这些角色(含数据权限控制)
if (roleMapper.selectRoleCount(roleList) != roleList.size()) {
throw new ServiceException("没有权限访问角色的数据");