From 693f83ad6d2565c0da47d9b9ae0581304d210c9f Mon Sep 17 00:00:00 2001 From: taojinlong Date: Mon, 27 Nov 2023 12:30:27 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E5=8E=BB=E6=8E=89=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/dataset/DataSetTableService.java | 13 +++++++++++++ .../plugins/datasource/dm/provider/DmConfig.java | 5 ++--- .../dm/dm-frontend/src/views/dm.vue | 4 ---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/core/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/core/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index d5561c0148..3b6b890970 100644 --- a/core/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/core/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -1116,6 +1116,19 @@ public class DataSetTableService { } private String handlePlainSelect(PlainSelect plainSelect, Select statementSelect, String dsType) throws Exception { + + List selectItems = new ArrayList<>(); + plainSelect.getSelectItems().forEach(selectItem -> { + System.out.println(selectItem); + System.out.println(selectItem instanceof PlainSelect); + System.out.println(selectItem instanceof SubSelect); + + selectItems.add(selectItem); + }); + + plainSelect.addSelectItems(selectItems); + + FromItem fromItem = plainSelect.getFromItem(); if (fromItem instanceof SubSelect) { SelectBody selectBody = ((SubSelect) fromItem).getSelectBody(); diff --git a/extensions/dataease-extensions-datasource/dm/dm-backend/src/main/java/io/dataease/plugins/datasource/dm/provider/DmConfig.java b/extensions/dataease-extensions-datasource/dm/dm-backend/src/main/java/io/dataease/plugins/datasource/dm/provider/DmConfig.java index e1d07a3167..16f7eb1200 100644 --- a/extensions/dataease-extensions-datasource/dm/dm-backend/src/main/java/io/dataease/plugins/datasource/dm/provider/DmConfig.java +++ b/extensions/dataease-extensions-datasource/dm/dm-backend/src/main/java/io/dataease/plugins/datasource/dm/provider/DmConfig.java @@ -13,9 +13,8 @@ public class DmConfig extends JdbcConfiguration { public String getJdbc() { - return "jdbc:dm://HOST:PORT/DATABASE" + return "jdbc:dm://HOST:PORT" .replace("HOST", getHost().trim()) - .replace("PORT", getPort().toString()) - .replace("DATABASE", getDataBase().trim()); + .replace("PORT", getPort().toString()); } } diff --git a/extensions/dataease-extensions-datasource/dm/dm-frontend/src/views/dm.vue b/extensions/dataease-extensions-datasource/dm/dm-frontend/src/views/dm.vue index 35dc3badef..d8ef255152 100644 --- a/extensions/dataease-extensions-datasource/dm/dm-frontend/src/views/dm.vue +++ b/extensions/dataease-extensions-datasource/dm/dm-frontend/src/views/dm.vue @@ -20,10 +20,6 @@ - - - - From ad83d8074606b0edc74419b28737cf64778f33e9 Mon Sep 17 00:00:00 2001 From: taojinlong Date: Mon, 27 Nov 2023 16:27:31 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20[Bug]API=E6=95=B0=E6=8D=AE=E6=BA=90?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=E4=B8=8D=E5=90=AB=E6=9A=82?= =?UTF-8?q?=E6=97=B6=E4=B8=BA=E7=A9=BA=E7=9A=84=E5=AD=97=E6=AE=B5=20#6234?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../provider/datasource/ApiProvider.java | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/core/backend/src/main/java/io/dataease/provider/datasource/ApiProvider.java b/core/backend/src/main/java/io/dataease/provider/datasource/ApiProvider.java index b6695e6e4b..0b4adc7626 100644 --- a/core/backend/src/main/java/io/dataease/provider/datasource/ApiProvider.java +++ b/core/backend/src/main/java/io/dataease/provider/datasource/ApiProvider.java @@ -4,6 +4,7 @@ package io.dataease.provider.datasource; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.parser.Feature; import com.alibaba.fastjson.serializer.SerializerFeature; import com.google.common.reflect.TypeToken; import com.google.gson.Gson; @@ -40,7 +41,7 @@ public class ApiProvider extends Provider { @Override public List getData(DatasourceRequest datasourceRequest) throws Exception { ApiDefinition apiDefinition = checkApiDefinition(datasourceRequest); - String response = execHttpRequest(apiDefinition, apiDefinition.getApiQueryTimeout() == null || apiDefinition.getApiQueryTimeout()<=0 ? 30 : apiDefinition.getApiQueryTimeout()); + String response = execHttpRequest(apiDefinition, apiDefinition.getApiQueryTimeout() == null || apiDefinition.getApiQueryTimeout() <= 0 ? 30 : apiDefinition.getApiQueryTimeout()); return fetchResult(response, apiDefinition); } @@ -68,7 +69,7 @@ public class ApiProvider extends Provider { List dataList = new ArrayList<>(); List fieldList = new ArrayList<>(); ApiDefinition apiDefinition = checkApiDefinition(datasourceRequest); - String response = execHttpRequest(apiDefinition, apiDefinition.getApiQueryTimeout() == null || apiDefinition.getApiQueryTimeout()<=0 ? 30 : apiDefinition.getApiQueryTimeout()); + String response = execHttpRequest(apiDefinition, apiDefinition.getApiQueryTimeout() == null || apiDefinition.getApiQueryTimeout() <= 0 ? 30 : apiDefinition.getApiQueryTimeout()); fieldList = getTableFields(apiDefinition); result.put("fieldList", fieldList); @@ -141,13 +142,13 @@ public class ApiProvider extends Provider { switch (apiDefinition.getMethod()) { case "GET": - List params = new ArrayList<>(); + List params = new ArrayList<>(); for (Map argument : apiDefinition.getRequest().getArguments()) { - if(StringUtils.isNotEmpty(argument.get("name")) && StringUtils.isNotEmpty(argument.get("value"))){ + if (StringUtils.isNotEmpty(argument.get("name")) && StringUtils.isNotEmpty(argument.get("value"))) { params.add(argument.get("name") + "=" + URLEncoder.encode(argument.get("value"))); } } - if(CollectionUtils.isNotEmpty(params)){ + if (CollectionUtils.isNotEmpty(params)) { apiDefinition.setUrl(apiDefinition.getUrl() + "?" + StringUtils.join(params, "&")); } response = HttpClientUtil.get(apiDefinition.getUrl().trim(), httpClientConfig); @@ -167,7 +168,7 @@ public class ApiProvider extends Provider { if (StringUtils.equalsAny(type, "Form_Data", "WWW_FORM")) { if (apiDefinitionRequest.getBody().get("kvs") != null) { Map body = new HashMap<>(); - JSONObject bodyObj = JSONObject.parseObject(apiDefinitionRequest.getBody().toString()); + JSONObject bodyObj = JSONObject.parseObject(apiDefinitionRequest.getBody().toString(), Feature.IgnoreNotMatch); JSONArray kvsArr = bodyObj.getJSONArray("kvs"); for (int i = 0; i < kvsArr.size(); i++) { JSONObject kv = kvsArr.getJSONObject(i); @@ -267,9 +268,12 @@ public class ApiProvider extends Provider { handleStr(apiDefinition, o.toString(), fields, rootPath); } } else { - JSONObject jsonObject = JSONObject.parseObject(jsonStr); + JSONObject jsonObject = JSONObject.parseObject(jsonStr, Feature.IgnoreNotMatch); for (String s : jsonObject.keySet()) { String value = jsonObject.getString(s); + if (StringUtils.isNotEmpty(value) && value.startsWith("{")) { + value = JSONObject.toJSONString(jsonObject.getJSONObject(s), SerializerFeature.WriteMapNullValue); + } if (StringUtils.isNotEmpty(value) && value.startsWith("[")) { JSONObject o = new JSONObject(); try { @@ -283,7 +287,7 @@ public class ApiProvider extends Provider { } catch (Exception e) { JSONArray array = new JSONArray(); - array.add(StringUtils.isNotEmpty(jsonObject.getString(s)) ? jsonObject.getString(s) : ""); + array.add(StringUtils.isNotEmpty(value) ? value : ""); o.put("value", array); } o.put("jsonPath", rootPath + "." + String.format(path, s)); @@ -293,9 +297,9 @@ public class ApiProvider extends Provider { } } else if (StringUtils.isNotEmpty(value) && value.startsWith("{")) { try { - JSONObject.parseObject(jsonStr); + JSONObject.parseObject(value, Feature.IgnoreNotMatch); List children = new ArrayList<>(); - handleStr(apiDefinition, jsonObject.getString(s), children, rootPath + "." + String.format(path, s)); + handleStr(apiDefinition, value, children, rootPath + "." + String.format(path, s)); JSONObject o = new JSONObject(); o.put("children", children); o.put("childrenDataType", "OBJECT"); @@ -304,12 +308,13 @@ public class ApiProvider extends Provider { if (!hasItem(apiDefinition, fields, o)) { fields.add(o); } - }catch (Exception e){ + } catch (Exception e) { + e.printStackTrace(); JSONObject o = new JSONObject(); o.put("jsonPath", rootPath + "." + String.format(path, s)); setProperty(apiDefinition, o, s); JSONArray array = new JSONArray(); - array.add(StringUtils.isNotEmpty(jsonObject.getString(s)) ? jsonObject.getString(s) : ""); + array.add(StringUtils.isNotEmpty(value) ? value : ""); o.put("value", array); if (!hasItem(apiDefinition, fields, o)) { fields.add(o); @@ -320,7 +325,7 @@ public class ApiProvider extends Provider { o.put("jsonPath", rootPath + "." + String.format(path, s)); setProperty(apiDefinition, o, s); JSONArray array = new JSONArray(); - array.add(StringUtils.isNotEmpty(jsonObject.getString(s)) ? jsonObject.getString(s) : ""); + array.add(StringUtils.isNotEmpty(value) ? value : ""); o.put("value", array); if (!hasItem(apiDefinition, fields, o)) { fields.add(o); @@ -376,9 +381,9 @@ public class ApiProvider extends Provider { } for (Object itemChild : itemChildren) { boolean hasKey = false; - JSONObject itemChildObject = JSONObject.parseObject(itemChild.toString()); + JSONObject itemChildObject = JSONObject.parseObject(itemChild.toString(), Feature.IgnoreNotMatch); for (Object fieldChild : fieldChildren) { - JSONObject fieldChildObject = JSONObject.parseObject(fieldChild.toString()); + JSONObject fieldChildObject = JSONObject.parseObject(fieldChild.toString(), Feature.IgnoreNotMatch); if (itemChildObject.getString("jsonPath").equals(fieldChildObject.getString("jsonPath"))) { mergeField(fieldChildObject, itemChildObject); hasKey = true; @@ -403,10 +408,10 @@ public class ApiProvider extends Provider { JSONArray fieldArrayChildren = new JSONArray(); for (Object fieldChild : fieldChildren) { - JSONObject jsonObject = JSONObject.parseObject(fieldChild.toString()); + JSONObject jsonObject = JSONObject.parseObject(fieldChild.toString(), Feature.IgnoreNotMatch); JSONObject find = null; for (Object itemChild : itemChildren) { - JSONObject itemObject = JSONObject.parseObject(itemChild.toString()); + JSONObject itemObject = JSONObject.parseObject(itemChild.toString(), Feature.IgnoreNotMatch); if (jsonObject.getString("jsonPath").equals(itemObject.getString("jsonPath"))) { find = itemObject; } @@ -422,7 +427,7 @@ public class ApiProvider extends Provider { private List fetchResult(String result, ApiDefinition apiDefinition) { List dataList = new LinkedList<>(); - if(apiDefinition.isUseJsonPath()){ + if (apiDefinition.isUseJsonPath()) { List currentData = new ArrayList<>(); Object object = JsonPath.read(result, apiDefinition.getJsonPath()); if (object instanceof List) { @@ -439,7 +444,7 @@ public class ApiProvider extends Provider { } dataList.add(row); } - }else { + } else { if (StringUtils.isNotEmpty(apiDefinition.getDataPath()) && CollectionUtils.isEmpty(apiDefinition.getJsonFields())) { List currentData = new ArrayList<>(); Object object = JsonPath.read(result, apiDefinition.getDataPath()); From ba26066860395129fb885f2f37d81dfcd2fe9e2f Mon Sep 17 00:00:00 2001 From: taojinlong Date: Mon, 27 Nov 2023 17:11:29 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20[Bug]API=E6=95=B0[Bug]=E6=9D=83?= =?UTF-8?q?=E9=99=90=E9=97=AE=E9=A2=98=EF=BC=8Cdemo=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=97=A0=E6=9D=83=E9=99=90=E7=AE=A1=E7=90=86=E9=A9=B1=E5=8A=A8?= =?UTF-8?q?=EF=BC=8C=E4=BD=86=E5=8F=AF=E9=80=9A=E8=BF=87=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E5=AE=9E=E7=8E=B0=E9=A9=B1=E5=8A=A8=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20#6812?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datasource/DriverMgmController.java | 16 ++++++++++++++++ .../resources/i18n/messages_en_US.properties | 3 ++- .../resources/i18n/messages_zh_CN.properties | 1 + .../resources/i18n/messages_zh_TW.properties | 3 ++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/core/backend/src/main/java/io/dataease/controller/datasource/DriverMgmController.java b/core/backend/src/main/java/io/dataease/controller/datasource/DriverMgmController.java index 784091daf9..32edc4ae23 100644 --- a/core/backend/src/main/java/io/dataease/controller/datasource/DriverMgmController.java +++ b/core/backend/src/main/java/io/dataease/controller/datasource/DriverMgmController.java @@ -3,7 +3,10 @@ package io.dataease.controller.datasource; import io.dataease.auth.annotation.DeLog; import io.dataease.commons.constants.SysLogConstants; +import io.dataease.commons.exception.DEException; +import io.dataease.commons.utils.AuthUtils; import io.dataease.dto.DriverDTO; +import io.dataease.i18n.Translator; import io.dataease.plugins.common.base.domain.DeDriver; import io.dataease.plugins.common.base.domain.DeDriverDetails; import io.dataease.service.datasource.DriverService; @@ -31,6 +34,7 @@ public class DriverMgmController { @ApiOperation("驱动列表") @PostMapping("/list") public List listDeDriver() throws Exception{ + checkPermission(); return driverService.list(); } @@ -45,6 +49,7 @@ public class DriverMgmController { value = "id" ) public void delete(@RequestBody DeDriver deDriver) throws Exception{ + checkPermission(); driverService.delete(deDriver); } @@ -52,6 +57,7 @@ public class DriverMgmController { @ApiOperation("驱动列表") @GetMapping("/list/{type}") public List listDeDriver(@PathVariable String type) throws Exception{ + checkPermission(); return listDeDriver().stream().filter(driverDTO -> driverDTO.getType().equalsIgnoreCase(type)).collect(Collectors.toList()); } @@ -66,6 +72,7 @@ public class DriverMgmController { value = "id" ) public DeDriver save(@RequestBody DeDriver deDriver) throws Exception{ + checkPermission(); return driverService.save(deDriver); } @@ -79,6 +86,7 @@ public class DriverMgmController { value = "id" ) public DeDriver update(@RequestBody DeDriver deDriver) throws Exception{ + checkPermission(); return driverService.update(deDriver); } @@ -86,6 +94,7 @@ public class DriverMgmController { @ApiOperation("驱动文件列表") @GetMapping("/listDriverDetails/{id}") public List listDriverDetails(@PathVariable String id) throws Exception{ + checkPermission(); return driverService.listDriverDetails(id); } @@ -93,6 +102,7 @@ public class DriverMgmController { @ApiOperation("删除驱动文件") @PostMapping("/deleteDriverFile") public void deleteDriverFile(@RequestBody DeDriverDetails deDriverDetails) throws Exception{ + checkPermission(); driverService.deleteDriverFile(deDriverDetails.getId()); } @@ -104,9 +114,15 @@ public class DriverMgmController { @ApiImplicitParam(name = "id", value = "驱动D", required = true, dataType = "String") }) public DeDriverDetails excelUpload(@RequestParam("id") String id, @RequestParam("file") MultipartFile file) throws Exception { + checkPermission(); return driverService.saveJar(file, id); } + private void checkPermission()throws Exception{ + if(!AuthUtils.getUser().getIsAdmin()){ + DEException.throwException(Translator.get("I18N_NO_DRIVER_PERMISSION")); + } + } } diff --git a/core/backend/src/main/resources/i18n/messages_en_US.properties b/core/backend/src/main/resources/i18n/messages_en_US.properties index 0d5b36e213..f9389b00d7 100644 --- a/core/backend/src/main/resources/i18n/messages_en_US.properties +++ b/core/backend/src/main/resources/i18n/messages_en_US.properties @@ -275,4 +275,5 @@ I18N_PANEL_PDF_TEMPLATE_ONLY_PIC=Default template only screenshot \u8FB9\u68469=Border 9 \u8FB9\u684610=Border 10 I18n_name_cant_empty=Name can not be empty! -I18n_del_admin_tips=Forbidden to delete the admin account \ No newline at end of file +I18n_del_admin_tips=Forbidden to delete the admin account +I18N_NO_DRIVER_PERMISSION=Do not have permissions! \ No newline at end of file diff --git a/core/backend/src/main/resources/i18n/messages_zh_CN.properties b/core/backend/src/main/resources/i18n/messages_zh_CN.properties index a31e8745dc..ebfc1038d3 100644 --- a/core/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/core/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -266,4 +266,5 @@ I18N_PANEL_PDF_TEMPLATE_WITH_PARAMS=\u9ED8\u8BA4\u6A21\u677F(\u52A0\u4EEA\u8868\ I18N_PANEL_PDF_TEMPLATE_ONLY_PIC=\u9ED8\u8BA4\u6A21\u677F(\u53EA\u622A\u56FE) I18n_name_cant_empty=\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A\uFF01 I18n_del_admin_tips=\u7981\u6B62\u5220\u9664admin\u8D26\u53F7 +I18N_NO_DRIVER_PERMISSION=\u6ca1\u6709\u6743\u9650\uff01 diff --git a/core/backend/src/main/resources/i18n/messages_zh_TW.properties b/core/backend/src/main/resources/i18n/messages_zh_TW.properties index e5b121220c..75d68484ec 100644 --- a/core/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/core/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -271,4 +271,5 @@ I18N_PANEL_PDF_TEMPLATE_ONLY_PIC=\u9ED8\u8A8D\u6A21\u677F(\u53EA\u622A\u5716) \u8FB9\u68469=\u908A\u6846 9 \u8FB9\u684610=\u908A\u6846 10 I18n_name_cant_empty=\u540D\u7A31\u4E0D\u80FD\u70BA\u7A7A\uFF01 -I18n_del_admin_tips=\u7981\u6B62\u522A\u9664admin\u8CEC\u865F \ No newline at end of file +I18n_del_admin_tips=\u7981\u6B62\u522A\u9664admin\u8CEC\u865F +I18N_NO_DRIVER_PERMISSION=\u6c92\u6709\u8a31\u53ef\u6b0a\uff01 \ No newline at end of file