This commit is contained in:
chenjianxing 2020-10-22 18:19:33 +08:00
commit 709a18697d
5 changed files with 45 additions and 16 deletions

View File

@ -9,6 +9,7 @@ import io.metersphere.commons.constants.NoticeConstants;
import io.metersphere.notice.domain.MessageDetail;
import io.metersphere.notice.domain.UserDetail;
import io.metersphere.service.UserService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
@ -19,12 +20,11 @@ import java.util.ArrayList;
import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public class DingTaskService {
@Resource
private UserService userService;
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void sendNailRobot(MessageDetail messageDetail, List<String> userIds, String context, String eventType) {
List<String> addresseeIdList = new ArrayList<>();
messageDetail.getEvents().forEach(e -> {
@ -54,6 +54,9 @@ public class DingTaskService {
}
public void sendDingTask(String context, List<String> userIds, String Webhook) {
if (CollectionUtils.isEmpty(userIds)) {
return;
}
DingTalkClient client = new DefaultDingTalkClient(Webhook);
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("text");

View File

@ -42,7 +42,7 @@ import java.text.SimpleDateFormat;
import java.util.*;
@Service
@Transactional(rollbackFor = Exception.class)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public class MailService {
@Resource
private UserService userService;
@ -70,6 +70,7 @@ public class MailService {
}
}
public void sendApiNotification(ApiTestReport apiTestReport, List<NoticeDetail> noticeList) {
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
Map<String, String> context = new HashMap<>();
@ -128,6 +129,7 @@ public class MailService {
}
//测试评审
public void sendEndNotice(MessageDetail messageDetail, List<String> userIds, SaveTestCaseReviewRequest reviewRequest, String eventType) {
Map<String, String> context = getReviewContext(reviewRequest);
try {
@ -138,6 +140,7 @@ public class MailService {
}
}
public void sendDeleteNotice(MessageDetail messageDetail, List<String> userIds, SaveTestCaseReviewRequest reviewRequest, String eventType) {
Map<String, String> context = getReviewContext(reviewRequest);
try {
@ -148,6 +151,7 @@ public class MailService {
}
}
public void sendCommentNotice(MessageDetail messageDetail, List<String> userIds, SaveCommentRequest request, TestCaseWithBLOBs testCaseWithBLOBs, String eventType) {
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
Map<String, String> context = new HashMap<>();
@ -164,6 +168,7 @@ public class MailService {
}
}
public void sendReviewerNotice(MessageDetail messageDetail, List<String> userIds, SaveTestCaseReviewRequest reviewRequest, String eventType) {
Map<String, String> context = getReviewContext(reviewRequest);
try {
@ -175,7 +180,7 @@ public class MailService {
}
//测试计划
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void sendTestPlanStartNotice(MessageDetail messageDetail, List<String> userIds, AddTestPlanRequest testPlan, String eventType) {
Map<String, String> context = getTestPlanContext(testPlan);
context.put("creator", userIds.toString());
@ -187,7 +192,7 @@ public class MailService {
}
}
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void sendTestPlanEndNotice(MessageDetail messageDetail, List<String> userIds, AddTestPlanRequest testPlan, String eventType) {
Map<String, String> context = getTestPlanContext(testPlan);
context.put("creator", userIds.toString());
@ -199,7 +204,7 @@ public class MailService {
}
}
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void sendTestPlanDeleteNotice(MessageDetail messageDetail, List<String> userIds, AddTestPlanRequest testPlan, String eventType) {
Map<String, String> context = getTestPlanContext(testPlan);
context.put("creator", userIds.toString());
@ -276,6 +281,9 @@ public class MailService {
}
private void sendReviewNotice(List<String> userIds, Map<String, String> context, String Template) throws MessagingException {
if (CollectionUtils.isEmpty(userIds)) {
return;
}
JavaMailSenderImpl javaMailSender = getMailSender();
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
@ -296,6 +304,9 @@ public class MailService {
}
private void sendTestPlanNotice(List<String> userIds, Map<String, String> context, String Template) throws MessagingException {
if (CollectionUtils.isEmpty(userIds)) {
return;
}
JavaMailSenderImpl javaMailSender = getMailSender();
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
@ -303,9 +314,6 @@ public class MailService {
helper.setSubject("MeterSphere平台" + Translator.get("test_plan_notification"));
String[] users;
List<String> emails = new ArrayList<>();
if (CollectionUtils.isEmpty(userIds)) {
return;
}
List<UserDetail> list = userService.queryTypeByIds(userIds);
list.forEach(u -> {
emails.add(u.getEmail());
@ -318,6 +326,9 @@ public class MailService {
}
private void sendIssuesNotice(List<String> userIds, Map<String, String> context, String Template) throws MessagingException {
if (CollectionUtils.isEmpty(userIds)) {
return;
}
JavaMailSenderImpl javaMailSender = getMailSender();
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);

View File

@ -7,6 +7,7 @@ import io.metersphere.notice.message.TextMessage;
import io.metersphere.notice.util.SendResult;
import io.metersphere.notice.util.WxChatbotClient;
import io.metersphere.service.UserService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
@ -18,12 +19,11 @@ import java.util.ArrayList;
import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public class WxChatTaskService {
@Resource
private UserService userService;
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void sendWechatRobot(MessageDetail messageDetail, List<String> userIds, String context, String eventType) {
List<String> addresseeIdList = new ArrayList<>();
messageDetail.getEvents().forEach(e -> {
@ -53,8 +53,11 @@ public class WxChatTaskService {
}
public void enterpriseWechatTask(String context, List<String> userIds, String Webhook) {
if (CollectionUtils.isEmpty(userIds)) {
return;
}
TextMessage message = new TextMessage(context);
List<String> mentionedMobileList = new ArrayList<String>();
List<String> mentionedMobileList = new ArrayList<>();
List<UserDetail> list = userService.queryTypeByIds(userIds);
List<String> phoneList = new ArrayList<>();
list.forEach(u -> {

View File

@ -360,9 +360,16 @@ public class TestCaseReviewService {
public void testReviewRelevance(ReviewRelevanceRequest request) {
String reviewId = request.getReviewId();
List<String> userIds = getTestCaseReviewerIds(reviewId);
String creator = "";
TestCaseReview review = testCaseReviewMapper.selectByPrimaryKey(reviewId);
if (review != null) {
creator = review.getCreator();
}
String currentId = SessionUtils.getUser().getId();
if (!userIds.contains(currentId)) {
MSException.throwException("非用例评审人员,不能关联用例!");
if (!userIds.contains(currentId) && !StringUtils.equals(creator, currentId)) {
MSException.throwException("没有权限,不能关联用例!");
}
List<String> testCaseIds = request.getTestCaseIds();

View File

@ -87,8 +87,13 @@ public class TestReviewTestCaseService {
private void checkReviewer(String reviewId) {
List<String> userIds = testCaseReviewService.getTestCaseReviewerIds(reviewId);
String currentId = SessionUtils.getUser().getId();
if (!userIds.contains(currentId)) {
MSException.throwException("非用例评审人员,不能解除用例关联!");
TestCaseReview caseReview = testCaseReviewMapper.selectByPrimaryKey(reviewId);
String creator = "";
if (caseReview != null) {
creator = caseReview.getCreator();
}
if (!userIds.contains(currentId) && !StringUtils.equals(creator, currentId)) {
MSException.throwException("没有权限,不能解除用例关联!");
}
}