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

This commit is contained in:
aotemiao
2026-03-06 08:57:39 +08:00
parent 593a94cbaf
commit 50c36dc803

View File

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