From 3d78d116ad531595f5d1314c67a1b316845a1287 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Thu, 1 Feb 2024 17:38:15 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E9=A1=B9=E7=9B=AE=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=8A=82=E7=82=B9=E7=A7=BB=E5=8A=A8=E6=97=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E5=90=8D=E5=9C=A8=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E7=9B=AE=E5=BD=95=E4=B8=8B=E4=B8=8D=E8=83=BD=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E7=9A=84=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1035097 --user=宋天阳 【文件管理】-拖拽移动模块到有重名的模块中,提示信息不友好 https://www.tapd.cn/55049933/s/1458560 --- .../project/service/FileModuleService.java | 6 ++- .../FileManagementControllerTests.java | 45 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileModuleService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileModuleService.java index 517c9040b6..0af403f359 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileModuleService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileModuleService.java @@ -186,8 +186,12 @@ public class FileModuleService extends ModuleTreeService implements CleanupProje FileModuleExample example = new FileModuleExample(); example.createCriteria().andParentIdEqualTo(nodeSortDTO.getParent().getId()).andIdEqualTo(request.getDragNodeId()); - //节点换到了别的节点下,要先更新parent节点再计算sort + //节点换到了别的节点下,要先更新parent节点再计算sort (同步进行名称的校验) if (fileModuleMapper.countByExample(example) == 0) { + FileModule moveModule = fileModuleMapper.selectByPrimaryKey(request.getDragNodeId()); + moveModule.setParentId(nodeSortDTO.getParent().getId()); + this.checkDataValidity(moveModule); + FileModule fileModule = new FileModule(); fileModule.setId(request.getDragNodeId()); fileModule.setParentId(nodeSortDTO.getParent().getId()); diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java index 81b470ac8a..4e5ea79f00 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java @@ -23,6 +23,7 @@ import io.metersphere.sdk.file.FileRequest; import io.metersphere.sdk.util.FileAssociationSourceUtil; import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.TempFileUtils; +import io.metersphere.sdk.util.Translator; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.dto.AddProjectRequest; @@ -45,6 +46,7 @@ import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.SqlConfig; import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -64,6 +66,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. public class FileManagementControllerTests extends BaseTest { private static Project project; + private static BaseTreeNode A1B1C1_CHILD_NODE; + private static List preliminaryTreeNodes = new ArrayList<>(); private static final Map FILE_ID_PATH = new LinkedHashMap<>(); @@ -293,6 +297,30 @@ public class FileManagementControllerTests extends BaseTest { } } Assertions.assertNotNull(a1b1c1Node); + + //子节点a1-b1下继续创建节点a1-b1-c1 + request = new FileModuleCreateRequest(); + request.setProjectId(project.getId()); + request.setName("a1-b1-c1"); + request.setParentId(a1b1c1Node.getId()); + this.requestPostWithOkAndReturn(FileManagementRequestUtils.URL_MODULE_ADD, request); + treeNodes = this.getFileModuleTreeNode(); + BaseTreeNode a1b1c1ChildNode = null; + for (BaseTreeNode baseTreeNode : treeNodes) { + if (StringUtils.equals(baseTreeNode.getName(), "a1") && CollectionUtils.isNotEmpty(baseTreeNode.getChildren())) { + for (BaseTreeNode secondNode : baseTreeNode.getChildren()) { + if (StringUtils.equals(secondNode.getName(), "a1-b1") && CollectionUtils.isNotEmpty(secondNode.getChildren())) { + for (BaseTreeNode thirdNode : secondNode.getChildren()) { + if (StringUtils.equals(thirdNode.getName(), "a1-b1-c1") && CollectionUtils.isNotEmpty(thirdNode.getChildren())) { + a1b1c1ChildNode = thirdNode.getChildren().getFirst(); + } + } + } + } + } + } + Assertions.assertNotNull(a1b1c1ChildNode); + A1B1C1_CHILD_NODE = a1b1c1ChildNode; preliminaryTreeNodes = treeNodes; LOG_CHECK_LIST.add( @@ -1935,6 +1963,8 @@ public class FileManagementControllerTests extends BaseTest { | ·a1-b1 + | | | | | ·a1-b1-c1 + | | | + | | ·a1-b1-c1 | | | *a1-a1 +(创建的时候是a1,通过修改改为a1-a1) | | @@ -1959,6 +1989,19 @@ public class FileManagementControllerTests extends BaseTest { this.requestPostWithOk(FileManagementRequestUtils.URL_MODULE_MOVE, request); this.checkModulePos(a3Node.getId(), a1Node.getId(), null, false); } + + //测试a1b1c1(child)节点无法移动到a1b1c1同级别 + { + request.setDragNodeId(A1B1C1_CHILD_NODE.getId()); + request.setDropNodeId(a1b1Node.getId()); + request.setDropPosition(0); + ResultActions resultActions = this.requestPost(FileManagementRequestUtils.URL_MODULE_MOVE, request); + resultActions.andExpect(status().is5xxServerError()); + MvcResult mvcResult = resultActions.andReturn(); + ResultHolder resultHolder = JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class); + Assertions.assertEquals(resultHolder.getMessage(), Translator.get("node.name.repeat")); + } + //父节点内移动-移动到末位 在上面的基础上,a1挪到a2上面 { request = new NodeMoveRequest(); @@ -2389,6 +2432,8 @@ public class FileManagementControllerTests extends BaseTest { | ·a1-b1 + | | | | | ·a1-b1-c1 + | | | + | | ·a1-b1-c1 | | | *a1-a1 +(创建的时候是a1,通过修改改为a1-a1) | | |