From ee9928ebca93be3c00f89adbd99b9e7c9bff2f3e Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Tue, 27 Feb 2024 16:23:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E4=B8=AA=E4=BA=BA=E4=B8=AD=E5=BF=83=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=8E=BB=E6=8E=89=E6=A0=A1=E9=AA=8C=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserLocalConfigController.java | 6 ---- .../service/UserLocalConfigService.java | 28 ++----------------- .../UserLocalConfigControllerTests.java | 19 ------------- 3 files changed, 2 insertions(+), 51 deletions(-) diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserLocalConfigController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserLocalConfigController.java index 84ce7bf1a3..78874444ec 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserLocalConfigController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserLocalConfigController.java @@ -31,12 +31,6 @@ public class UserLocalConfigController { return userLocalConfigService.add(request, SessionUtils.getUserId()); } - @GetMapping("/validate/{id}") - @Operation(summary = "系统设置-个人中心-我的设置-本地执行-验证是否通过") - public boolean validate(@PathVariable String id) { - return userLocalConfigService.validate(id); - } - @GetMapping("/get") @Operation(summary = "系统设置-个人中心-我的设置-本地执行-获取本地执行") public List get() { diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserLocalConfigService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserLocalConfigService.java index f83dd7c375..89f679a5a7 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserLocalConfigService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserLocalConfigService.java @@ -21,8 +21,6 @@ import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.net.HttpURLConnection; -import java.net.URI; import java.util.List; @Service @@ -73,24 +71,6 @@ public class UserLocalConfigService { } - public boolean validate(String id) { - UserLocalConfig userLocalConfig = checkResourceById(id); - HttpURLConnection connection = null; - try { - URI url = new URI(userLocalConfig.getUserUrl()); - connection = (HttpURLConnection) url.toURL().openConnection(); - connection.setConnectTimeout(3000); - return connection.getResponseCode() == HttpURLConnection.HTTP_OK; - } catch (Exception e) { - return false; - } finally { - if (connection != null) { - connection.disconnect(); - } - } - - } - public List get(String userId) { UserLocalConfigExample userLocalConfigExample = new UserLocalConfigExample(); userLocalConfigExample.createCriteria().andCreateUserEqualTo(userId); @@ -99,12 +79,8 @@ public class UserLocalConfigService { public void enable(String id) { UserLocalConfig userLocalConfig = checkResourceById(id); - if (validate(id)) { - userLocalConfig.setEnable(true); - userLocalConfigMapper.updateByPrimaryKeySelective(userLocalConfig); - } else { - throw new MSException(Translator.get("current_user_local_config_not_validate")); - } + userLocalConfig.setEnable(true); + userLocalConfigMapper.updateByPrimaryKeySelective(userLocalConfig); } public void disable(String id) { diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/UserLocalConfigControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/UserLocalConfigControllerTests.java index 9999202bc9..14677d6692 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/UserLocalConfigControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/UserLocalConfigControllerTests.java @@ -79,21 +79,6 @@ public class UserLocalConfigControllerTests extends BaseTest { } - @Test - @Order(2) - public void testValidate() throws Exception { - UserLocalConfigExample userLocalConfigExample = new UserLocalConfigExample(); - userLocalConfigExample.createCriteria().andCreateUserEqualTo("admin").andTypeEqualTo("API"); - UserLocalConfig userLocalConfig = userLocalConfigMapper.selectByExample(userLocalConfigExample).get(0); - requestGet(String.format(VALIDATE, userLocalConfig.getId())); - userLocalConfigExample.clear(); - userLocalConfigExample.createCriteria().andCreateUserEqualTo("admin").andTypeEqualTo("UI"); - userLocalConfig = userLocalConfigMapper.selectByExample(userLocalConfigExample).get(0); - requestGet(String.format(VALIDATE, userLocalConfig.getId())); - //不存在的 - requestGet(String.format(VALIDATE, UUID.randomUUID().toString()), status().is5xxServerError()); - } - @Test @Order(3) public void testUpdate() throws Exception { @@ -134,10 +119,6 @@ public class UserLocalConfigControllerTests extends BaseTest { checkLog(userLocalConfig.getId(), OperationLogType.UPDATE); //不存在的 requestGet(String.format(ENABLE, UUID.randomUUID().toString()), status().is5xxServerError()); - userLocalConfigExample.clear(); - userLocalConfigExample.createCriteria().andCreateUserEqualTo("admin").andTypeEqualTo("UI"); - userLocalConfig = userLocalConfigMapper.selectByExample(userLocalConfigExample).get(0); - requestGet(String.format(ENABLE, userLocalConfig.getId())).andExpect(status().is5xxServerError()); } @Test