Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.rebuild</groupId>
<artifactId>rebuild</artifactId>
<version>3.9.2</version>
<version>3.9.3</version>
<name>rebuild</name>
<description>Building your business-systems freely!</description>
<url>https://getrebuild.com/</url>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/rebuild/core/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public class Application implements ApplicationListener<ApplicationStartedEvent>
/**
* Rebuild Version
*/
public static final String VER = "3.9.2";
public static final String VER = "3.9.3";
/**
* Rebuild Build [MAJOR]{1}[MINOR]{2}[PATCH]{2}[BUILD]{2}
*/
public static final int BUILD = 3090207;
public static final int BUILD = 3090308;

static {
// Driver for DB
Expand Down
25 changes: 15 additions & 10 deletions src/main/java/com/rebuild/core/privileges/UserHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static boolean isAdmin(ID userId) {
try {
return Application.getUserStore().getUser(userId).isAdmin();
} catch (NoMemberFoundException ex) {
log.error("No User found : " + userId);
log.error("No User found : {}", userId);
}
return false;
}
Expand Down Expand Up @@ -100,7 +100,7 @@ public static boolean isActive(ID bizzId) {
}

} catch (NoMemberFoundException ex) {
log.error("No bizz found : " + bizzId);
log.error("No bizz found : {}", bizzId);
}
return false;
}
Expand Down Expand Up @@ -460,16 +460,21 @@ public static Set<ID> getMembersOfRole(ID roleId) {
* @return
*/
public static boolean isSelf(ID user, ID otherUserOrAnyRecordId) {
ID createdBy = otherUserOrAnyRecordId;
if (otherUserOrAnyRecordId.getEntityCode() != EntityHelper.User) {
createdBy = getCreatedBy(otherUserOrAnyRecordId);
if (createdBy == null) return false;
}
try {
ID createdBy = otherUserOrAnyRecordId;
if (otherUserOrAnyRecordId.getEntityCode() != EntityHelper.User) {
createdBy = getCreatedBy(otherUserOrAnyRecordId);
if (createdBy == null) return false;
}

if (createdBy.equals(user)) return true;
if (createdBy.equals(user)) return true;

// 所有管理员被视为同一用户
return isAdmin(createdBy) && isAdmin(user);
// 所有管理员被视为同一用户
return isAdmin(createdBy) && isAdmin(user);
} catch (Exception ex) {
log.warn("Check isSelf error : {}, {}", user, otherUserOrAnyRecordId, ex);
return false;
}
}

private static ID getCreatedBy(ID anyRecordId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@
import com.rebuild.core.configuration.general.TransformManager;
import com.rebuild.core.metadata.EntityHelper;
import com.rebuild.core.metadata.MetadataHelper;
import com.rebuild.core.metadata.easymeta.EasyMetaFactory;
import com.rebuild.core.service.general.GeneralEntityService;
import com.rebuild.core.service.query.QueryHelper;
import com.rebuild.core.support.CommonsLog;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* @author Zixin
Expand Down Expand Up @@ -175,6 +179,12 @@ public JSON preview(ID sourceRecordId, ID specMainId, ID targetExistsRecordId) {
}

((JSONObject) formModel).put(GeneralEntityService.HAS_DETAILS, formModelDetailsMap);

// 明细导入
if (targetEntity.getDetailEntity() != null) {
((JSONObject) formModel).put("detailImports", buildDetailImports39(targetEntity));
}

return formModel;
}

Expand All @@ -190,21 +200,6 @@ private void mergeExistsAndTarget(Record transTargetRecord) {
transTargetRecord.removeValue(EntityHelper.OwningUser);
transTargetRecord.removeValue(EntityHelper.OwningDept);
}

// if (isPreview) {
// Record existsRecordSnap = Application.getQueryFactory().recordNoFilter(targetExistsRecordId);
// for (Field field : existsRecordSnap.getEntity().getFields()) {
// EasyField easyField = EasyMetaFactory.valueOf(field);
// if (MetadataHelper.isCommonsField(field) || easyField.getDisplayType() == DisplayType.SERIES) {
// if (field.getType() == FieldType.PRIMARY) continue;
//
// String fieldName = field.getName();
// if (EntityHelper.AutoId.equals(fieldName) || EntityHelper.QuickCode.equals(fieldName)) continue;
//
// transTargetRecord.setObjectValue(fieldName, existsRecordSnap.getObjectValue(fieldName));
// }
// }
// }
}

// 获取主记录(如果是明细的话)
Expand All @@ -215,4 +210,44 @@ private ID forceGetSpecMainId(ID targetRecordId) {
}
return null;
}

// ~~

/**
* @param mainEntity
* @return
*/
public static List<Object> buildDetailImports39(Entity mainEntity) {
List<Object> alist = new ArrayList<>();
for (Entity de : mainEntity.getDetialEntities()) {
List<ConfigBean> confImports = TransformManager.instance.getDetailImports(de.getName());
if (!confImports.isEmpty()) {
for (ConfigBean c : confImports) {
JSONObject trans = (JSONObject) EasyMetaFactory.valueOf(c.getString("source")).toJSON();
trans.put("transid", c.getID("id"));
trans.put("transName", c.getString("name"));

int ifAuto = ((JSONObject) c.getJSON("config")).getIntValue("importsMode2Auto");
if (ifAuto > 0) {
JSONArray importsFilter = ((JSONObject) c.getJSON("config")).getJSONArray("importsFilter");
Set<String> autoFields = new HashSet<>();
for (Object o : importsFilter) {
String name = ((JSONArray) o).getString(0);
autoFields.add(name.split("\\.")[1]);
}

if (!autoFields.isEmpty()) {
trans.put("auto", ifAuto);
trans.put("autoFields", autoFields);
}
}

trans.put("detailName", de.getName());
alist.add(trans);
}

}
}
return alist;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.rebuild.core.support.general;

import cn.devezhao.commons.CalendarUtils;
import cn.devezhao.persist4j.Entity;
import cn.devezhao.persist4j.Record;
import cn.devezhao.persist4j.engine.ID;
Expand Down Expand Up @@ -51,14 +52,14 @@ public class ContentWithFieldVars {
* @return
*/
public static String replaceWithRecord(String content, ID recordId) {
if (StringUtils.isBlank(content) || recordId == null) {
return content;
}
if (StringUtils.isBlank(content) || recordId == null) return content;

final Entity entity = MetadataHelper.getEntity(recordId.getEntityCode());
final String pkName = entity.getPrimaryField().getName();

Entity entity = MetadataHelper.getEntity(recordId.getEntityCode());
String pkName = entity.getPrimaryField().getName();
// 主键占位符
// 固定占位符
content = content.replace("{ID}", String.format("{%s}", pkName));
content = content.replace("{NOW}", CalendarUtils.getUTCDateFormat().format(CalendarUtils.now()));

Set<String> fieldVars = new HashSet<>();
for (String field : matchsVars(content)) {
Expand All @@ -84,12 +85,12 @@ public static String replaceWithRecord(String content, ID recordId) {
public static String replaceWithRecord(String content, Record record) {
if (StringUtils.isBlank(content) || record == null) return content;

// 主键占位符
content = content.replace("{ID}",
String.format("{%s}", record.getEntity().getPrimaryField().getName()));

final Entity entity = record.getEntity();

// 固定占位符
content = content.replace("{ID}", String.format("{%s}", entity.getPrimaryField().getName()));
content = content.replace("{NOW}", CalendarUtils.getUTCDateFormat().format(CalendarUtils.now()));

Map<String, String> fieldVars = new HashMap<>();
for (String field : matchsVars(content)) {
if (MetadataHelper.getLastJoinField(entity, field) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import java.io.File;
import java.io.IOException;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -194,7 +195,7 @@ public static String sendMail(String to, String subject, String content, File[]
String base64;
try {
byte[] bs = FileUtils.readFileToByteArray(a);
base64 = java.util.Base64.getEncoder().encodeToString(bs);
base64 = Base64.getEncoder().encodeToString(bs);
} catch (IOException ex) {
continue;
}
Expand Down Expand Up @@ -280,10 +281,22 @@ protected static Element getMailTemplate() {
if (Application.devMode()) MT_CACHE = null;
if (MT_CACHE != null) return MT_CACHE.clone();

String content = CommonsUtils.getStringOfRes("i18n/email.zh_CN.html");
Assert.notNull(content, "Cannot load template of email");
Document html = Jsoup.parse(content);
String content = null;
// v3.9.3 从数据目录
File file = RebuildConfiguration.getFileOfData("email.zh_CN.html");
if (file.exists()) {
try {
content = FileUtils.readFileToString(file, AppUtils.UTF8);
} catch (IOException ex) {
log.warn("Cannot read file of email template : {}", file, ex);
}
}
if (content == null) {
content = CommonsUtils.getStringOfRes("i18n/email.zh_CN.html");
}
Assert.notNull(content, "Cannot read email template");

Document html = Jsoup.parse(content);
MT_CACHE = html.body();
return MT_CACHE.clone();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public File backup(File backups) throws IOException {
log.warn("Cannot zip backup : {}", zip);
}

log.info("Backup succeeded : {} ({})", dest, FileUtils.byteCountToDisplaySize(dest.length()));
log.info("Backup database succeeded : {} ({})", dest, FileUtils.byteCountToDisplaySize(dest.length()));

// 恢复
// https://stackoverflow.com/questions/16735344/how-to-ignore-certain-mysql-tables-when-importing-a-database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
@Slf4j
public class DatafileBackup extends DatabaseBackup {

/**
* @return
* @throws IOException
*/
@Override
public File backup(File backups) throws IOException {
File rbdata = RebuildConfiguration.getFileOfData("");
Expand All @@ -41,7 +37,7 @@ public File backup(File backups) throws IOException {
return !("_backups".equals(name) || "_log".equals(name) || "temp".equals(name) || "rebuild.pid".equals(name));
});

log.info("Backup succeeded : {} ({})", destZip, FileUtils.byteCountToDisplaySize(destZip.length()));
log.info("Backup files succeeded : {} ({})", destZip, FileUtils.byteCountToDisplaySize(destZip.length()));

return destZip;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/rebuild/web/BaseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ protected String getParameterNotNull(HttpServletRequest request, String name) {
* @param name
* @return
*/
protected Integer getIntParameter(HttpServletRequest request, String name) {
return getIntParameter(request, name, null);
protected int getIntParameter(HttpServletRequest request, String name) {
return getIntParameter(request, name, 0);
}

/**
Expand All @@ -127,7 +127,7 @@ protected Integer getIntParameter(HttpServletRequest request, String name) {
* @param defaultValue
* @return
*/
protected Integer getIntParameter(HttpServletRequest request, String name, Integer defaultValue) {
protected int getIntParameter(HttpServletRequest request, String name, int defaultValue) {
String v = request.getParameter(name);
if (StringUtils.isBlank(v)) return defaultValue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.rebuild.core.support.DataDesensitized;
import com.rebuild.core.support.License;
import com.rebuild.core.support.RebuildConfiguration;
import com.rebuild.core.support.SysbaseHeartbeat;
import com.rebuild.core.support.i18n.Language;
import com.rebuild.core.support.integration.QiniuCloud;
import com.rebuild.core.support.integration.SMSender;
Expand Down Expand Up @@ -145,6 +146,7 @@ public RespBody postSystemsBackup(HttpServletRequest request) {
if (type == 1 || type == 3) {
try {
dbFile = "_backups/" + new DatabaseBackup().backup(backups).getName();
SysbaseHeartbeat.setItem(SysbaseHeartbeat.DatabaseBackupFail, null);
} catch (Exception e) {
dbFile = "ERR:" + e.getMessage();
log.error("Executing [DatabaseBackup] fails", e);
Expand All @@ -153,6 +155,7 @@ public RespBody postSystemsBackup(HttpServletRequest request) {
if (type == 2 || type == 3) {
try {
fileFile = "_backups/" + new DatafileBackup().backup(backups).getName();
SysbaseHeartbeat.setItem(SysbaseHeartbeat.DataFileBackupFail, null);
} catch (Exception e) {
fileFile = "ERR:" + e.getMessage();
log.error("Executing [DataFileBackup] fails", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public JSONAware saveDataItem(@IdParam(name = "item_id", required = false) ID it
item = EntityHelper.forUpdate(itemId, user);
} else if (dataId != null) {
ID parent = getIdParameter(request, "parent");
int level = getIntParameter(request, "level", 0);
int level = getIntParameter(request, "level");

item = EntityHelper.forNew(EntityHelper.ClassificationData, user);
item.setID("dataId", dataId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void generateAndRender(HttpServletRequest request, HttpServletResponse re
@GetMapping({"/commons/barcode/render-qr", "/commons/barcode/render"})
public void render(HttpServletRequest request, HttpServletResponse response) throws IOException {
String content = getParameter(request, "t", "UNSET");
int w = getIntParameter(request, "w", 0);
int w = getIntParameter(request, "w");

BufferedImage bi;
if (request.getRequestURI().endsWith("render-qr")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void download(HttpServletRequest request, HttpServletResponse response) t
public void readRawText(HttpServletRequest request, HttpServletResponse response) throws IOException {
String filepath = getParameterNotNull(request, "url");
final String charset = getParameter(request, "charset", AppUtils.UTF8);
final int cut = getIntParameter(request, "cut"); // MB
final Integer cut = getIntParameter(request, "cut"); // MB

if (CommonsUtils.isExternalUrl(filepath)) {
// v3.7 禁外部地址
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public JSON entities(HttpServletRequest request) {
public JSON fields(HttpServletRequest request) {
Entity entity = MetadataHelper.getEntity(getParameterNotNull(request, "entity"));
// 返回引用实体的字段层级
int appendRefFields = getIntParameter(request, "deep", 0);
int appendRefFields = getIntParameter(request, "deep");

// 根据不同的 referer 返回不同的字段列表
// 返回 ID 主键字段
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class AnnouncementController extends BaseController {
@GetMapping("/commons/announcements")
public RespBody announcementList(HttpServletRequest request) {
final ID user = AppUtils.getRequestUser(request);
int fromWhere = getIntParameter(request, "from", 0);
int fromWhere = getIntParameter(request, "from");

if (fromWhere == 0) {
// 1=动态页 2=首页 4=登录页
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public RespBody fetchFeeds(HttpServletRequest request) {
sqlWhere = "(1=1)";
}

int type = getIntParameter(request, "type", 0);
int type = getIntParameter(request, "type");
if (type == 1) {
sqlWhere += String.format(" and exists (select feedsId from FeedsMention where ^feedsId = feedsId and user = '%s')", user);
} else if (type == 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public ModelAndView pageList(@PathVariable String entity, HttpServletRequest req
final EasyEntity easyEntity = EasyMetaFactory.valueOf(listEntity);

int listMode = ObjectUtils.toInt(easyEntity.getExtraAttr(EasyEntityConfigProps.ADVLIST_MODE), 1);
int listModeForce = getIntParameter(request, "mode", 0);
int listModeForce = getIntParameter(request, "mode");
if (listModeForce >= 1 && listModeForce <= 3) listMode = listModeForce;
String listPage = listEntity.getMainEntity() != null ? "/general/detail-list" : "/general/record-list";
if (listMode == 2) listPage = "/general/record-list2"; // Mode2
Expand Down
Loading
Loading