diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectController.java b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectController.java index ca31192bd5..713871d3ab 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectController.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectController.java @@ -5,10 +5,10 @@ import io.metersphere.project.request.ProjectSwitchRequest; import io.metersphere.project.service.ProjectLogService; import io.metersphere.project.service.ProjectService; import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.sdk.dto.OptionDTO; +import io.metersphere.sdk.dto.UserDTO; import io.metersphere.system.dto.ProjectDTO; import io.metersphere.system.dto.UpdateProjectRequest; -import io.metersphere.sdk.dto.UserDTO; -import io.metersphere.system.domain.TestResourcePool; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.utils.SessionUtils; @@ -61,7 +61,7 @@ public class ProjectController { @GetMapping("/pool-options/{type}/{projectId}") @Operation(summary = "项目管理-获取项目下的资源池") @RequiresPermissions(PermissionConstants.PROJECT_BASE_INFO_READ) - public List getPoolOptions(@PathVariable String type ,@PathVariable String projectId) { + public List getPoolOptions(@PathVariable String type , @PathVariable String projectId) { return projectService.getPoolOptions(projectId, type); } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectService.java index 896625b73c..50b625243b 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectService.java @@ -10,6 +10,7 @@ import io.metersphere.project.mapper.ProjectTestResourcePoolMapper; import io.metersphere.project.request.ProjectSwitchRequest; import io.metersphere.sdk.constants.InternalUserRole; import io.metersphere.sdk.constants.ModuleType; +import io.metersphere.sdk.dto.OptionDTO; import io.metersphere.sdk.dto.SessionUser; import io.metersphere.sdk.dto.UserDTO; import io.metersphere.sdk.exception.MSException; @@ -161,14 +162,14 @@ public class ProjectService { return poolIds; } - public List getPoolOptions(String projectId, String type) { - //判断项目是否关联了资源池 + public List getPoolOptions(String projectId, String type) { checkProjectNotExist(projectId); List poolIds = getPoolIds(projectId); TestResourcePoolExample example = new TestResourcePoolExample(); TestResourcePoolExample.Criteria criteria = example.createCriteria(); criteria.andIdIn(poolIds).andEnableEqualTo(true).andDeletedEqualTo(false); - return switch (type) { + List testResourcePools = new ArrayList<>(); + testResourcePools = switch (type) { case ModuleType.API_TEST-> { criteria.andApiTestEqualTo(true); yield testResourcePoolMapper.selectByExample(example); @@ -183,5 +184,8 @@ public class ProjectService { } default -> new ArrayList<>(); }; + return testResourcePools.stream().map(testResourcePool -> + new OptionDTO(testResourcePool.getId(), testResourcePool.getName()) + ).toList(); } } diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectControllerTests.java index fb1839c7f9..f77d2002a7 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectControllerTests.java @@ -8,13 +8,12 @@ import io.metersphere.project.request.ProjectSwitchRequest; import io.metersphere.sdk.constants.ModuleType; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.SessionConstants; -import io.metersphere.system.dto.ProjectDTO; -import io.metersphere.system.dto.UpdateProjectRequest; import io.metersphere.sdk.dto.UserDTO; import io.metersphere.sdk.util.JSON; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; -import io.metersphere.system.domain.TestResourcePool; +import io.metersphere.system.dto.ProjectDTO; +import io.metersphere.system.dto.UpdateProjectRequest; import io.metersphere.system.log.constants.OperationLogType; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; @@ -67,6 +66,15 @@ public class ProjectControllerTests extends BaseTest { return null; } + private void responseGet(String url, ResultMatcher resultMatcher) throws Exception { + mockMvc.perform(MockMvcRequestBuilders.get(url) + .header(SessionConstants.HEADER_TOKEN, sessionId) + .header(SessionConstants.CSRF_TOKEN, csrfToken) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(resultMatcher) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + } + private MvcResult responseGet(String url) throws Exception { return mockMvc.perform(MockMvcRequestBuilders.get(url) .header(SessionConstants.HEADER_TOKEN, sessionId) @@ -323,15 +331,14 @@ public class ProjectControllerTests extends BaseTest { mvcResult = this.responseGet(getPoolOptions + ModuleType.UI_TEST + "/" + DEFAULT_PROJECT_ID); mvcResult = this.responseGet(getPoolOptions + ModuleType.LOAD_TEST + "/" + DEFAULT_PROJECT_ID); mvcResult = this.responseGet(getPoolOptions + "test" + "/" + DEFAULT_PROJECT_ID); - List list = parseObjectFromMvcResult(mvcResult, List.class); - //断言为空的list - Assertions.assertEquals(0, list.size()); mvcResult = this.responseGet(getPoolOptions + ModuleType.API_TEST + "/" + "projectId"); mvcResult = this.responseGet(getPoolOptions + ModuleType.UI_TEST + "/" + "projectId"); mvcResult = this.responseGet(getPoolOptions + ModuleType.LOAD_TEST + "/" + "projectId"); - + //项目不存在 + this.responseGet(getPoolOptions + ModuleType.LOAD_TEST + "/" + "projectId20", status().is5xxServerError()); //权限校验 requestGetPermissionTest(PermissionConstants.PROJECT_BASE_INFO_READ, getPoolOptions + "api_test" + "/" + DEFAULT_PROJECT_ID); + } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationProjectController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationProjectController.java index 34e135949d..9ad1a259a4 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationProjectController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationProjectController.java @@ -4,22 +4,22 @@ package io.metersphere.system.controller; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.sdk.constants.PermissionConstants; -import io.metersphere.sdk.dto.*; -import io.metersphere.system.domain.TestResourcePool; +import io.metersphere.sdk.dto.OptionDTO; +import io.metersphere.sdk.dto.UserExtend; +import io.metersphere.sdk.util.PageUtils; +import io.metersphere.sdk.util.Pager; import io.metersphere.system.dto.AddProjectRequest; import io.metersphere.system.dto.ProjectDTO; import io.metersphere.system.dto.UpdateProjectRequest; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; -import io.metersphere.sdk.util.PageUtils; -import io.metersphere.sdk.util.Pager; -import io.metersphere.system.utils.SessionUtils; import io.metersphere.system.request.OrganizationProjectRequest; import io.metersphere.system.request.ProjectAddMemberBatchRequest; import io.metersphere.system.request.ProjectAddMemberRequest; import io.metersphere.system.request.ProjectMemberRequest; import io.metersphere.system.service.OrganizationProjectLogService; import io.metersphere.system.service.OrganizationProjectService; +import io.metersphere.system.utils.SessionUtils; import io.metersphere.validation.groups.Created; import io.metersphere.validation.groups.Updated; import io.swagger.v3.oas.annotations.Operation; @@ -161,7 +161,7 @@ public class OrganizationProjectController { @GetMapping("/pool-options/{organizationId}") @Operation(summary = "系统设置-组织-项目-获取资源池下拉选项") @RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ) - public List getProjectOptions(@PathVariable String organizationId) { + public List getProjectOptions(@PathVariable String organizationId) { return organizationProjectService.getTestResourcePoolOptions(organizationId); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemProjectController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemProjectController.java index d08c53f6d8..3d8c93917f 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemProjectController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemProjectController.java @@ -4,10 +4,10 @@ package io.metersphere.system.controller; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.sdk.constants.PermissionConstants; -import io.metersphere.sdk.dto.*; +import io.metersphere.sdk.dto.OptionDTO; +import io.metersphere.sdk.dto.UserExtend; import io.metersphere.sdk.util.PageUtils; import io.metersphere.sdk.util.Pager; -import io.metersphere.system.domain.TestResourcePool; import io.metersphere.system.domain.User; import io.metersphere.system.dto.AddProjectRequest; import io.metersphere.system.dto.ProjectDTO; @@ -156,7 +156,7 @@ public class SystemProjectController { @GetMapping("/pool-options/{organizationId}") @Operation(summary = "系统设置-系统-组织与项目-项目-获取资源池下拉选项") @RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ) - public List getProjectOptions(@PathVariable String organizationId) { + public List getProjectOptions(@PathVariable String organizationId) { return systemProjectService.getTestResourcePoolOptions(organizationId); } 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 78f56e7d31..f465018424 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 @@ -588,7 +588,7 @@ public class CommonProjectService { projectMapper.updateByPrimaryKeySelective(project); } - public List getTestResourcePoolOptions(String organizationId) { + public List getTestResourcePoolOptions(String organizationId) { //获取制定组织的资源池 和全部组织的资源池 List testResourcePools = new ArrayList<>(); TestResourcePoolOrganizationExample example = new TestResourcePoolOrganizationExample(); @@ -606,6 +606,8 @@ public class CommonProjectService { testResourcePools.addAll(testResourcePoolMapper.selectByExample(poolExample)); testResourcePools = testResourcePools.stream().filter(Objects::nonNull).distinct().collect(Collectors.toList()); - return testResourcePools; + return testResourcePools.stream().map(testResourcePool -> + new OptionDTO(testResourcePool.getId(), testResourcePool.getName()) + ).toList(); } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationProjectService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationProjectService.java index 96bb40fc3a..7412cf9ec3 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationProjectService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationProjectService.java @@ -1,17 +1,17 @@ package io.metersphere.system.service; -import io.metersphere.sdk.dto.*; +import io.metersphere.sdk.dto.OptionDTO; +import io.metersphere.sdk.dto.UserExtend; import io.metersphere.sdk.exception.MSException; -import io.metersphere.system.domain.TestResourcePool; +import io.metersphere.sdk.util.BeanUtils; +import io.metersphere.sdk.util.Translator; +import io.metersphere.system.domain.UserRoleRelation; +import io.metersphere.system.domain.UserRoleRelationExample; import io.metersphere.system.dto.AddProjectRequest; import io.metersphere.system.dto.ProjectDTO; import io.metersphere.system.dto.UpdateProjectRequest; import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogType; -import io.metersphere.sdk.util.BeanUtils; -import io.metersphere.sdk.util.Translator; -import io.metersphere.system.domain.UserRoleRelation; -import io.metersphere.system.domain.UserRoleRelationExample; import io.metersphere.system.mapper.ExtSystemProjectMapper; import io.metersphere.system.mapper.OrganizationMapper; import io.metersphere.system.mapper.UserRoleRelationMapper; @@ -130,7 +130,7 @@ public class OrganizationProjectService { } } - public List getTestResourcePoolOptions(String organizationId) { + public List getTestResourcePoolOptions(String organizationId) { return commonProjectService.getTestResourcePoolOptions(organizationId); } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemProjectService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemProjectService.java index a42b829522..a7ab6dec31 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemProjectService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/SystemProjectService.java @@ -1,15 +1,15 @@ package io.metersphere.system.service; import io.metersphere.project.domain.Project; -import io.metersphere.sdk.dto.*; -import io.metersphere.system.domain.TestResourcePool; +import io.metersphere.sdk.dto.OptionDTO; +import io.metersphere.sdk.dto.UserExtend; +import io.metersphere.sdk.util.Translator; import io.metersphere.system.dto.AddProjectRequest; +import io.metersphere.system.dto.OrganizationProjectOptionsDTO; import io.metersphere.system.dto.ProjectDTO; import io.metersphere.system.dto.UpdateProjectRequest; import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogType; -import io.metersphere.sdk.util.Translator; -import io.metersphere.system.dto.OrganizationProjectOptionsDTO; import io.metersphere.system.mapper.ExtSystemProjectMapper; import io.metersphere.system.request.ProjectAddMemberBatchRequest; import io.metersphere.system.request.ProjectMemberRequest; @@ -99,7 +99,7 @@ public class SystemProjectService { commonProjectService.disable(id, updateUser); } - public List getTestResourcePoolOptions(String organizationId) { + public List getTestResourcePoolOptions(String organizationId) { return commonProjectService.getTestResourcePoolOptions(organizationId); }