refactor(auth): 移除平台角色 admin,改为纯 user/super 两级

变更内容:
1. sys_user.role 枚举从 enum('user','admin','super') 改为 enum('user','super')
2. RoleAspect 移除 case "admin" 分支,公司拥有者通过检查 org_company_member.role=owner 获得公司管理员权限
3. PermissionAspect 同样添加 owner 检查逻辑
4. UserMenuServiceImpl 移除 case "admin" 分支
5. AccountServiceImpl/SuperAccountServiceImpl 移除 getRoleName 中的 admin 分支
This commit is contained in:
小蟑螂
2026-03-29 22:01:10 +08:00
parent 8398d5db1e
commit be8f9cd92f
6 changed files with 22 additions and 20 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ CREATE TABLE `sys_user` (
`real_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '用户名称',
`avatar` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '头像路径(冗余字段)',
`avatar_image_id` bigint unsigned DEFAULT NULL COMMENT '头像图片ID',
`role` enum('user','admin','super') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT 'user' COMMENT '关联角色(user-普通账户 admin-公司管理员 super-超管账户)',
`role` enum('user','super') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT 'user' COMMENT '关联角色(user-普通账户 super-超管账户)',
`pwd_security_level` tinyint unsigned DEFAULT NULL COMMENT '密码安全级别(0-初始 1-很弱 2-弱 3-安全 4-很安全)',
`pwd_update_time` timestamp NULL DEFAULT NULL COMMENT '密码最后更新时间',
`last_login_ip` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '最后登录 ip',
@@ -60,12 +60,28 @@ public class PermissionAspect {
case "super":
hasPermission = annotation.allowSuper();
break;
case "admin":
hasPermission = annotation.allowCompany();
break;
case "user":
hasPermission = annotation.allowUser() &&
permissionCheckService.hasPermissionByPosition(positionId, annotation.value(), companyId);
// 普通用户检查公司成员角色
if (annotation.allowCompany()) {
try {
String memberRole = currentUserContext.getCurrentMemberRole();
if ("owner".equals(memberRole)) {
hasPermission = true;
log.debug("权限验证 - 用户是公司拥有者,视为公司管理员");
} else {
hasPermission = annotation.allowUser() &&
permissionCheckService.hasPermissionByPosition(positionId, annotation.value(), companyId);
}
} catch (BusinessException e) {
// 无法获取公司成员角色,降为普通用户权限
log.debug("无法获取公司成员角色: {}", e.getMessage());
hasPermission = annotation.allowUser() &&
permissionCheckService.hasPermissionByPosition(positionId, annotation.value(), companyId);
}
} else {
hasPermission = annotation.allowUser() &&
permissionCheckService.hasPermissionByPosition(positionId, annotation.value(), companyId);
}
break;
default:
throw new BusinessException("未知的用户角色: " + role);
@@ -55,9 +55,6 @@ public class RoleAspect {
case "super":
hasPermission = annotation.allowSuper();
break;
case "admin":
hasPermission = annotation.allowCompany();
break;
case "user":
// 普通用户检查公司成员角色,如果是 owner 则视为公司管理员
if (annotation.allowCompany()) {
@@ -428,7 +428,6 @@ public class AccountServiceImpl extends ServiceImpl<UserMapper, UserPO> implemen
if (role == null) return "未知";
return switch (role) {
case "super" -> "超级管理员";
case "admin" -> "公司管理员";
case "user" -> "普通用户";
default -> "未知";
};
@@ -445,7 +445,6 @@ public class SuperAccountServiceImpl extends ServiceImpl<UserMapper, UserPO> imp
if (role == null) return "未知";
return switch (role) {
case "super" -> "超级管理员";
case "admin" -> "公司管理员";
case "user" -> "普通用户";
default -> "未知";
};
@@ -79,15 +79,6 @@ public class UserMenuServiceImpl implements UserMenuService {
// 超级管理员获取所有系统菜单,不需要公司上下文
menus = menuService.getAllMenus();
break;
case "admin":
// 公司管理员获取公司所有菜单
Long companyId = currentUserContext.getCurrentCompanyId();
if (companyId == null) {
menus = List.of();
} else {
menus = companyMenuService.getCompanyMenusForRoute(companyId);
}
break;
case "user":
// 普通用户,根据公司成员角色判断
Long companyIdForUser = currentUserContext.getCurrentCompanyId();