feat(系统设置): 系统参数补充文件上传大小限制

This commit is contained in:
song-cc-rock 2024-09-03 17:30:55 +08:00 committed by Craftsman
parent 2836631b29
commit f44307ff31
10 changed files with 114 additions and 7 deletions

View File

@ -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;
}
}
}

View File

@ -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=无法移除当前登录用户

View File

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

View File

@ -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=无法移除当前登录用户

View File

@ -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=無法移除當前登錄用戶

View File

@ -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> systemParameter) {
systemParameterService.editUploadConfigInfo(systemParameter);
}
}

View File

@ -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;
}

View File

@ -0,0 +1,9 @@
package io.metersphere.system.dto.sdk;
import lombok.Data;
@Data
public class UploadInfoDTO {
private String fileSize;
}

View File

@ -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<SystemParameter> 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<SystemParameter> paramList) {
private BaseSystemConfigDTO transBaseToDto(List<SystemParameter> paramList) {
BaseSystemConfigDTO baseSystemConfigDTO = new BaseSystemConfigDTO();
if (!CollectionUtils.isEmpty(paramList)) {
for (SystemParameter param : paramList) {
@ -161,6 +165,22 @@ public class SystemParameterService {
});
}
public void editUploadConfigInfo(List<SystemParameter> 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<String, String> hashMap) {
JavaMailSenderImpl javaMailSender = null;
try {
@ -312,6 +332,11 @@ public class SystemParameterService {
return transCleanConfigToDto(paramList);
}
public UploadInfoDTO getUploadConfigInfo() {
List<SystemParameter> paramList = this.getParamList(ParamConstants.Classify.UPLOAD_CONFIG.getValue());
return transUploadConfigToDto(paramList);
}
private BaseCleanConfigDTO transCleanConfigToDto(List<SystemParameter> paramList) {
BaseCleanConfigDTO configDTO = new BaseCleanConfigDTO();
if (CollectionUtils.isNotEmpty(paramList)) {
@ -326,6 +351,18 @@ public class SystemParameterService {
return configDTO;
}
private UploadInfoDTO transUploadConfigToDto(List<SystemParameter> 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<SystemParameter> paramList = this.getParamList(ParamConstants.ApiConcurrentConfig.API_CONCURRENT_CONFIG.getValue());
if (CollectionUtils.isNotEmpty(paramList)) {

View File

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