Merge branch 'master' into develop

This commit is contained in:
RB 2022-04-25 13:45:31 +08:00
commit 966636dcc4
2 changed files with 14 additions and 12 deletions

View file

@ -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) {

View file

@ -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<String, String> 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();
}