|
|
|
|
@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.datapermission.core.rule.dept;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.util.ReflectUtil;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.collection.SetUtils;
|
|
|
|
|
import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
|
|
|
|
|
import cn.iocoder.yudao.module.system.api.permission.dto.DeptDataPermissionRespDTO;
|
|
|
|
|
@ -19,6 +20,7 @@ import org.mockito.MockedStatic;
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
|
|
import static cn.iocoder.yudao.framework.datapermission.core.rule.dept.DeptDataPermissionRule.EXPRESSION_NULL;
|
|
|
|
|
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
|
|
|
|
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString;
|
|
|
|
|
@ -95,7 +97,7 @@ class DeptDataPermissionRuleTest extends BaseMockitoUnitTest {
|
|
|
|
|
securityFrameworkUtilsMock.when(SecurityFrameworkUtils::getLoginUser).thenReturn(loginUser);
|
|
|
|
|
// mock 方法(DeptDataPermissionRespDTO)
|
|
|
|
|
DeptDataPermissionRespDTO deptDataPermission = new DeptDataPermissionRespDTO().setAll(true);
|
|
|
|
|
when(permissionApi.getDeptDataPermission(same(1L))).thenReturn(deptDataPermission);
|
|
|
|
|
when(permissionApi.getDeptDataPermission(same(1L))).thenReturn(success(deptDataPermission));
|
|
|
|
|
|
|
|
|
|
// 调用
|
|
|
|
|
Expression expression = rule.getExpression(tableName, tableAlias);
|
|
|
|
|
@ -118,7 +120,7 @@ class DeptDataPermissionRuleTest extends BaseMockitoUnitTest {
|
|
|
|
|
securityFrameworkUtilsMock.when(SecurityFrameworkUtils::getLoginUser).thenReturn(loginUser);
|
|
|
|
|
// mock 方法(DeptDataPermissionRespDTO)
|
|
|
|
|
DeptDataPermissionRespDTO deptDataPermission = new DeptDataPermissionRespDTO();
|
|
|
|
|
when(permissionApi.getDeptDataPermission(same(1L))).thenReturn(deptDataPermission);
|
|
|
|
|
when(permissionApi.getDeptDataPermission(same(1L))).thenReturn(success(deptDataPermission));
|
|
|
|
|
|
|
|
|
|
// 调用
|
|
|
|
|
Expression expression = rule.getExpression(tableName, tableAlias);
|
|
|
|
|
@ -142,7 +144,7 @@ class DeptDataPermissionRuleTest extends BaseMockitoUnitTest {
|
|
|
|
|
// mock 方法(DeptDataPermissionRespDTO)
|
|
|
|
|
DeptDataPermissionRespDTO deptDataPermission = new DeptDataPermissionRespDTO()
|
|
|
|
|
.setDeptIds(SetUtils.asSet(10L, 20L)).setSelf(true);
|
|
|
|
|
when(permissionApi.getDeptDataPermission(same(1L))).thenReturn(deptDataPermission);
|
|
|
|
|
when(permissionApi.getDeptDataPermission(same(1L))).thenReturn(success(deptDataPermission));
|
|
|
|
|
|
|
|
|
|
// 调用
|
|
|
|
|
Expression expression = rule.getExpression(tableName, tableAlias);
|
|
|
|
|
@ -166,7 +168,7 @@ class DeptDataPermissionRuleTest extends BaseMockitoUnitTest {
|
|
|
|
|
// mock 方法(DeptDataPermissionRespDTO)
|
|
|
|
|
DeptDataPermissionRespDTO deptDataPermission = new DeptDataPermissionRespDTO()
|
|
|
|
|
.setSelf(true);
|
|
|
|
|
when(permissionApi.getDeptDataPermission(same(1L))).thenReturn(deptDataPermission);
|
|
|
|
|
when(permissionApi.getDeptDataPermission(same(1L))).thenReturn(success(deptDataPermission));
|
|
|
|
|
// 添加 user 字段配置
|
|
|
|
|
rule.addUserColumn("t_user", "id");
|
|
|
|
|
|
|
|
|
|
@ -192,7 +194,7 @@ class DeptDataPermissionRuleTest extends BaseMockitoUnitTest {
|
|
|
|
|
// mock 方法(DeptDataPermissionRespDTO)
|
|
|
|
|
DeptDataPermissionRespDTO deptDataPermission = new DeptDataPermissionRespDTO()
|
|
|
|
|
.setDeptIds(CollUtil.newLinkedHashSet(10L, 20L));
|
|
|
|
|
when(permissionApi.getDeptDataPermission(same(1L))).thenReturn(deptDataPermission);
|
|
|
|
|
when(permissionApi.getDeptDataPermission(same(1L))).thenReturn(success(deptDataPermission));
|
|
|
|
|
// 添加 dept 字段配置
|
|
|
|
|
rule.addDeptColumn("t_user", "dept_id");
|
|
|
|
|
|
|
|
|
|
@ -218,7 +220,7 @@ class DeptDataPermissionRuleTest extends BaseMockitoUnitTest {
|
|
|
|
|
// mock 方法(DeptDataPermissionRespDTO)
|
|
|
|
|
DeptDataPermissionRespDTO deptDataPermission = new DeptDataPermissionRespDTO()
|
|
|
|
|
.setDeptIds(CollUtil.newLinkedHashSet(10L, 20L)).setSelf(true);
|
|
|
|
|
when(permissionApi.getDeptDataPermission(same(1L))).thenReturn(deptDataPermission);
|
|
|
|
|
when(permissionApi.getDeptDataPermission(same(1L))).thenReturn(success(deptDataPermission));
|
|
|
|
|
// 添加 user 字段配置
|
|
|
|
|
rule.addUserColumn("t_user", "id");
|
|
|
|
|
// 添加 dept 字段配置
|
|
|
|
|
|