diff --git a/src/main/java/com/rebuild/server/configuration/portals/FieldValueWrapper.java b/src/main/java/com/rebuild/server/configuration/portals/FieldValueWrapper.java index d0a65067e..b00e5b936 100644 --- a/src/main/java/com/rebuild/server/configuration/portals/FieldValueWrapper.java +++ b/src/main/java/com/rebuild/server/configuration/portals/FieldValueWrapper.java @@ -317,10 +317,11 @@ public class FieldValueWrapper { * 获取记录的 NAME/LABEL 字段值 * * @param id + * @param defaultValue * @return * @throws NoRecordFoundException If no record found */ - public static String getLabel(ID id) throws NoRecordFoundException { + public static String getLabel(ID id, String defaultValue) throws NoRecordFoundException { Entity entity = MetadataHelper.getEntity(id.getEntityCode()); Field nameField = MetadataHelper.getNameField(entity); @@ -331,11 +332,23 @@ public class FieldValueWrapper { Object nameLabel = instance.wrapFieldValue(nameValue[0], nameField, true); if (nameLabel == null || StringUtils.isBlank(nameLabel.toString())) { - return NO_LABEL_PREFIX + id.toLiteral().toUpperCase(); + if (defaultValue == null) { + defaultValue = NO_LABEL_PREFIX + id.toLiteral().toUpperCase(); + } + return defaultValue; } return nameLabel.toString(); } + /** + * @param id + * @return + * @throws NoRecordFoundException + */ + public static String getLabel(ID id) throws NoRecordFoundException { + return getLabel(id, null); + } + /** * @param id * @return @@ -354,7 +367,7 @@ public class FieldValueWrapper { * @param text * @return Returns `{ id:xxx, text:xxx, entity:xxx }` */ - public static JSON wrapMixValue(ID id, String text) { + public static JSONObject wrapMixValue(ID id, String text) { if (id != null && StringUtils.isBlank(text)) { text = id.getLabel(); } diff --git a/src/main/java/com/rebuild/server/helper/datalist/DataListWrapper.java b/src/main/java/com/rebuild/server/helper/datalist/DataListWrapper.java index 957311643..8e51ac8fc 100644 --- a/src/main/java/com/rebuild/server/helper/datalist/DataListWrapper.java +++ b/src/main/java/com/rebuild/server/helper/datalist/DataListWrapper.java @@ -20,6 +20,7 @@ package com.rebuild.server.helper.datalist; import cn.devezhao.persist4j.Entity; import cn.devezhao.persist4j.Field; +import cn.devezhao.persist4j.dialect.FieldType; import cn.devezhao.persist4j.engine.ID; import cn.devezhao.persist4j.query.compiler.SelectItem; import com.alibaba.fastjson.JSON; @@ -28,6 +29,7 @@ import com.rebuild.server.configuration.portals.FieldValueWrapper; import com.rebuild.server.metadata.MetadataHelper; import com.rebuild.server.metadata.entity.DisplayType; import com.rebuild.server.metadata.entity.EasyMeta; +import com.rebuild.server.service.bizz.UserHelper; import com.rebuild.utils.JSONUtils; import org.apache.commons.lang.StringUtils; @@ -70,6 +72,8 @@ public class DataListWrapper { } /** + * 设置权限过滤(针对引用字段) + * * @param user * @param joinFields */ @@ -98,26 +102,41 @@ public class DataListWrapper { data[rowIndex] = row; } - Object nameValue = StringUtils.EMPTY; + Object nameValue = null; for (int colIndex = 0; colIndex < selectFieldsLen; colIndex++) { if (!checkHasJoinFieldPrivileges(selectFields[colIndex], original)) { row[colIndex] = NO_READ_PRIVILEGES; continue; } - if (row[colIndex] == null) { + + final Object value = row[colIndex]; + if (value == null) { row[colIndex] = StringUtils.EMPTY; continue; } - Field field = selectFields[colIndex].getField(); - if (field.equals(nameFiled)) { - nameValue = row[colIndex]; + SelectItem fieldItem = selectFields[colIndex]; + Field field = fieldItem.getField(); + if (field.equals(nameFiled) && !fieldItem.getFieldPath().contains(".")) { + nameValue = value; if (nameValue == null) { nameValue = StringUtils.EMPTY; } } + // 如果最终没能取得名称字段,则补充 + if (field.getType() == FieldType.PRIMARY) { + if (nameValue == null) { + nameValue = FieldValueWrapper.getLabel((ID) value, StringUtils.EMPTY); + } else { + nameValue = FieldValueWrapper.instance.wrapFieldValue(nameValue, nameFiled, true); + if (nameValue == null) { + nameValue = StringUtils.EMPTY; + } + } + ((ID) value).setLabel(nameValue.toString()); + } - row[colIndex] = wrapFieldValue(row[colIndex], nameValue, field); + row[colIndex] = wrapFieldValue(value, field); } } @@ -127,16 +146,14 @@ public class DataListWrapper { } /** - * see FormsBuilder#wrapFieldValue(Record, EasyMeta) * @param value - * @param nameValue * @param field * @return */ - protected Object wrapFieldValue(Object value, Object nameValue, Field field) { + protected Object wrapFieldValue(Object value, Field field) { EasyMeta fieldEasy = EasyMeta.valueOf(field); if (fieldEasy.getDisplayType() == DisplayType.ID) { - return FieldValueWrapper.wrapMixValue((ID) value, (String) nameValue); + return FieldValueWrapper.wrapMixValue((ID) value, null); } else if (fieldEasy.getDisplayType() == DisplayType.CLASSIFICATION) { return FieldValueWrapper.instance.wrapFieldValue(value, fieldEasy, true); } else { @@ -152,10 +169,10 @@ public class DataListWrapper { * @return */ private boolean checkHasJoinFieldPrivileges(SelectItem field, Object[] original) { - if (this.queryJoinFields == null) { + if (this.queryJoinFields == null || UserHelper.isAdmin(user)) { return true; } - + String[] fieldPath = field.getFieldPath().split("\\."); if (fieldPath.length == 1) { return true; diff --git a/src/main/java/com/rebuild/web/feeds/FeedsListControll.java b/src/main/java/com/rebuild/web/feeds/FeedsListControll.java index 11ceec6a9..c98439317 100644 --- a/src/main/java/com/rebuild/web/feeds/FeedsListControll.java +++ b/src/main/java/com/rebuild/web/feeds/FeedsListControll.java @@ -146,12 +146,17 @@ public class FeedsListControll extends BasePageControll { item.put("type", o[8]); item.put("numComments", FeedsHelper.getNumOfComment((ID) o[0])); + // 相关记录 ID related = (ID) o[9]; if (related != null && MetadataHelper.containsEntity(related.getEntityCode())) { EasyMeta entity = EasyMeta.valueOf(related.getEntityCode()); - String recordLabel = FieldValueWrapper.getLabelNotry(related); - item.put("related", new Object[] { related, recordLabel, entity.getLabel(), entity.getIcon(), entity.getName() }); + String nameValue = FieldValueWrapper.getLabelNotry(related); + JSONObject mixValue = FieldValueWrapper.wrapMixValue(related, nameValue); + mixValue.put("icon", entity.getIcon()); + mixValue.put("entityLabel", entity.getLabel()); + item.put("related", mixValue); } + list.add(item); } writeSuccess(response, diff --git a/src/main/webapp/assets/js/feeds/feeds-list.jsx b/src/main/webapp/assets/js/feeds/feeds-list.jsx index 25b44af41..76525c630 100644 --- a/src/main/webapp/assets/js/feeds/feeds-list.jsx +++ b/src/main/webapp/assets/js/feeds/feeds-list.jsx @@ -377,8 +377,8 @@ function __renderRichContent(e) { dangerouslySetInnerHTML={{ __html: contentHtml }} /> {e.related &&
- {e.related[2]} - - {e.related[1]} + {e.related.entityLabel} - + {e.related.text}
} {(e.images || []).length > 0 &&