diff --git a/backend/pom.xml b/backend/pom.xml index a86ca5c84c..a702be3bac 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -63,7 +63,10 @@ org.springframework.boot spring-boot-starter-jetty - + + org.springframework.boot + spring-boot-starter-mail + org.projectlombok lombok diff --git a/backend/src/main/java/io/metersphere/commons/constants/ParamConstants.java b/backend/src/main/java/io/metersphere/commons/constants/ParamConstants.java index 51fe6a765d..0a96536d40 100644 --- a/backend/src/main/java/io/metersphere/commons/constants/ParamConstants.java +++ b/backend/src/main/java/io/metersphere/commons/constants/ParamConstants.java @@ -28,7 +28,7 @@ public interface ParamConstants { } enum Classify implements ParamConstants { - + MAIL("meter"), REGISTRY("registry"); private String value; @@ -85,4 +85,29 @@ public interface ParamConstants { this.value = value; } } + public static enum MAIL { + HOST("meter.host", 1), + PORT("meter.port", 2), + ACCOUNT("meter.account", 3), + PASSWORD("meter.password", 4), + SSL("meter.ssl", 5), + TLS("meter.tls", 6), + ANON("meter.anon", 7); + + private String key; + private Integer value; + + private MAIL(String key, Integer value) { + this.key = key; + this.value = value; + } + + public String getKey() { + return this.key; + } + + public Integer getValue() { + return this.value; + } + } } diff --git a/backend/src/main/java/io/metersphere/controller/SystemParameterController.java b/backend/src/main/java/io/metersphere/controller/SystemParameterController.java new file mode 100644 index 0000000000..1d02d58302 --- /dev/null +++ b/backend/src/main/java/io/metersphere/controller/SystemParameterController.java @@ -0,0 +1,28 @@ +package io.metersphere.controller; + +import io.metersphere.base.domain.SystemParameter; +import io.metersphere.service.SystemParameterService; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; + +@RestController +@RequestMapping(value = "/system") +public class SystemParameterController { + @Resource + private SystemParameterService SystemParameterService; + @PostMapping("/edit/email") + public void editMail(@RequestBody List SystemParameter){ + SystemParameterService.editMail(SystemParameter); + } + @PostMapping("/testConnection") + public void testConnection(@RequestBody HashMap hashMap){ + SystemParameterService.testConnection(hashMap); + } + +} diff --git a/backend/src/main/java/io/metersphere/service/SystemParameterService.java b/backend/src/main/java/io/metersphere/service/SystemParameterService.java index 4e1f0e49c9..7b98a8a6dc 100644 --- a/backend/src/main/java/io/metersphere/service/SystemParameterService.java +++ b/backend/src/main/java/io/metersphere/service/SystemParameterService.java @@ -4,14 +4,22 @@ import io.metersphere.base.domain.SystemParameter; import io.metersphere.base.domain.SystemParameterExample; import io.metersphere.base.mapper.SystemParameterMapper; import io.metersphere.commons.constants.ParamConstants; +import io.metersphere.commons.utils.EncryptUtils; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; - +import java.util.HashMap; import java.util.List; +import java.util.Properties; + +import org.springframework.mail.javamail.JavaMailSenderImpl; + + import javax.annotation.Resource; + @Service public class SystemParameterService { @@ -31,4 +39,43 @@ public class SystemParameterService { } return result; } + public void editMail(List parameters){ + List paramList = this.getParamList(ParamConstants.Classify.MAIL.getValue()); + boolean empty = paramList.size() < 2; + parameters.forEach(parameter -> { + if (parameter.getParamKey().equals(ParamConstants.MAIL.PASSWORD.getKey())) { + String string = EncryptUtils.aesEncrypt(parameter.getParamValue()).toString(); + parameter.setParamValue(string); + } + if (empty) { + systemParameterMapper.insert(parameter); + } else { + systemParameterMapper.updateByPrimaryKey(parameter); + } + }); + } + public List getParamList(String type) { + SystemParameterExample example = new SystemParameterExample(); + example.createCriteria().andParamKeyLike(type + "%"); + return systemParameterMapper.selectByExample(example); + } + + public void testConnection(HashMap hashMap){ + JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); + javaMailSender.setDefaultEncoding("UTF-8"); + javaMailSender.setHost(hashMap.get(ParamConstants.MAIL.PORT.getKey())); + javaMailSender.setPort(Integer.valueOf(hashMap.get(ParamConstants.MAIL.PORT.getKey()))); + javaMailSender.setUsername(hashMap.get(ParamConstants.MAIL.ACCOUNT.getKey())); + javaMailSender.setPassword(hashMap.get(ParamConstants.MAIL.PASSWORD.getKey())); + Properties props = new Properties(); + props.put("mail.smtp.auth", "true"); + if (BooleanUtils.toBoolean(hashMap.get(ParamConstants.MAIL.SSL.getKey()))) { + props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); + } + if (BooleanUtils.toBoolean(hashMap.get(ParamConstants.MAIL.TLS.getKey()))) { + props.put("mail.smtp.starttls.enable", "true"); + } + javaMailSender.setJavaMailProperties(props); + + } } diff --git a/frontend/src/business/components/common/router/router.js b/frontend/src/business/components/common/router/router.js index 2be39981df..534e931745 100644 --- a/frontend/src/business/components/common/router/router.js +++ b/frontend/src/business/components/common/router/router.js @@ -10,6 +10,7 @@ import OrganizationMember from "../../settings/organization/OrganizationMember"; import Member from "../../settings/workspace/WorkspaceMember"; import TestCaseReportTemplate from "../../settings/workspace/TestCaseReportTemplate"; import TestResourcePool from "../../settings/system/TestResourcePool"; +import SystemParameterSetting from "../../settings/system/SystemParameterSetting"; import MsProject from "../../project/MsProject"; import OrganizationWorkspace from "../../settings/organization/OrganizationWorkspace"; import PersonSetting from "../../settings/personal/PersonSetting"; @@ -80,11 +81,16 @@ const router = new VueRouter({ path: 'testresourcepool', component: TestResourcePool }, + { + path: 'systemparametersetting', + component: SystemParameterSetting + }, { path: 'testcase/report/template', name: 'testCaseReportTemplate', component: TestCaseReportTemplate - } + }, + ] }, { diff --git a/frontend/src/business/components/performance/test/components/PerformanceAdvancedConfig.vue b/frontend/src/business/components/performance/test/components/PerformanceAdvancedConfig.vue index 9e8092d136..a23058e6a9 100644 --- a/frontend/src/business/components/performance/test/components/PerformanceAdvancedConfig.vue +++ b/frontend/src/business/components/performance/test/components/PerformanceAdvancedConfig.vue @@ -1,5 +1,6 @@