Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用户设置多角色时的数据权限 #687

Closed
qmmm61 opened this issue Oct 13, 2021 · 2 comments
Closed

用户设置多角色时的数据权限 #687

qmmm61 opened this issue Oct 13, 2021 · 2 comments

Comments

@qmmm61
Copy link

qmmm61 commented Oct 13, 2021

版本: v2.6
环境: 本地/线上
复现步骤:设置三个角色,角色1,角色2,角色3,数据权限分别是自定义用户权限,全部用户权限,本级用户权限,设置用户拥有这三个角色,用户获取的数据权限时逻辑不明确。
具体获取用户数据权限的实现在DataServiceImpl的getDeptIds方法

    @Override
    @Cacheable(key = "'user:' + #p0.id")
    public List<Integer> getDeptIds(UserDto user) {
        // 用于存储部门id
        Set<Integer> deptIds = new HashSet<>();
        // 查询用户角色
        List<RoleSmallDto> roleSet = roleService.findByUsersId(user.getId());
        // 获取对应的部门ID
        for (RoleSmallDto role : roleSet) {
            DataScopeEnum dataScopeEnum = DataScopeEnum.find(role.getDataScope());
            switch (Objects.requireNonNull(dataScopeEnum)) {
                case THIS_LEVEL:
                    deptIds.add(user.getDept().getId());
                    break;
                case CUSTOMIZE:
                    deptIds.addAll(getCustomize(deptIds, role));
                    break;
                default:
                    return new ArrayList<>(deptIds);
            }
        }
        return new ArrayList<>(deptIds);
    }

这里返回数据权限结果集会因为查询用户所有角色集roleSet后,从中取出角色的顺序不同而不同,比如循环roleSet时取出的顺序是角色1,角色2,角色3,那么第一次循环,deptIds包含角色1的数据权限自定义数据权限,第二次循环因为是角色2是全部数据权限,return则直接返回new ArrayList<>(deptIds)后跳出循环,deptIds中就只有角色1的数据权限,最终这个用户就只有角色1的数据权限,根据这个样例不能理解这里返回多角色数据权限的逻辑。
日志提供: 无

@nibinyang
Copy link

页面没有看到数据权限控制的地方

@elunez
Copy link
Owner

elunez commented Jul 4, 2023

#801

@elunez elunez closed this as completed Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants