Commit 24a88059fc0dc823abb9c08f39abe53244d45875
1 parent
ed3edaf7
fix:【framework】修复 easy-trans 因为数据权限,导致无法读取的问题
Showing
1 changed file
with
28 additions
and
6 deletions
yudao-framework/yudao-spring-boot-starter-biz-data-permission/src/main/java/cn/iocoder/yudao/framework/datapermission/core/rule/DataPermissionRuleFactoryImpl.java
| ... | ... | @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.ArrayUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; |
| 6 | 6 | import cn.iocoder.yudao.framework.datapermission.core.aop.DataPermissionContextHolder; |
| 7 | +import com.fhs.trans.service.impl.SimpleTransService; | |
| 7 | 8 | import lombok.RequiredArgsConstructor; |
| 8 | 9 | |
| 9 | 10 | import java.util.Collections; |
| ... | ... | @@ -31,32 +32,53 @@ public class DataPermissionRuleFactoryImpl implements DataPermissionRuleFactory |
| 31 | 32 | |
| 32 | 33 | @Override // mappedStatementId 参数,暂时没有用。以后,可以基于 mappedStatementId + DataPermission 进行缓存 |
| 33 | 34 | public List<DataPermissionRule> getDataPermissionRule(String mappedStatementId) { |
| 34 | - // 1. 无数据权限 | |
| 35 | + // 1.1 无数据权限 | |
| 35 | 36 | if (CollUtil.isEmpty(rules)) { |
| 36 | 37 | return Collections.emptyList(); |
| 37 | 38 | } |
| 38 | - // 2. 未配置,则默认开启 | |
| 39 | + // 1.2 未配置,则默认开启 | |
| 39 | 40 | DataPermission dataPermission = DataPermissionContextHolder.get(); |
| 40 | 41 | if (dataPermission == null) { |
| 41 | 42 | return rules; |
| 42 | 43 | } |
| 43 | - // 3. 已配置,但禁用 | |
| 44 | + // 1.3 已配置,但禁用 | |
| 44 | 45 | if (!dataPermission.enable()) { |
| 45 | 46 | return Collections.emptyList(); |
| 46 | 47 | } |
| 48 | + // 1.4 特殊:数据翻译时,强制忽略数据权限 https://github.com/YunaiV/ruoyi-vue-pro/issues/1007 | |
| 49 | + if (isTranslateCall()) { | |
| 50 | + return Collections.emptyList(); | |
| 51 | + } | |
| 47 | 52 | |
| 48 | - // 4. 已配置,只选择部分规则 | |
| 53 | + // 2.1 情况一:已配置,只选择部分规则 | |
| 49 | 54 | if (ArrayUtil.isNotEmpty(dataPermission.includeRules())) { |
| 50 | 55 | return rules.stream().filter(rule -> ArrayUtil.contains(dataPermission.includeRules(), rule.getClass())) |
| 51 | 56 | .collect(Collectors.toList()); // 一般规则不会太多,所以不采用 HashSet 查询 |
| 52 | 57 | } |
| 53 | - // 5. 已配置,只排除部分规则 | |
| 58 | + // 2.2 已配置,只排除部分规则 | |
| 54 | 59 | if (ArrayUtil.isNotEmpty(dataPermission.excludeRules())) { |
| 55 | 60 | return rules.stream().filter(rule -> !ArrayUtil.contains(dataPermission.excludeRules(), rule.getClass())) |
| 56 | 61 | .collect(Collectors.toList()); // 一般规则不会太多,所以不采用 HashSet 查询 |
| 57 | 62 | } |
| 58 | - // 6. 已配置,全部规则 | |
| 63 | + // 2.3 已配置,全部规则 | |
| 59 | 64 | return rules; |
| 60 | 65 | } |
| 61 | 66 | |
| 67 | + /** | |
| 68 | + * 判断是否为数据翻译 {@link com.fhs.core.trans.anno.Trans} 的调用 | |
| 69 | + * | |
| 70 | + * 目前暂时只有这个办法,已经和 easy-trans 做过沟通 | |
| 71 | + * | |
| 72 | + * @return 是否 | |
| 73 | + */ | |
| 74 | + private boolean isTranslateCall() { | |
| 75 | + StackTraceElement[] stack = Thread.currentThread().getStackTrace(); | |
| 76 | + for (StackTraceElement e : stack) { | |
| 77 | + if (SimpleTransService.class.getName().equals(e.getClassName())) { | |
| 78 | + return true; | |
| 79 | + } | |
| 80 | + } | |
| 81 | + return false; | |
| 82 | + } | |
| 83 | + | |
| 62 | 84 | } | ... | ... |