diff --git a/backend/framework/sdk/src/main/resources/i18n/bug.properties b/backend/framework/sdk/src/main/resources/i18n/bug.properties index 85aca73e6e..a9b092ff73 100644 --- a/backend/framework/sdk/src/main/resources/i18n/bug.properties +++ b/backend/framework/sdk/src/main/resources/i18n/bug.properties @@ -79,6 +79,7 @@ bug_relation_case.create_user.length_range=创建人长度必须在1-50之间 # error bug_not_exist=缺陷不存在 not_local_bug_error=非本地缺陷,无法操作 +bug_tags_size_large_than=缺陷标签数量超过{0}个 third_party_not_config=项目未配置第三方平台 bug_attachment_upload_error=缺陷附件上传失败 bug_attachment_delete_error=缺陷附件删除失败 diff --git a/backend/framework/sdk/src/main/resources/i18n/bug_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/bug_en_US.properties index 1fb4b97e3d..7fa19413a4 100644 --- a/backend/framework/sdk/src/main/resources/i18n/bug_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/bug_en_US.properties @@ -78,6 +78,7 @@ bug_relation_case.create_user.length_range=createUser length must be between 1-5 # error bug_not_exist=Bug does not exist +bug_tags_size_large_than=Bug size large than {0} not_local_bug_error=Not local bug, error third_party_not_config=The project third-party platform not configured bug_attachment_upload_error=Bug attachment upload error diff --git a/backend/framework/sdk/src/main/resources/i18n/bug_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/bug_zh_CN.properties index 5f98c0005a..ea551093ea 100644 --- a/backend/framework/sdk/src/main/resources/i18n/bug_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/bug_zh_CN.properties @@ -79,6 +79,7 @@ bug_relation_case.create_user.length_range=创建人长度必须在1-50之间 # error bug_not_exist=缺陷不存在 not_local_bug_error=非本地缺陷,无法操作 +bug_tags_size_large_than=缺陷标签数量超过{0}个 third_party_not_config=项目未配置第三方平台 bug_attachment_upload_error=缺陷附件上传失败 bug_attachment_delete_error=缺陷附件删除失败 diff --git a/backend/framework/sdk/src/main/resources/i18n/bug_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/bug_zh_TW.properties index 4b56ed0d22..2c02932dbc 100644 --- a/backend/framework/sdk/src/main/resources/i18n/bug_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/bug_zh_TW.properties @@ -80,6 +80,7 @@ bug_relation_case.create_user.length_range=创建人長度必須在1-50之間 bug_not_exist=缺陷不存在 not_local_bug_error=非本地缺陷,無法操作 third_party_not_config=項目未配置第三方平台 +bug_tags_size_large_than=缺陷标签数量超过{0}个 bug_attachment_upload_error=缺陷附件上傳失敗 bug_attachment_delete_error=缺陷附件刪除失敗 no_bug_select=未勾選缺陷 diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java index 7dd45940c0..c37d4b8256 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java @@ -91,6 +91,8 @@ import static io.metersphere.bug.enums.result.BugResultCode.NOT_LOCAL_BUG_ERROR; @Transactional(rollbackFor = Exception.class) public class BugService { + private static int MAX_TAG_SIZE = 10; + @Resource private BugMapper bugMapper; @Resource @@ -176,6 +178,12 @@ public class BugService { return buildExtraInfo(bugList); } + private void checkTagLength(List tags) { + if (CollectionUtils.isNotEmpty(tags) && tags.size() > MAX_TAG_SIZE) { + throw new MSException(Translator.getWithArgs("bug_tags_size_large_than", String.valueOf(MAX_TAG_SIZE))); + } + } + /** * 创建或编辑缺陷 * @@ -187,6 +195,7 @@ public class BugService { * @return 缺陷 */ public Bug addOrUpdate(BugEditRequest request, List files, String currentUser, String currentOrgId, boolean isUpdate) { + this.checkTagLength(request.getTags()); /* * 缺陷创建或者修改逻辑: * 1. 判断所属项目是否关联第三方平台; @@ -418,8 +427,10 @@ public class BugService { * @param currentUser 当前用户 */ public void batchUpdate(BugBatchUpdateRequest request, String currentUser) { - List batchIds = getBatchIdsByRequest(request); + //校验标签长度 + this.checkTagLength(request.getTags()); + List batchIds = getBatchIdsByRequest(request); // 批量日志{修改之前} List logs = getBatchLogByRequest(batchIds, OperationLogType.UPDATE.name(), "/bug/batch-update", request.getProjectId(), true, request.isAppend(), request.getTags()); @@ -437,6 +448,9 @@ public class BugService { record.setTags(ListUtils.union(v, request.getTags())); record.setUpdateUser(currentUser); record.setUpdateTime(System.currentTimeMillis()); + //校验标签长度 + this.checkTagLength(record.getTags()); + //入库 batchMapper.updateByPrimaryKeySelective(record); }); sqlSession.flushStatements(); diff --git a/backend/services/bug-management/src/test/java/io/metersphere/bug/controller/BugControllerTests.java b/backend/services/bug-management/src/test/java/io/metersphere/bug/controller/BugControllerTests.java index 088580796f..acaa760377 100644 --- a/backend/services/bug-management/src/test/java/io/metersphere/bug/controller/BugControllerTests.java +++ b/backend/services/bug-management/src/test/java/io/metersphere/bug/controller/BugControllerTests.java @@ -256,6 +256,11 @@ public class BugControllerTests extends BaseTest { MultiValueMap paramMap = getMultiPartParam(request, file); this.requestMultipart(BUG_ADD, paramMap).andExpect(status().isBadRequest()); request.setProjectId("default-project-for-bug"); + // 标签超过10个 + request.setTags(List.of("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11")); + paramMap = getMultiPartParam(request, file); + this.requestMultipart(BUG_ADD, paramMap).andExpect(status().is5xxServerError()); + request.setTags(null); // 处理人为空 request.setTitle("default-bug-title"); List noHandleUser = request.getCustomFields().stream().filter(field -> !StringUtils.equals(field.getId(), "handleUser")).toList(); @@ -302,6 +307,13 @@ public class BugControllerTests extends BaseTest { File file = new File(filePath); MultiValueMap paramMap = getMultiPartParam(request, file); this.requestMultipart(BUG_UPDATE, paramMap).andExpect(status().is5xxServerError()); + + // 标签超过10个 + request = buildRequest(true); + request.setTags(List.of("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11")); + paramMap = getMultiPartParam(request, file); + this.requestMultipart(BUG_UPDATE, paramMap).andExpect(status().is5xxServerError()); + } @Test