feat(缺陷管理): 缺陷管理的标签数量增加限制

【【缺陷管理】创建缺陷时,标签个数没有限制10个以内】
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001036344
This commit is contained in:
song-tianyang 2024-02-28 16:01:01 +08:00 committed by 刘瑞斌
parent 49942eb646
commit 7e45a24752
6 changed files with 31 additions and 1 deletions

View File

@ -79,6 +79,7 @@ bug_relation_case.create_user.length_range=创建人长度必须在1-50之间
# error # error
bug_not_exist=缺陷不存在 bug_not_exist=缺陷不存在
not_local_bug_error=非本地缺陷,无法操作 not_local_bug_error=非本地缺陷,无法操作
bug_tags_size_large_than=缺陷标签数量超过{0}个
third_party_not_config=项目未配置第三方平台 third_party_not_config=项目未配置第三方平台
bug_attachment_upload_error=缺陷附件上传失败 bug_attachment_upload_error=缺陷附件上传失败
bug_attachment_delete_error=缺陷附件删除失败 bug_attachment_delete_error=缺陷附件删除失败

View File

@ -78,6 +78,7 @@ bug_relation_case.create_user.length_range=createUser length must be between 1-5
# error # error
bug_not_exist=Bug does not exist 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 not_local_bug_error=Not local bug, error
third_party_not_config=The project third-party platform not configured third_party_not_config=The project third-party platform not configured
bug_attachment_upload_error=Bug attachment upload error bug_attachment_upload_error=Bug attachment upload error

View File

@ -79,6 +79,7 @@ bug_relation_case.create_user.length_range=创建人长度必须在1-50之间
# error # error
bug_not_exist=缺陷不存在 bug_not_exist=缺陷不存在
not_local_bug_error=非本地缺陷,无法操作 not_local_bug_error=非本地缺陷,无法操作
bug_tags_size_large_than=缺陷标签数量超过{0}个
third_party_not_config=项目未配置第三方平台 third_party_not_config=项目未配置第三方平台
bug_attachment_upload_error=缺陷附件上传失败 bug_attachment_upload_error=缺陷附件上传失败
bug_attachment_delete_error=缺陷附件删除失败 bug_attachment_delete_error=缺陷附件删除失败

View File

@ -80,6 +80,7 @@ bug_relation_case.create_user.length_range=创建人長度必須在1-50之間
bug_not_exist=缺陷不存在 bug_not_exist=缺陷不存在
not_local_bug_error=非本地缺陷,無法操作 not_local_bug_error=非本地缺陷,無法操作
third_party_not_config=項目未配置第三方平台 third_party_not_config=項目未配置第三方平台
bug_tags_size_large_than=缺陷标签数量超过{0}个
bug_attachment_upload_error=缺陷附件上傳失敗 bug_attachment_upload_error=缺陷附件上傳失敗
bug_attachment_delete_error=缺陷附件刪除失敗 bug_attachment_delete_error=缺陷附件刪除失敗
no_bug_select=未勾選缺陷 no_bug_select=未勾選缺陷

View File

@ -91,6 +91,8 @@ import static io.metersphere.bug.enums.result.BugResultCode.NOT_LOCAL_BUG_ERROR;
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public class BugService { public class BugService {
private static int MAX_TAG_SIZE = 10;
@Resource @Resource
private BugMapper bugMapper; private BugMapper bugMapper;
@Resource @Resource
@ -176,6 +178,12 @@ public class BugService {
return buildExtraInfo(bugList); return buildExtraInfo(bugList);
} }
private void checkTagLength(List<String> 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 缺陷 * @return 缺陷
*/ */
public Bug addOrUpdate(BugEditRequest request, List<MultipartFile> files, String currentUser, String currentOrgId, boolean isUpdate) { public Bug addOrUpdate(BugEditRequest request, List<MultipartFile> files, String currentUser, String currentOrgId, boolean isUpdate) {
this.checkTagLength(request.getTags());
/* /*
* 缺陷创建或者修改逻辑: * 缺陷创建或者修改逻辑:
* 1. 判断所属项目是否关联第三方平台; * 1. 判断所属项目是否关联第三方平台;
@ -418,8 +427,10 @@ public class BugService {
* @param currentUser 当前用户 * @param currentUser 当前用户
*/ */
public void batchUpdate(BugBatchUpdateRequest request, String currentUser) { public void batchUpdate(BugBatchUpdateRequest request, String currentUser) {
List<String> batchIds = getBatchIdsByRequest(request); //校验标签长度
this.checkTagLength(request.getTags());
List<String> batchIds = getBatchIdsByRequest(request);
// 批量日志{修改之前} // 批量日志{修改之前}
List<LogDTO> logs = getBatchLogByRequest(batchIds, OperationLogType.UPDATE.name(), "/bug/batch-update", List<LogDTO> logs = getBatchLogByRequest(batchIds, OperationLogType.UPDATE.name(), "/bug/batch-update",
request.getProjectId(), true, request.isAppend(), request.getTags()); request.getProjectId(), true, request.isAppend(), request.getTags());
@ -437,6 +448,9 @@ public class BugService {
record.setTags(ListUtils.union(v, request.getTags())); record.setTags(ListUtils.union(v, request.getTags()));
record.setUpdateUser(currentUser); record.setUpdateUser(currentUser);
record.setUpdateTime(System.currentTimeMillis()); record.setUpdateTime(System.currentTimeMillis());
//校验标签长度
this.checkTagLength(record.getTags());
//入库
batchMapper.updateByPrimaryKeySelective(record); batchMapper.updateByPrimaryKeySelective(record);
}); });
sqlSession.flushStatements(); sqlSession.flushStatements();

View File

@ -256,6 +256,11 @@ public class BugControllerTests extends BaseTest {
MultiValueMap<String, Object> paramMap = getMultiPartParam(request, file); MultiValueMap<String, Object> paramMap = getMultiPartParam(request, file);
this.requestMultipart(BUG_ADD, paramMap).andExpect(status().isBadRequest()); this.requestMultipart(BUG_ADD, paramMap).andExpect(status().isBadRequest());
request.setProjectId("default-project-for-bug"); 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"); request.setTitle("default-bug-title");
List<BugCustomFieldDTO> noHandleUser = request.getCustomFields().stream().filter(field -> !StringUtils.equals(field.getId(), "handleUser")).toList(); List<BugCustomFieldDTO> 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); File file = new File(filePath);
MultiValueMap<String, Object> paramMap = getMultiPartParam(request, file); MultiValueMap<String, Object> paramMap = getMultiPartParam(request, file);
this.requestMultipart(BUG_UPDATE, paramMap).andExpect(status().is5xxServerError()); 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 @Test