feat(功能用例): 评论删除只能由评论人自己删除

This commit is contained in:
guoyuqi 2024-01-22 17:29:38 +08:00 committed by Craftsman
parent 362b06cd86
commit fe94252ee0
8 changed files with 42 additions and 4 deletions

View File

@ -133,6 +133,7 @@ case_comment.parent_id_is_null=当前回复的评论id为空
case_comment.parent_case_is_null=当前回复的评论不存在
case_comment.reply_user_is_null=回复的用户为空
case_comment.id_is_null=当前评论id为空
case_comment.user_self=只能删除自己的评论
#module
case_module.not.exist=用例模块不存在
#case
@ -148,3 +149,6 @@ case_review.multiple=多人评审
case_review.not.exist=用例评审不存在
case_review_content.not.exist = 评审意见不能为空
case_review_history.system=系统触发
#minder
case.minder.all.case=全部用例

View File

@ -147,6 +147,7 @@ case_comment.parent_id_is_null=The comment id of the current reply is empty
case_comment.parent_case_is_null=The comment currently being replied to does not exist
case_comment.reply_user_is_null=The user who replied is empty
case_comment.id_is_null=The current comment id is empty
case_comment.user_self=You can only delete your own comments
un_follow_functional_case=unfollow functional case
follow_functional_case=followed functional case
#module
@ -168,3 +169,5 @@ case_review_history.system=System trigger
case_review.viewFlag.not_blank=View flag cannot be empty
functional_case_relationship_edge.type.not_blank=Relationship type cannot be empty
cycle_relationship=There is a circular dependency after association, please check the dependency relationship
#minder
case.minder.all.case=All Case

View File

@ -146,6 +146,7 @@ case_comment.parent_id_is_null=当前回复的评论id为空
case_comment.parent_case_is_null=当前回复的评论不存在
case_comment.reply_user_is_null=回复的用户为空
case_comment.id_is_null=当前评论id为空
case_comment.user_self=只能删除自己的评论
un_follow_functional_case=取消关注用例
follow_functional_case=关注用例
#module
@ -167,3 +168,5 @@ case_review_history.system=系统触发
case_review.viewFlag.not_blank=查看标识不能为空
functional_case_relationship_edge.type.not_blank=类型不能为空
cycle_relationship=关联后存在循环依赖,请检查依赖关系
#minder
case.minder.all.case=全部用例

View File

@ -147,6 +147,7 @@ case_comment.parent_id_is_null=目前回覆的評論id為空
case_comment.parent_case_is_null=目前回應的評論不存在
case_comment.reply_user_is_null=回覆的用戶為空
case_comment.id_is_null=目前評論id為空
case_comment.user_self=只能刪除自己的評論
un_follow_functional_case=取消關注用例
follow_functional_case=關注用例
#module
@ -168,3 +169,5 @@ case_review_history.system=系統觸發
case_review.viewFlag.not_blank=查看標誌不能為空
functional_case_relationship_edge.type.not_blank=類型不能為空
cycle_relationship=關聯后存在循環依賴,請檢查依賴關係
#minder
case.minder.all.case=全部用例

View File

@ -46,7 +46,7 @@ public class FunctionalCaseCommentController {
@Operation(summary = "用例管理-功能用例-用例评论-删除评论")
@RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_COMMENT)
public void deleteComment(@PathVariable String commentId) {
functionalCaseCommentService.deleteComment(commentId);
functionalCaseCommentService.deleteComment(commentId, SessionUtils.getUserId());
}
@GetMapping("/get/list/{caseId}")

View File

@ -213,11 +213,15 @@ public class FunctionalCaseCommentService {
return relatedUserList;
}
public void deleteComment(String commentId) {
public void deleteComment(String commentId, String userId) {
FunctionalCaseComment functionalCaseComment = functionalCaseCommentMapper.selectByPrimaryKey(commentId);
if (functionalCaseComment == null) {
return;
}
//只有评论人自己可以删除当前评论
if (!StringUtils.equalsIgnoreCase(functionalCaseComment.getCreateUser(), userId)) {
throw new MSException(Translator.get("case_comment.user_self"));
}
//删除选中的评论下的所有回复
FunctionalCaseCommentExample functionalCaseCommentExample = new FunctionalCaseCommentExample();
functionalCaseCommentExample.createCriteria().andParentIdEqualTo(commentId);

View File

@ -468,6 +468,15 @@ public class FunctionalCaseCommentControllerTests {
}
@Test
@Order(22)
public void deleteCommentUser() throws Exception {
delFunctionalCaseCommentError();
FunctionalCaseComment functionalCaseComment = functionalCaseCommentMapper.selectByPrimaryKey("user_not_exist");
Assertions.assertNotNull(functionalCaseComment);
}
private FunctionalCaseComment getFunctionalCaseComment(FunctionalCaseCommentRequest functionalCaseCommentRequest, String url) throws Exception {
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post(url).header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken)
@ -490,6 +499,15 @@ public class FunctionalCaseCommentControllerTests {
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
}
private void delFunctionalCaseCommentError() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get(DELETE_URL+ "user_not_exist").header(SessionConstants.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken)
.header(SessionConstants.CURRENT_PROJECT, projectId)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is5xxServerError())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}
private FunctionalCaseComment getFunctionalCaseComment() {
FunctionalCaseCommentExample functionalCaseCommentExample = new FunctionalCaseCommentExample();
functionalCaseCommentExample.createCriteria().andCaseIdEqualTo("xiaomeinvGTest");

View File

@ -142,5 +142,8 @@ VALUES (UUID(), 'default-project-member-user-guo', 'project_admin', 'project-cas
INSERT INTO user_role_permission(id, role_id, permission_id)
VALUES ('user_role_guo_permission1', 'project_admin', 'FUNCTIONAL_CASE:READ+COMMENT');
INSERT INTO functional_case_comment(id, case_id, create_user, parent_id, resource_id, notifier, content, reply_user, create_time, update_time)
VALUES ('user_not_exist', 'comment_case', 'gyq', 'NONE', null, 'gyq;', '', null,UNIX_TIMESTAMP() * 1000,UNIX_TIMESTAMP() * 1000);