From 39ab712324e02b212193075cc55cd28332f58b3f Mon Sep 17 00:00:00 2001
From: RB <42044143+getrebuild@users.noreply.github.com>
Date: Mon, 25 Apr 2022 13:44:17 +0800
Subject: [PATCH] Fix 2.8.4 (#459)
* fix: rule for GroupAggregation
* v2.8.4
---
pom.xml | 2 +-
.../java/com/rebuild/core/Application.java | 4 ++--
.../PrivilegesGuardInterceptor.java | 7 +++++--
.../trigger/impl/GroupAggregation.java | 19 +++++++++----------
4 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/pom.xml b/pom.xml
index 9b89aaba6..acf3beded 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
com.rebuild
rebuild
- 2.8.3
+ 2.8.4
rebuild
Building your business-systems freely!
diff --git a/src/main/java/com/rebuild/core/Application.java b/src/main/java/com/rebuild/core/Application.java
index 8009087c5..075fac2d3 100644
--- a/src/main/java/com/rebuild/core/Application.java
+++ b/src/main/java/com/rebuild/core/Application.java
@@ -64,11 +64,11 @@ public class Application implements ApplicationListener
/**
* Rebuild Version
*/
- public static final String VER = "2.8.3";
+ public static final String VER = "2.8.4";
/**
* Rebuild Build [MAJOR]{1}[MINOR]{2}[PATCH]{2}[BUILD]{2}
*/
- public static final int BUILD = 2080308;
+ public static final int BUILD = 2080408;
static {
// Driver for DB
diff --git a/src/main/java/com/rebuild/core/privileges/PrivilegesGuardInterceptor.java b/src/main/java/com/rebuild/core/privileges/PrivilegesGuardInterceptor.java
index ac94692f2..d90aa884d 100644
--- a/src/main/java/com/rebuild/core/privileges/PrivilegesGuardInterceptor.java
+++ b/src/main/java/com/rebuild/core/privileges/PrivilegesGuardInterceptor.java
@@ -26,6 +26,7 @@ import com.rebuild.core.support.i18n.Language;
import lombok.extern.slf4j.Slf4j;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
+import org.apache.commons.lang3.ObjectUtils;
import org.springframework.util.Assert;
import java.lang.reflect.Method;
@@ -131,9 +132,11 @@ public class PrivilegesGuardInterceptor implements MethodInterceptor, Guard {
}
// 无权限操作
- if (!allowed && PrivilegesGuardContextHolder.getSkipGuardOnce() != null) {
+ ID skipId;
+ if (!allowed && (skipId = PrivilegesGuardContextHolder.getSkipGuardOnce()) != null) {
allowed = true;
- log.warn("Allow no permission(" + action.getName() + ") passed once : " + recordId);
+ log.warn("Allow no permission({}) passed once : {}",
+ action.getName(), ObjectUtils.defaultIfNull(recordId, skipId));
}
if (!allowed) {
diff --git a/src/main/java/com/rebuild/core/service/trigger/impl/GroupAggregation.java b/src/main/java/com/rebuild/core/service/trigger/impl/GroupAggregation.java
index 21efcc9f5..870ea9a5c 100644
--- a/src/main/java/com/rebuild/core/service/trigger/impl/GroupAggregation.java
+++ b/src/main/java/com/rebuild/core/service/trigger/impl/GroupAggregation.java
@@ -20,6 +20,7 @@ import com.rebuild.core.metadata.easymeta.DisplayType;
import com.rebuild.core.metadata.easymeta.EasyField;
import com.rebuild.core.metadata.easymeta.EasyMetaFactory;
import com.rebuild.core.metadata.impl.EasyFieldConfigProps;
+import com.rebuild.core.privileges.PrivilegesGuardContextHolder;
import com.rebuild.core.privileges.UserService;
import com.rebuild.core.service.general.OperatingContext;
import com.rebuild.core.service.trigger.ActionContext;
@@ -35,8 +36,6 @@ import java.util.*;
/**
* 分组聚合
*
- * FIXME 目标实体记录自动新建时不会触发业务规则,因为使用了 CommonService 创建
- *
* @author devezhao
* @since 2021/6/28
*/
@@ -195,6 +194,7 @@ public class GroupAggregation extends FieldAggregation {
// 不必担心必填字段,必填只是前端约束
// 还可以通过设置字段默认值来完成必填字段的自动填写
+ // 0425 需要业务规则,譬如自动编号、默认值等
Record newTargetRecord = EntityHelper.forNew(targetEntity.getEntityCode(), UserService.SYSTEM_USER);
for (Map.Entry e : groupFieldsMapping.entrySet()) {
@@ -207,14 +207,13 @@ public class GroupAggregation extends FieldAggregation {
}
}
-// // 若无权限可能抛出异常(无权新建)
-// if (allowNoPermissionUpdate) {
-// PrivilegesGuardContextHolder.setSkipGuard(PrivilegesGuardContextHolder.FOR_NEW_RECORD);
-// }
-// newTargetRecord = Application.getEntityService(targetEntity.getEntityCode()).create(newTargetRecord);
-
- // FIXME 忽略业务规则新建
- newTargetRecord = Application.getCommonsService().create(newTargetRecord, false);
+ // 强制新建
+ PrivilegesGuardContextHolder.setSkipGuard(EntityHelper.UNSAVED_ID);
+ try {
+ Application.getEntityService(targetEntity.getEntityCode()).create(newTargetRecord);
+ } finally {
+ PrivilegesGuardContextHolder.getSkipGuardOnce();
+ }
targetRecordId = newTargetRecord.getPrimary();
}