fix(测试跟踪): 测试计划执行接口增加对操作人以及操作项目的校验

--bug=1026974 --user=宋天阳
[消息通知]github#24902调用/track/test/plan/run/save接口执行测试计划时,如果userId参数不是平台上存在的用户,消息通知会判断出错
https://www.tapd.cn/55049933/s/1385555
This commit is contained in:
song-tianyang 2023-06-25 16:14:09 +08:00 committed by 刘瑞斌
parent 0b323768b3
commit 9a7dbf23b4
2 changed files with 16 additions and 5 deletions

View File

@ -789,4 +789,16 @@ public class BaseUserService {
List<User> users = userMapper.selectByExample(new UserExample());
return users.stream().map(User::getId).collect(Collectors.toList());
}
public void checkUserAndProject(String userId, String projectId) {
User user = userMapper.selectByPrimaryKey(userId);
if (user == null) {
MSException.throwException(Translator.get("user_not_exist") + userId);
}
UserGroupExample userGroupExample = new UserGroupExample();
userGroupExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(projectId);
if (userGroupMapper.countByExample(userGroupExample) == 0) {
MSException.throwException(Translator.get("user_not_exists") + userId);
}
}
}

View File

@ -5,13 +5,11 @@ import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.*;
import io.metersphere.commons.constants.*;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.dto.ScheduleDTO;
import io.metersphere.dto.TestPlanDTOWithMetric;
import io.metersphere.dto.TestPlanRerunParametersDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.log.annotation.MsRequestLog;
import io.metersphere.notice.annotation.SendNotice;
@ -268,9 +266,8 @@ public class TestPlanController {
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_PLAN_READ_RUN)
@MsRequestLog(module = OperLogModule.TRACK_TEST_PLAN)
public String run(@RequestBody TestPlanRunRequest testplanRunRequest) {
if (baseUserService.getUserDTO(testplanRunRequest.getUserId()) == null) {
MSException.throwException(Translator.get("user_not_exist"));
}
//检查用户是否存在
baseUserService.checkUserAndProject(testplanRunRequest.getUserId(), testplanRunRequest.getProjectId());
return testPlanService.runPlan(testplanRunRequest);
}
@ -278,6 +275,8 @@ public class TestPlanController {
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_PLAN_READ_RUN)
@MsRequestLog(module = OperLogModule.TRACK_TEST_PLAN)
public String runAndSave(@RequestBody TestPlanRunRequest testplanRunRequest) {
//检查用户是否存在
baseUserService.checkUserAndProject(testplanRunRequest.getUserId(), testplanRunRequest.getProjectId());
testPlanService.updateRunModeConfig(testplanRunRequest);
return testPlanService.runPlan(testplanRunRequest);
}