Commit 30fbfb61432e254305d447802cc5e85d9c63c861

Authored by YunaiV
1 parent abe6828d

新建的用户未分配角色时,操作自己信息回报错的问题

yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java
@@ -458,13 +458,16 @@ public class PermissionServiceImpl implements PermissionService { @@ -458,13 +458,16 @@ public class PermissionServiceImpl implements PermissionService {
458 @DataPermission(enable = false) // 关闭数据权限,不然就会出现递归获取数据权限的问题 458 @DataPermission(enable = false) // 关闭数据权限,不然就会出现递归获取数据权限的问题
459 @TenantIgnore // 忽略多租户的自动过滤。如果不忽略,会导致添加租户时,因为切换租户,导致获取不到 User。即使忽略,本身该方法不存在跨租户的操作,不会存在问题。 459 @TenantIgnore // 忽略多租户的自动过滤。如果不忽略,会导致添加租户时,因为切换租户,导致获取不到 User。即使忽略,本身该方法不存在跨租户的操作,不会存在问题。
460 public DeptDataPermissionRespDTO getDeptDataPermission(Long userId) { 460 public DeptDataPermissionRespDTO getDeptDataPermission(Long userId) {
461 - DeptDataPermissionRespDTO result = new DeptDataPermissionRespDTO();  
462 // 获得用户的角色 461 // 获得用户的角色
463 Set<Long> roleIds = getUserRoleIdsFromCache(userId, singleton(CommonStatusEnum.ENABLE.getStatus())); 462 Set<Long> roleIds = getUserRoleIdsFromCache(userId, singleton(CommonStatusEnum.ENABLE.getStatus()));
  463 + // 如果角色为空,则只能查看自己
  464 + DeptDataPermissionRespDTO result = new DeptDataPermissionRespDTO();
464 if (CollUtil.isEmpty(roleIds)) { 465 if (CollUtil.isEmpty(roleIds)) {
  466 + result.setSelf(true);
465 return result; 467 return result;
466 } 468 }
467 List<RoleDO> roles = roleService.getRolesFromCache(roleIds); 469 List<RoleDO> roles = roleService.getRolesFromCache(roleIds);
  470 +
468 // 获得用户的部门编号的缓存,通过 Guava 的 Suppliers 惰性求值,即有且仅有第一次发起 DB 的查询 471 // 获得用户的部门编号的缓存,通过 Guava 的 Suppliers 惰性求值,即有且仅有第一次发起 DB 的查询
469 Supplier<Long> userDeptIdCache = Suppliers.memoize(() -> userService.getUser(userId).getDeptId()); 472 Supplier<Long> userDeptIdCache = Suppliers.memoize(() -> userService.getUser(userId).getDeptId());
470 // 遍历每个角色,计算 473 // 遍历每个角色,计算