diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ParamConstants.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ParamConstants.java index 8bd716aafe..6b71825b85 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ParamConstants.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ParamConstants.java @@ -10,7 +10,8 @@ public interface ParamConstants { BASE("base"), LDAP("ldap"), REGISTRY("registry"), - CLEAN_CONFIG("cleanConfig.operation"); + CLEAN_CONFIG("cleanConfig.operation"), + UPLOAD_CONFIG("upload"); private String value; @@ -97,4 +98,18 @@ public interface ParamConstants { } } + enum UploadConfig implements ParamConstants { + UPLOAD_FILE_SIZE("upload.file.size"); + + private String value; + + private UploadConfig(String value) { + this.value = value; + } + + @Override + public String getValue() { + return value; + } + } } diff --git a/backend/framework/sdk/src/main/resources/i18n/commons.properties b/backend/framework/sdk/src/main/resources/i18n/commons.properties index 681103ce75..759cf6039f 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons.properties @@ -25,6 +25,7 @@ user_id_already_exists=用户id已存在 password_modification_failed=旧密码输入错误,请重新输入 cannot_delete_current_user=无法删除当前登录用户 connection_failed=连接失败 +upload_config_save_param_error=文件限制参数错误 connection_timeout=连接超时 user_already_exists=该用户已存在于当前成员列表中 cannot_remove_current=无法移除当前登录用户 diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties index e91388ff2f..022afc35b7 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_en_US.properties @@ -7,6 +7,7 @@ number=Number row=row error=error connection_failed=Connection failed +upload_config_save_param_error=File limit parameter error connection_timeout=Connection timeout delete_fail=Delete fail start_engine_fail=Start fail diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties index 2b299b190e..88f46fb9b3 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_zh_CN.properties @@ -25,6 +25,7 @@ user_id_already_exists=用户id已存在 password_modification_failed=旧密码输入错误,请重新输入 cannot_delete_current_user=无法删除当前登录用户 connection_failed=连接失败 +upload_config_save_param_error=文件限制参数错误 connection_timeout=连接超时 user_already_exists=该用户已存在于当前成员列表中 cannot_remove_current=无法移除当前登录用户 diff --git a/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties index 67142c50f2..9dfca47725 100644 --- a/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/commons_zh_TW.properties @@ -25,6 +25,7 @@ user_id_already_exists=用戶id已存在 password_modification_failed=舊密碼輸入錯誤,請重新輸入 cannot_delete_current_user=無法刪除當前登錄用戶 connection_failed=連接失敗 +upload_config_save_param_error=文件限制參數錯誤 connection_timeout=連接超時 user_already_exists=該用戶已存在於當前成員列表中 cannot_remove_current=無法移除當前登錄用戶 diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemParameterController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemParameterController.java index dbdbf514b1..b392b3f94d 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemParameterController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemParameterController.java @@ -100,4 +100,12 @@ public class SystemParameterController { public String getApiConcurrentConfig() { return systemParameterService.getApiConcurrentConfig(); } + + @PostMapping("/edit/upload-config") + @Operation(summary = "系统设置-系统-系统参数-基本设置-文件限制-保存") + @RequiresPermissions(PermissionConstants.SYSTEM_PARAMETER_SETTING_BASE_READ_UPDATE) + @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#systemParameter)", msClass = SystemParameterService.class) + public void editUploadConfigInfo(@Validated @RequestBody List systemParameter) { + systemParameterService.editUploadConfigInfo(systemParameter); + } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/BaseSystemConfigDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/BaseSystemConfigDTO.java index 665dcef965..2b9ffd0239 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/BaseSystemConfigDTO.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/BaseSystemConfigDTO.java @@ -1,14 +1,13 @@ package io.metersphere.system.dto.sdk; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; -@Getter -@Setter +@Data public class BaseSystemConfigDTO { private String url; private String concurrency; private String prometheusHost; private String runMode; private String docUrl; + private String fileMaxSize; } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/UploadInfoDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/UploadInfoDTO.java new file mode 100644 index 0000000000..f9f065eebd --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/sdk/UploadInfoDTO.java @@ -0,0 +1,9 @@ +package io.metersphere.system.dto.sdk; + +import lombok.Data; + +@Data +public class UploadInfoDTO { + + private String fileSize; +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemParameterService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemParameterService.java index cf60d58737..d4bea1d3c0 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemParameterService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemParameterService.java @@ -13,6 +13,7 @@ import io.metersphere.system.domain.SystemParameterExample; import io.metersphere.system.dto.sdk.BaseCleanConfigDTO; import io.metersphere.system.dto.sdk.BaseSystemConfigDTO; import io.metersphere.system.dto.sdk.EMailInfoDto; +import io.metersphere.system.dto.sdk.UploadInfoDTO; import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.dto.LogDTO; @@ -85,10 +86,13 @@ public class SystemParameterService { public BaseSystemConfigDTO getBaseInfo() { List paramList = this.getParamList(ParamConstants.Classify.BASE.getValue()); - return TransBaseToDto(paramList); + BaseSystemConfigDTO baseSystemConfig = transBaseToDto(paramList); + UploadInfoDTO uploadConfigInfo = getUploadConfigInfo(); + baseSystemConfig.setFileMaxSize(uploadConfigInfo.getFileSize()); + return baseSystemConfig; } - private BaseSystemConfigDTO TransBaseToDto(List paramList) { + private BaseSystemConfigDTO transBaseToDto(List paramList) { BaseSystemConfigDTO baseSystemConfigDTO = new BaseSystemConfigDTO(); if (!CollectionUtils.isEmpty(paramList)) { for (SystemParameter param : paramList) { @@ -161,6 +165,22 @@ public class SystemParameterService { }); } + public void editUploadConfigInfo(List parameters) { + SystemParameterExample example = new SystemParameterExample(); + SystemParameter uploadConfig = parameters.getFirst(); + if (StringUtils.equals(uploadConfig.getParamKey(), ParamConstants.UploadConfig.UPLOAD_FILE_SIZE.getValue())) { + example.createCriteria().andParamKeyEqualTo(uploadConfig.getParamKey()); + if (systemParameterMapper.countByExample(example) > 0) { + systemParameterMapper.updateByPrimaryKey(uploadConfig); + } else { + systemParameterMapper.insert(uploadConfig); + } + example.clear(); + } else { + throw new MSException(Translator.get("upload_config_save_param_error")); + } + } + public void testEmailConnection(HashMap hashMap) { JavaMailSenderImpl javaMailSender = null; try { @@ -312,6 +332,11 @@ public class SystemParameterService { return transCleanConfigToDto(paramList); } + public UploadInfoDTO getUploadConfigInfo() { + List paramList = this.getParamList(ParamConstants.Classify.UPLOAD_CONFIG.getValue()); + return transUploadConfigToDto(paramList); + } + private BaseCleanConfigDTO transCleanConfigToDto(List paramList) { BaseCleanConfigDTO configDTO = new BaseCleanConfigDTO(); if (CollectionUtils.isNotEmpty(paramList)) { @@ -326,6 +351,18 @@ public class SystemParameterService { return configDTO; } + private UploadInfoDTO transUploadConfigToDto(List paramList) { + UploadInfoDTO configDTO = new UploadInfoDTO(); + if (CollectionUtils.isNotEmpty(paramList)) { + paramList.forEach(param -> { + if (StringUtils.equals(param.getParamKey(), ParamConstants.UploadConfig.UPLOAD_FILE_SIZE.getValue())) { + configDTO.setFileSize(param.getParamValue()); + } + }); + } + return configDTO; + } + public String getApiConcurrentConfig() { List paramList = this.getParamList(ParamConstants.ApiConcurrentConfig.API_CONCURRENT_CONFIG.getValue()); if (CollectionUtils.isNotEmpty(paramList)) { diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemParameterControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemParameterControllerTests.java index ccedb920d5..3a5a1a9a14 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemParameterControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemParameterControllerTests.java @@ -43,6 +43,7 @@ public class SystemParameterControllerTests extends BaseTest { public static final String EMAIL_INFO_URL = "/system/parameter/get/email-info"; public static final String EMAIL_INFO_SAVE_URL = "/system/parameter/edit/email-info"; + public static final String UPLOAD_CONFIG_SAVE_URL = "/system/parameter/edit/upload-config"; public static final String EMAIL_INFO_TEST_CONNECT_URL = "/system/parameter/test/email"; @@ -172,6 +173,40 @@ public class SystemParameterControllerTests extends BaseTest { requestPostPermissionTest(PermissionConstants.SYSTEM_PARAMETER_SETTING_BASE_READ_UPDATE, BASE_INFO_SAVE_URL, systemParameters); } + @Test + @Order(6) + public void testEditUploadConfigInfo() throws Exception { + List systemParameters = new ArrayList<>() {{ + add(new SystemParameter() {{ + setParamKey("upload.file.size"); + setParamValue("10"); + setType("text"); + }}); + }}; + this.requestPost(UPLOAD_CONFIG_SAVE_URL, systemParameters); + requestPostPermissionTest(PermissionConstants.SYSTEM_PARAMETER_SETTING_BASE_READ_UPDATE, UPLOAD_CONFIG_SAVE_URL, systemParameters); + systemParameters = new ArrayList<>() {{ + add(new SystemParameter() {{ + setParamKey("upload.file.size"); + setParamValue("20"); + setType("text"); + }}); + }}; + this.requestPost(UPLOAD_CONFIG_SAVE_URL, systemParameters); + } + + @Test + @Order(7) + public void testEditUploadConfigInfoError() throws Exception { + List systemParameters = new ArrayList<>() {{ + add(new SystemParameter() {{ + setParamKey("upload.file"); + setParamValue("10"); + setType("text"); + }}); + }}; + this.requestPost(UPLOAD_CONFIG_SAVE_URL, systemParameters, status().is5xxServerError()); + } private MvcResult requestPost(String url, Object param) throws Exception { return mockMvc.perform(MockMvcRequestBuilders.post(url)