!171 创建用户不分配角色的情况会存在空指针

Merge pull request !171 from caiti/master
This commit is contained in:
芋道源码 2022-05-17 14:01:30 +00:00 committed by Gitee
commit 9ee2fe5eb3
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 7 additions and 2 deletions

View File

@ -8,8 +8,8 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
import cn.iocoder.yudao.module.system.api.permission.dto.DeptDataPermissionRespDTO;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.system.api.permission.dto.DeptDataPermissionRespDTO;
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
@ -248,7 +248,12 @@ public class PermissionServiceImpl implements PermissionService {
@Override
public Set<Long> getUserRoleIdsFromCache(Long userId, Collection<Integer> roleStatuses) {
Set<Long> roleIds = new HashSet<>(userRoleCache.get(userId));
Set<Long> cacheRoleIds = userRoleCache.get(userId);
// 创建用户的时候没有分配角色会存在空指针异常
if (CollUtil.isEmpty(cacheRoleIds)) {
return Collections.emptySet();
}
Set<Long> roleIds = new HashSet<>(cacheRoleIds);
// 过滤角色状态
if (CollectionUtil.isNotEmpty(roleStatuses)) {
roleIds.removeIf(roleId -> {