diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseUserService.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseUserService.java index bb8706eeb4..0991d87bd1 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseUserService.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseUserService.java @@ -789,4 +789,16 @@ public class BaseUserService { List 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); + } + } } diff --git a/test-track/backend/src/main/java/io/metersphere/controller/TestPlanController.java b/test-track/backend/src/main/java/io/metersphere/controller/TestPlanController.java index 3d2ca40dae..6bf7b05db2 100644 --- a/test-track/backend/src/main/java/io/metersphere/controller/TestPlanController.java +++ b/test-track/backend/src/main/java/io/metersphere/controller/TestPlanController.java @@ -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); }