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 a2059ff50c..16c710e210 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 @@ -196,14 +196,26 @@ public class NoticeMessageTaskService { * @return Map> */ private Map> checkUserExistProject(List receiverIds, String projectId) { - UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample(); - userRoleRelationExample.createCriteria().andUserIdIn(receiverIds).andSourceIdEqualTo(projectId); - List userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample); - List userIds = userRoleRelations.stream().map(UserRoleRelation::getUserId).distinct().toList(); - Map> map = new HashMap<>(); - if (CollectionUtils.isEmpty(userIds)) { - throw new MSException(Translator.get("user.not.exist")); + ListnormalUserIds = new ArrayList<>(); + for (String receiverId : receiverIds) { + if (!StringUtils.equalsIgnoreCase(receiverId, CREATOR) && !StringUtils.equalsIgnoreCase(receiverId, FOLLOW_PEOPLE)) { + normalUserIds.add(receiverId); + } } + List userIds = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(normalUserIds)) { + UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample(); + userRoleRelationExample.createCriteria().andUserIdIn(normalUserIds).andSourceIdEqualTo(projectId); + List userRoleRelations = userRoleRelationMapper.selectByExample(userRoleRelationExample); + userIds = new ArrayList<>(userRoleRelations.stream().map(UserRoleRelation::getUserId).distinct().toList()); + } + if (receiverIds.contains(CREATOR)) { + userIds.add(CREATOR); + } + if (receiverIds.contains(FOLLOW_PEOPLE)) { + userIds.add(FOLLOW_PEOPLE); + } + Map> map = new HashMap<>(); List noUserNames = new ArrayList<>(); if (userIds.size() < receiverIds.size()) { for (String receiverId : receiverIds) { diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java index ed9a20bb54..39c9c72476 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java @@ -66,6 +66,7 @@ public class NoticeTemplateService { addOptionDto(optionDTOList, allFields); //TODO:获取报告和自定义 } + default -> optionDTOList = new ArrayList<>(); } return optionDTOList; } 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 532eb94335..b54678f86e 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 @@ -129,6 +129,8 @@ public class NoticeMessageTaskControllerTests extends BaseTest { userIds.add("project-message-user-7"); userIds.add("project-message-user-8"); messageTaskRequest.setReceiverIds(userIds); + messageTaskRequest.setEnable(null); + messageTaskRequest.setTestId("testId"); messageTaskRequest.setTemplate("发送消息测试"); MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/notice/message/task/save") .header(SessionConstants.HEADER_TOKEN, sessionId) @@ -242,4 +244,111 @@ public class NoticeMessageTaskControllerTests extends BaseTest { List messageTaskDTOList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), MessageTaskDTO.class); Assertions.assertTrue(CollectionUtils.isEmpty(messageTaskDTOList)); } + + @Test + @Order(10) + public void addMessageTaskCheckSpecialUserSuccess() throws Exception { + MessageTaskRequest messageTaskRequest = new MessageTaskRequest(); + messageTaskRequest.setProjectId("project-message-test-1"); + messageTaskRequest.setTaskType(NoticeConstants.TaskType.API_DEFINITION_TASK); + messageTaskRequest.setEvent(NoticeConstants.Event.CREATE); + List userIds = new ArrayList<>(); + userIds.add("CREATOR"); + userIds.add("FOLLOW_PEOPLE"); + messageTaskRequest.setReceiverIds(userIds); + messageTaskRequest.setRobotId("test_message_robot2"); + messageTaskRequest.setEnable(true); + messageTaskRequest.setTemplate("发送消息测试"); + 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(11) + public void addMessageTaskCheckSpecialUserTwoSuccess() 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("CREATOR"); + userIds.add("FOLLOW_PEOPLE"); + userIds.add("project-message-user-5"); + messageTaskRequest.setReceiverIds(userIds); + messageTaskRequest.setRobotId("test_message_robot2"); + messageTaskRequest.setEnable(true); + messageTaskRequest.setTemplate("发送消息测试"); + 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(12) + public void addMessageTaskCheckSpecialUserThreeSuccess() 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("CREATOR"); + userIds.add("FOLLOW_PEOPLE"); + userIds.add("project-message-user-6"); + userIds.add("project-message-user-del"); + messageTaskRequest.setReceiverIds(userIds); + messageTaskRequest.setRobotId("test_message_robot2"); + messageTaskRequest.setEnable(true); + messageTaskRequest.setTemplate("发送消息测试"); + 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(102001, resultHolder.getCode()); + } + + @Test + @Order(13) + 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("CREATOR"); + userIds.add("FOLLOW_PEOPLE"); + messageTaskRequest.setReceiverIds(userIds); + messageTaskRequest.setRobotId("test_message_robot2"); + messageTaskRequest.setEnable(null); + messageTaskRequest.setTemplate("发送消息测试"); + 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()); + } } diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectRobotControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectRobotControllerTests.java index 393fce26de..b29f97f122 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectRobotControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectRobotControllerTests.java @@ -323,6 +323,20 @@ public class ProjectRobotControllerTests extends BaseTest { @Test @Order(21) + void setEnableFalseSuccess() throws Exception { + ProjectRobot projectRobot = getRobot("测试Enable"); + String projectRobotId = projectRobot.getId(); + mockMvc.perform(MockMvcRequestBuilders.get(ROBOT_ENABLE + "/" + projectRobotId) + .header(SessionConstants.HEADER_TOKEN, sessionId) + .header(SessionConstants.CSRF_TOKEN, csrfToken)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)); + ProjectRobot projectRobotEnable = getRobot("测试Enable"); + Assertions.assertTrue(projectRobotEnable.getEnable()); + } + + @Test + @Order(22) void setEnableFail() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get(ROBOT_ENABLE + "/no_id") .header(SessionConstants.HEADER_TOKEN, sessionId) @@ -332,6 +346,8 @@ public class ProjectRobotControllerTests extends BaseTest { } + + private static ProjectRobot getResult(MvcResult mvcResult) throws UnsupportedEncodingException { String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ;