From 1a9d36534aa9709625169dc05cd269428a65bb6a Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Wed, 27 Sep 2023 14:20:13 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=B6=88=E6=81=AF=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=20=E8=A1=A5=E5=85=85=E6=B6=88=E6=81=AF=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NoticeMessageTaskController.java | 3 +- .../project/dto/ProjectRobotDTO.java | 4 +- .../service/NoticeMessageTaskService.java | 12 ++--- .../NoticeMessageTaskControllerTests.java | 50 ++++++++++++++++--- 4 files changed, 50 insertions(+), 19 deletions(-) diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/controller/NoticeMessageTaskController.java b/backend/services/project-management/src/main/java/io/metersphere/project/controller/NoticeMessageTaskController.java index ff2a626e9e..41e814d1dc 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/controller/NoticeMessageTaskController.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/controller/NoticeMessageTaskController.java @@ -21,6 +21,7 @@ import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.io.IOException; import java.util.List; @@ -42,7 +43,7 @@ public class NoticeMessageTaskController { @GetMapping("message/task/get/{projectId}") @Operation(summary = "项目管理-项目与权限-消息管理-消息设置-获取消息设置") @RequiresPermissions(PermissionConstants.PROJECT_MESSAGE_READ_ADD) - public List getMessageList(@PathVariable String projectId) { + public List getMessageList(@PathVariable String projectId) throws IOException { return noticeMessageTaskService.getMessageList(projectId); } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/ProjectRobotDTO.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/ProjectRobotDTO.java index f776c6d9d0..1c4a93bcf5 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/ProjectRobotDTO.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/ProjectRobotDTO.java @@ -19,13 +19,13 @@ public class ProjectRobotDTO { @NotBlank(message = "{project_robot.name.not_blank}", groups = {Created.class, Updated.class}) private String name; - @Schema(description = "所属平台(飞书,钉钉,企业微信,自定义)", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "所属平台(飞书:LARK,钉钉:DING_TALK,企业微信:WE_COM,自定义:CUSTOM, 站内信:IN_SITE, 邮件:MAIL)", requiredMode = Schema.RequiredMode.REQUIRED) private String platform; @Schema(description = "webhook", requiredMode = Schema.RequiredMode.REQUIRED) private String webhook; - @Schema(description = "钉钉自定义和内部") + @Schema(description = "钉钉机器人的种类: 自定义:CUSTOM, 企业内部:ENTERPRISE") private String type; @Schema(description = "钉钉AppKey") diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeMessageTaskService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeMessageTaskService.java index 60be56c96e..9261237d76 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeMessageTaskService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeMessageTaskService.java @@ -279,21 +279,17 @@ public class NoticeMessageTaskService { * @param projectId 项目ID * @return List */ - public List getMessageList(String projectId) { + public List getMessageList(String projectId) throws IOException { checkProjectExist(projectId); //获取返回数据结构 StringBuilder jsonStr = new StringBuilder(); InputStream inputStream = getClass().getResourceAsStream("/message_task.json"); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); String line; - try { - while ((line = reader.readLine()) != null) { - jsonStr.append(line); - } - reader.close(); - } catch (IOException e) { - throw new RuntimeException(e); + while ((line = reader.readLine()) != null) { + jsonStr.append(line); } + reader.close(); List messageTaskDTOList = JSON.parseArray(jsonStr.toString(), MessageTaskDTO.class); //查询数据 MessageTaskExample messageTaskExample = new MessageTaskExample(); diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeMessageTaskControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeMessageTaskControllerTests.java index 4fd009b64d..954115002b 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeMessageTaskControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeMessageTaskControllerTests.java @@ -86,6 +86,9 @@ public class NoticeMessageTaskControllerTests extends BaseTest { messageTaskRequest.setRobotId("test_message_robot2"); messageTaskRequest.setEnable(true); messageTaskRequest.setTemplate("发送消息测试"); + messageTaskRequest.setUseDefaultTemplate(true); + messageTaskRequest.setSubject("发送消息测试标题"); + messageTaskRequest.setUseDefaultTemplate(true); MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/notice/message/task/save") .header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.CSRF_TOKEN, csrfToken) @@ -300,8 +303,9 @@ public class NoticeMessageTaskControllerTests extends BaseTest { messageTaskRequest.setTaskType(NoticeConstants.TaskType.API_DEFINITION_TASK); messageTaskRequest.setEvent(NoticeConstants.Event.CREATE); List userIds = new ArrayList<>(); - userIds.add("CREATE_USER"); - userIds.add("FOLLOW_PEOPLE"); + userIds.add(NoticeConstants.RelatedUser.CREATE_USER); + userIds.add(NoticeConstants.RelatedUser.FOLLOW_PEOPLE); + userIds.add(NoticeConstants.RelatedUser.OPERATOR); messageTaskRequest.setReceiverIds(userIds); messageTaskRequest.setRobotId("test_message_robot2"); messageTaskRequest.setEnable(true); @@ -326,8 +330,8 @@ public class NoticeMessageTaskControllerTests extends BaseTest { messageTaskRequest.setTaskType(NoticeConstants.TaskType.API_DEFINITION_TASK); messageTaskRequest.setEvent(NoticeConstants.Event.CREATE); List userIds = new ArrayList<>(); - userIds.add("CREATE_USER"); - userIds.add("FOLLOW_PEOPLE"); + userIds.add(NoticeConstants.RelatedUser.CREATE_USER); + userIds.add(NoticeConstants.RelatedUser.FOLLOW_PEOPLE); userIds.add("project-message-user-5"); messageTaskRequest.setReceiverIds(userIds); messageTaskRequest.setRobotId("test_message_robot2"); @@ -353,8 +357,8 @@ public class NoticeMessageTaskControllerTests extends BaseTest { messageTaskRequest.setTaskType(NoticeConstants.TaskType.API_DEFINITION_TASK); messageTaskRequest.setEvent(NoticeConstants.Event.CREATE); List userIds = new ArrayList<>(); - userIds.add("CREATE_USER"); - userIds.add("FOLLOW_PEOPLE"); + userIds.add(NoticeConstants.RelatedUser.CREATE_USER); + userIds.add(NoticeConstants.RelatedUser.FOLLOW_PEOPLE); userIds.add("project-message-user-6"); userIds.add("project-message-user-del"); messageTaskRequest.setReceiverIds(userIds); @@ -375,14 +379,44 @@ public class NoticeMessageTaskControllerTests extends BaseTest { @Test @Order(14) + public void updateMessageTaskCheckSpecialUserThreeSuccess() throws Exception { + MessageTaskRequest messageTaskRequest = new MessageTaskRequest(); + messageTaskRequest.setProjectId("project-message-test"); + messageTaskRequest.setTaskType(NoticeConstants.TaskType.API_DEFINITION_TASK); + messageTaskRequest.setEvent(NoticeConstants.Event.CREATE); + List userIds = new ArrayList<>(); + userIds.add(NoticeConstants.RelatedUser.CREATE_USER); + userIds.add(NoticeConstants.RelatedUser.FOLLOW_PEOPLE); + userIds.add("project-message-user-6"); + messageTaskRequest.setReceiverIds(userIds); + messageTaskRequest.setRobotId("test_message_robot2"); + messageTaskRequest.setEnable(false); + messageTaskRequest.setTemplate("发送消息测试"); + messageTaskRequest.setSubject("发送消息测试标题"); + messageTaskRequest.setUseDefaultTemplate(false); + messageTaskRequest.setUseDefaultSubject(false); + MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/notice/message/task/save") + .header(SessionConstants.HEADER_TOKEN, sessionId) + .header(SessionConstants.CSRF_TOKEN, csrfToken) + .content(JSON.toJSONString(messageTaskRequest)) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); + Assertions.assertEquals(100200, resultHolder.getCode()); + } + + @Test + @Order(15) public void closeMessageTaskSuccess() throws Exception { MessageTaskRequest messageTaskRequest = new MessageTaskRequest(); messageTaskRequest.setProjectId("project-message-test"); messageTaskRequest.setTaskType(NoticeConstants.TaskType.API_DEFINITION_TASK); messageTaskRequest.setEvent(NoticeConstants.Event.CREATE); List userIds = new ArrayList<>(); - userIds.add("CREATE_USER"); - userIds.add("FOLLOW_PEOPLE"); + userIds.add(NoticeConstants.RelatedUser.CREATE_USER); + userIds.add(NoticeConstants.RelatedUser.FOLLOW_PEOPLE); messageTaskRequest.setReceiverIds(userIds); messageTaskRequest.setRobotId("test_message_robot2"); messageTaskRequest.setEnable(false);