From bb3f8a9cdc59c9140042977f142f13b3e5a6cc8f Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Mon, 28 Oct 2024 13:33:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=BA=E6=99=AF=E5=AF=BC=E5=85=A5=E5=85=B3?= =?UTF-8?q?=E8=81=94=E7=94=A8=E4=BE=8B=E6=97=B6=E7=94=A8=E4=BE=8B=E7=9B=AE?= =?UTF-8?q?=E6=A0=87=E9=A1=B9=E7=9B=AE=E9=80=89=E6=8B=A9=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1048019 --user=宋天阳 【场景导入】-导入有引用关系的场景文件,切换组织后,在新项目中导入场景,没有在目标项目中新建关联资源 https://www.tapd.cn/55049933/s/1599124 --- .../service/ApiScenarioDataTransferService.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiScenarioDataTransferService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiScenarioDataTransferService.java index 0d3c93c7a9..b66808d0b0 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiScenarioDataTransferService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiScenarioDataTransferService.java @@ -834,7 +834,6 @@ public class ApiScenarioDataTransferService { List apiDefinitionDetails = entry.getValue(); // 如果没有权限,需要在当前项目进行校验 Project targetProject = projectMapper.selectByPrimaryKey(targetProjectId); - // 项目不存在或者项目和当前项目不在统一组织下,需要在当前项目进行校验。场景不能跨项目关联 if (targetProject == null || !StringUtils.equals(targetProject.getOrganizationId(), project.getOrganizationId())) { targetProjectId = projectId; @@ -850,12 +849,16 @@ public class ApiScenarioDataTransferService { for (Map.Entry> entry : parseResult.getRelatedApiTestCaseList().stream().collect(Collectors.groupingBy(ApiTestCaseDTO::getProjectId)).entrySet()) { String targetProjectId = entry.getKey(); List apiTestCaseList = entry.getValue(); + // 如果没有权限,需要在当前项目进行校验 - if (projectMapper.selectByPrimaryKey(targetProjectId) == null) { + Project targetProject = projectMapper.selectByPrimaryKey(targetProjectId); + // 项目不存在或者项目和当前项目不在统一组织下,需要在当前项目进行校验。场景不能跨项目关联 + if (targetProject == null || !StringUtils.equals(targetProject.getOrganizationId(), project.getOrganizationId())) { targetProjectId = projectId; - } else if (!permissionCheckService.userHasProjectPermission(operator, targetProjectId, PermissionConstants.PROJECT_API_DEFINITION_CASE_ADD)) { + } else if (!permissionCheckService.userHasProjectPermission(operator, targetProjectId, PermissionConstants.PROJECT_API_DEFINITION_ADD)) { targetProjectId = projectId; } + if (projectApiCaseMap.containsKey(targetProjectId)) { projectApiCaseMap.get(targetProjectId).addAll(apiTestCaseList); } else { @@ -866,9 +869,11 @@ public class ApiScenarioDataTransferService { String targetProjectId = entry.getKey(); List scenarioList = entry.getValue(); // 如果没有权限,需要在当前项目进行校验 - if (projectMapper.selectByPrimaryKey(targetProjectId) == null) { + Project targetProject = projectMapper.selectByPrimaryKey(targetProjectId); + // 项目不存在或者项目和当前项目不在统一组织下,需要在当前项目进行校验。场景不能跨项目关联 + if (targetProject == null || !StringUtils.equals(targetProject.getOrganizationId(), project.getOrganizationId())) { targetProjectId = projectId; - } else if (!permissionCheckService.userHasProjectPermission(operator, targetProjectId, PermissionConstants.PROJECT_API_DEFINITION_CASE_ADD)) { + } else if (!permissionCheckService.userHasProjectPermission(operator, targetProjectId, PermissionConstants.PROJECT_API_DEFINITION_ADD)) { targetProjectId = projectId; } if (projectScenarioMap.containsKey(targetProjectId)) {