From 50fed7ada71ae2452ca10789ffe5648d715980a6 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Tue, 19 Sep 2023 18:39:51 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E9=A1=B9=E7=9B=AE=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0=E6=9D=83=E9=99=90=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/permission.json | 6 +++ .../controller/CleanupEnvironmentTests.java | 1 - .../EnvironmentControllerTests.java | 40 +++++-------------- .../src/test/resources/dml/init_project.sql | 2 +- .../system/service/CommonProjectService.java | 1 + .../system/service/UserInviteService.java | 2 +- .../test/resources/dml/init_org_project.sql | 2 +- .../src/test/resources/dml/init_project.sql | 2 +- 8 files changed, 21 insertions(+), 35 deletions(-) diff --git a/backend/services/project-management/src/main/resources/permission.json b/backend/services/project-management/src/main/resources/permission.json index d20cfcf241..24e547d0a1 100644 --- a/backend/services/project-management/src/main/resources/permission.json +++ b/backend/services/project-management/src/main/resources/permission.json @@ -13,6 +13,12 @@ }, { "id": "PROJECT:READ+UPDATE" + }, + { + "id": "PROJECT:READ+DELETE" + }, + { + "id": "PROJECT:READ+RECOVER" } ] }, diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/CleanupEnvironmentTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/CleanupEnvironmentTests.java index 7dbf3603d6..3866606d52 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/CleanupEnvironmentTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/CleanupEnvironmentTests.java @@ -28,7 +28,6 @@ public class CleanupEnvironmentTests { @Order(1) public void testCleanupResource() throws Exception { serviceInvoker.invokeServices("test"); - cleanupEnvironmentResourceService.deleteResources("test"); cleanupEnvironmentResourceService.cleanReportResources("test"); } diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentControllerTests.java index 388498bb37..a4e48bf064 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentControllerTests.java @@ -1,7 +1,6 @@ package io.metersphere.project.controller; - import io.metersphere.project.dto.environment.EnvironmentConfig; import io.metersphere.project.dto.environment.EnvironmentRequest; import io.metersphere.project.dto.environment.KeyValue; @@ -38,11 +37,10 @@ import io.metersphere.sdk.util.JSON; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.log.constants.OperationLogType; -import io.metersphere.system.request.PluginUpdateRequest; -import io.metersphere.system.service.JdbcDriverPluginService; import jakarta.annotation.Resource; import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.*; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpHeaders; @@ -97,8 +95,12 @@ public class EnvironmentControllerTests extends BaseTest { private EnvironmentMapper environmentMapper; @Resource private EnvironmentBlobMapper environmentBlobMapper; - @Resource - private JdbcDriverPluginService jdbcDriverPluginService; + @Value("${spring.datasource.url}") + private String dburl; + @Value("${spring.datasource.username}") + private String username; + @Value("${spring.datasource.password}") + private String password; public static T parseObjectFromMvcResult(MvcResult mvcResult, Class parseClass) { try { @@ -795,37 +797,15 @@ public class EnvironmentControllerTests extends BaseTest { public void testDataValidate() throws Exception { //测试mysql DataSource dataSource = new DataSource(); - dataSource.setDbUrl("jdbc:mysql://101.43.186.75:3307/metersphere?autoReconnect=false&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false"); - dataSource.setPassword("Password123@mysql"); - dataSource.setUsername("root"); + dataSource.setDbUrl(dburl); + dataSource.setPassword(password); + dataSource.setUsername(username); dataSource.setDriverId(StringUtils.join("system", "&", "com.mysql.cj.jdbc.Driver")); dataSource.setDriver("com.mysql.cj.jdbc.Driver"); this.requestPost(validate, dataSource, status().isOk()); //校验权限 requestPostPermissionsTest(Arrays.asList(PermissionConstants.PROJECT_ENVIRONMENT_READ, PermissionConstants.PROJECT_ENVIRONMENT_READ_ADD, PermissionConstants.PROJECT_ENVIRONMENT_READ_UPDATE), validate, dataSource); - - //测试oracle 需要上传驱动jar包 - // 校验数据库驱动上传成功 - PluginUpdateRequest request = new PluginUpdateRequest(); - request.setName("my-driver"); - request.setOrganizationIds(Arrays.asList(DEFAULT_ORGANIZATION_ID)); - File myDriver = new File( - this.getClass().getClassLoader().getResource("file/ojdbc11.jar") - .getPath() - ); - request.setGlobal(true); - request.setEnable(true); - this.requestMultipartWithOkAndReturn("/plugin/add", - getDefaultMultiPartParam(request, myDriver)); - Assertions.assertEquals(jdbcDriverPluginService.getJdbcDriverClass(DEFAULT_ORGANIZATION_ID), Arrays.asList("oracle.jdbc.OracleDriver", "com.mysql.cj.jdbc.Driver")); - dataSource = new DataSource(); - dataSource.setDbUrl("jdbc:oracle:thin:@123.56.8.132:1521/orclpdb1.localdomain"); - dataSource.setPassword("dataease"); - dataSource.setUsername("dataease"); - dataSource.setDriverId("oracle.jdbc.OracleDriver&oracle.jdbc.OracleDriver"); - dataSource.setDriver("oracle.jdbc.OracleDriver"); - this.requestPost(validate, dataSource, status().isOk()); } @Test diff --git a/backend/services/project-management/src/test/resources/dml/init_project.sql b/backend/services/project-management/src/test/resources/dml/init_project.sql index f36f8d21ef..f8867fa98a 100644 --- a/backend/services/project-management/src/test/resources/dml/init_project.sql +++ b/backend/services/project-management/src/test/resources/dml/init_project.sql @@ -13,7 +13,7 @@ VALUES ('delete', 'test2', 'deleted@metersphere.io', MD5('deleted@metersphere.io UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin',1); replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time, enable,module_setting) VALUES ('projectId', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1, '["apiTest","uiTest"]'); -replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time,enable) VALUES ('projectId1', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目1', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1); +replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time,enable) VALUES ('projectId1', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目1', '系统默认创建的项目', 'test', 'test', unix_timestamp() * 1000, unix_timestamp() * 1000,1); replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time,update_time,enable ) VALUES ('projectId2', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目2', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1); replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time,update_time,enable, module_setting) VALUES ('projectId3', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目3', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1,'["apiTest","uiTest"]'); replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time,update_time,enable, module_setting) VALUES ('projectId4', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目4', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1,'["apiTest","uiTest","loadTest"]'); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/CommonProjectService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/CommonProjectService.java index ca6f79f274..c2c9252f63 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/CommonProjectService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/CommonProjectService.java @@ -118,6 +118,7 @@ public class CommonProjectService { memberRequest.setUserIds(addProjectDTO.getUserIds()); } projectMapper.insertSelective(project); + serviceInvoker.invokeCreateServices(project.getId()); //添加项目管理员 创建的时候如果没有传管理员id 则默认创建者为管理员 this.addProjectAdmin(memberRequest, createUser, path, OperationLogType.ADD.name(), Translator.get("add"), module); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserInviteService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserInviteService.java index 21fee525e6..026cdb2da2 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserInviteService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserInviteService.java @@ -99,7 +99,7 @@ public class UserInviteService { " \n" + " \n" + " " + inviteUser + "\n" + - " " + Translator.get("user.email.invite_ms") + "MeterSphere\n" + + " " + Translator.get("user.email.invite_ms") + "\n" + " \n" + " \n" + " \n" + diff --git a/backend/services/system-setting/src/test/resources/dml/init_org_project.sql b/backend/services/system-setting/src/test/resources/dml/init_org_project.sql index cd2d74b71c..8ce7cd04a1 100644 --- a/backend/services/system-setting/src/test/resources/dml/init_org_project.sql +++ b/backend/services/system-setting/src/test/resources/dml/init_org_project.sql @@ -17,7 +17,7 @@ VALUES ('test', 'test', 'admin3@metersphere.io', MD5('admin2@metersphere.io'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin'); replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time, enable,module_setting) VALUES ('projectId', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1, '["apiTest","uiTest"]'); -replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time,enable) VALUES ('projectId1', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目1', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1); +replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time,enable) VALUES ('projectId1', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目1', '系统默认创建的项目', 'test', 'test', unix_timestamp() * 1000, unix_timestamp() * 1000,1); replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time,update_time,enable ) VALUES ('projectId2', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目2', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1); replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time,update_time,enable, module_setting) VALUES ('projectId3', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目3', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1,'["apiTest","uiTest"]'); replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time,update_time,enable, module_setting) VALUES ('projectId4', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目4', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1,'["apiTest","uiTest","loadTest"]'); diff --git a/backend/services/system-setting/src/test/resources/dml/init_project.sql b/backend/services/system-setting/src/test/resources/dml/init_project.sql index e198501357..677ad5f521 100644 --- a/backend/services/system-setting/src/test/resources/dml/init_project.sql +++ b/backend/services/system-setting/src/test/resources/dml/init_project.sql @@ -1,7 +1,7 @@ # 插入测试数据 replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time,module_setting) VALUES ('projectId', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000, '["apiTest","uiTest"]'); replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time, enable,module_setting) VALUES ('projectId', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1, '["apiTest","uiTest"]'); -replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time,enable) VALUES ('projectId1', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目1', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1); +replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time,enable) VALUES ('projectId1', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目1', '系统默认创建的项目', 'test', 'test', unix_timestamp() * 1000, unix_timestamp() * 1000,1); replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time,update_time,enable ) VALUES ('projectId2', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目2', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1); replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time,update_time,enable, module_setting) VALUES ('projectId3', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目3', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1,'["apiTest","uiTest"]'); replace INTO project (id, num, organization_id, name, description, create_user, update_user, create_time,update_time,enable, module_setting) VALUES ('projectId4', null, (SELECT id FROM organization WHERE name LIKE '默认组织'), '默认项目4', '系统默认创建的项目', 'admin', 'admin', unix_timestamp() * 1000, unix_timestamp() * 1000,1,'["apiTest","uiTest","loadTest"]');