Commit c61811a622a6829802e233e303bab091cc308f3a
1 parent
a49b1431
【修复】角色的数据范围为仅本人时,登陆后获取权限列表报错的问题
Showing
2 changed files
with
8 additions
and
3 deletions
yudao-framework/yudao-spring-boot-starter-biz-data-permission/src/main/java/cn/iocoder/yudao/framework/datapermission/core/dept/rule/DeptDataPermissionRule.java
| ... | ... | @@ -17,6 +17,7 @@ import lombok.extern.slf4j.Slf4j; |
| 17 | 17 | import net.sf.jsqlparser.expression.Alias; |
| 18 | 18 | import net.sf.jsqlparser.expression.Expression; |
| 19 | 19 | import net.sf.jsqlparser.expression.LongValue; |
| 20 | +import net.sf.jsqlparser.expression.NullValue; | |
| 20 | 21 | import net.sf.jsqlparser.expression.operators.conditional.OrExpression; |
| 21 | 22 | import net.sf.jsqlparser.expression.operators.relational.EqualsTo; |
| 22 | 23 | import net.sf.jsqlparser.expression.operators.relational.ExpressionList; |
| ... | ... | @@ -110,10 +111,12 @@ public class DeptDataPermissionRule implements DataPermissionRule { |
| 110 | 111 | Expression deptExpression = this.buildDeptExpression(tableName,tableAlias, deptDataPermission.getDeptIds()); |
| 111 | 112 | Expression userExpression = this.buildUserExpression(tableName, tableAlias, deptDataPermission.getSelf(), loginUser.getId()); |
| 112 | 113 | if (deptExpression == null && userExpression == null) { |
| 113 | - log.error("[getExpression][LoginUser({}) Table({}/{}) DeptDataPermission({}) 构建的条件为空]", | |
| 114 | + // TODO 芋艿:获得不到条件的时候,暂时不抛出异常,而是不返回数据 | |
| 115 | + log.warn("[getExpression][LoginUser({}) Table({}/{}) DeptDataPermission({}) 构建的条件为空]", | |
| 114 | 116 | JsonUtils.toJsonString(loginUser), tableName, tableAlias, JsonUtils.toJsonString(deptDataPermission)); |
| 115 | - throw new NullPointerException(String.format("LoginUser(%d) Table(%s/%s) 构建的条件为空", | |
| 116 | - loginUser.getId(), tableName, tableAlias.getName())); | |
| 117 | +// throw new NullPointerException(String.format("LoginUser(%d) Table(%s/%s) 构建的条件为空", | |
| 118 | +// loginUser.getId(), tableName, tableAlias.getName())); | |
| 119 | + return new NullValue(); | |
| 117 | 120 | } |
| 118 | 121 | if (deptExpression == null) { |
| 119 | 122 | return userExpression; | ... | ... |
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java
| ... | ... | @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.util.collection.SetUtils; |
| 7 | +import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; | |
| 7 | 8 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 8 | 9 | import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.*; |
| 9 | 10 | import cn.iocoder.yudao.module.system.convert.auth.AuthConvert; |
| ... | ... | @@ -63,6 +64,7 @@ public class AuthController { |
| 63 | 64 | |
| 64 | 65 | @GetMapping("/get-permission-info") |
| 65 | 66 | @ApiOperation("获取登录用户的权限信息") |
| 67 | + @DataPermission(enable = false) // 标记不使用数据权限,避免【SELF】权限范围报错 | |
| 66 | 68 | public CommonResult<AuthPermissionInfoRespVO> getPermissionInfo() { |
| 67 | 69 | // 获得用户信息 |
| 68 | 70 | AdminUserDO user = userService.getUser(getLoginUserId()); | ... | ... |