fix(项目管理): 文件节点移动时增加文件名在当前目录下不能重复的校验

--bug=1035097 --user=宋天阳 【文件管理】-拖拽移动模块到有重名的模块中,提示信息不友好 https://www.tapd.cn/55049933/s/1458560
This commit is contained in:
song-tianyang 2024-02-01 17:38:15 +08:00 committed by Craftsman
parent 356443d55e
commit 3d78d116ad
2 changed files with 50 additions and 1 deletions

View File

@ -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());

View File

@ -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<BaseTreeNode> preliminaryTreeNodes = new ArrayList<>();
private static final Map<String, String> 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);
}
//测试a1b1c1child)节点无法移动到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
| | |