diff --git a/backend/src/main/java/io/metersphere/controller/LoadTestController.java b/backend/src/main/java/io/metersphere/controller/LoadTestController.java index 91316b161b..dbe0e7c89e 100644 --- a/backend/src/main/java/io/metersphere/controller/LoadTestController.java +++ b/backend/src/main/java/io/metersphere/controller/LoadTestController.java @@ -24,6 +24,7 @@ import java.util.List; @RestController @RequestMapping(value = "/testplan") +@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR) public class LoadTestController { @Resource private LoadTestService loadTestService; @@ -31,7 +32,6 @@ public class LoadTestController { private FileService fileService; @GetMapping("recent/{count}") - @RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR) public List recentTestPlans(@PathVariable int count) { String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId(); QueryTestPlanRequest request = new QueryTestPlanRequest(); @@ -84,7 +84,7 @@ public class LoadTestController { } @PostMapping("/run") - public void delete(@RequestBody RunTestPlanRequest request) { + public void run(@RequestBody RunTestPlanRequest request) { loadTestService.run(request); } diff --git a/backend/src/main/java/io/metersphere/service/LoadTestService.java b/backend/src/main/java/io/metersphere/service/LoadTestService.java index 095438cae6..f85cad86f5 100644 --- a/backend/src/main/java/io/metersphere/service/LoadTestService.java +++ b/backend/src/main/java/io/metersphere/service/LoadTestService.java @@ -1,9 +1,6 @@ package io.metersphere.service; -import io.metersphere.base.domain.FileContent; -import io.metersphere.base.domain.FileMetadata; -import io.metersphere.base.domain.LoadTestFile; -import io.metersphere.base.domain.LoadTestWithBLOBs; +import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.ExtLoadTestMapper; import io.metersphere.commons.constants.EngineType; @@ -12,6 +9,7 @@ import io.metersphere.controller.request.testplan.*; import io.metersphere.dto.LoadTestDTO; import io.metersphere.engine.Engine; import io.metersphere.engine.EngineFactory; +import io.metersphere.i18n.Translator; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -69,6 +67,13 @@ public class LoadTestService { } private LoadTestWithBLOBs saveLoadTest(SaveTestPlanRequest request) { + + LoadTestExample example = new LoadTestExample(); + example.createCriteria().andNameEqualTo(request.getName()).andProjectIdEqualTo(request.getProjectId()); + if (loadTestMapper.countByExample(example) > 0) { + MSException.throwException(Translator.get("load_test_already_exists")); + } + final LoadTestWithBLOBs loadTest = new LoadTestWithBLOBs(); loadTest.setId(UUID.randomUUID().toString()); loadTest.setName(request.getName()); diff --git a/backend/src/main/java/io/metersphere/service/ProjectService.java b/backend/src/main/java/io/metersphere/service/ProjectService.java index 39b07b1ce0..c5b2944c7a 100644 --- a/backend/src/main/java/io/metersphere/service/ProjectService.java +++ b/backend/src/main/java/io/metersphere/service/ProjectService.java @@ -7,9 +7,9 @@ import io.metersphere.base.mapper.ext.ExtProjectMapper; import io.metersphere.commons.exception.MSException; import io.metersphere.controller.request.ProjectRequest; import io.metersphere.dto.ProjectDTO; +import io.metersphere.i18n.Translator; import io.metersphere.user.SessionUtils; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -27,14 +27,14 @@ public class ProjectService { public Project addProject(Project project) { if (StringUtils.isBlank(project.getName())) { - MSException.throwException("Project name cannot be null"); + MSException.throwException(Translator.get("project_name_is_null")); } ProjectExample example = new ProjectExample(); example.createCriteria() .andWorkspaceIdEqualTo(SessionUtils.getCurrentWorkspaceId()) .andNameEqualTo(project.getName()); if (projectMapper.countByExample(example) > 0) { - MSException.throwException("The project name already exists"); + MSException.throwException(Translator.get("project_name_already_exists")); } project.setId(UUID.randomUUID().toString()); long createTime = System.currentTimeMillis(); @@ -47,7 +47,7 @@ public class ProjectService { } public List getProjectList(ProjectRequest request) { - return extProjectMapper.getProjectWithWorkspace(request); + return extProjectMapper.getProjectWithWorkspace(request); } public void deleteProject(String projectId) { diff --git a/backend/src/main/java/io/metersphere/service/WorkspaceService.java b/backend/src/main/java/io/metersphere/service/WorkspaceService.java index 6ea453e7f3..d2ae432f07 100644 --- a/backend/src/main/java/io/metersphere/service/WorkspaceService.java +++ b/backend/src/main/java/io/metersphere/service/WorkspaceService.java @@ -13,6 +13,7 @@ import io.metersphere.controller.request.WorkspaceRequest; import io.metersphere.dto.UserRoleHelpDTO; import io.metersphere.dto.WorkspaceDTO; import io.metersphere.dto.WorkspaceMemberDTO; +import io.metersphere.i18n.Translator; import io.metersphere.user.SessionUser; import io.metersphere.user.SessionUtils; import org.apache.commons.lang3.StringUtils; @@ -44,7 +45,7 @@ public class WorkspaceService { public Workspace saveWorkspace(Workspace workspace) { if (StringUtils.isBlank(workspace.getName())) { - MSException.throwException("Workspace name cannot be null."); + MSException.throwException(Translator.get("workspace_name_is_null")); } // set organization id workspace.setOrganizationId(SessionUtils.getCurrentOrganizationId()); @@ -56,7 +57,7 @@ public class WorkspaceService { .andOrganizationIdEqualTo(SessionUtils.getCurrentOrganizationId()) .andNameEqualTo(workspace.getName()); if (workspaceMapper.countByExample(example) > 0) { - MSException.throwException("The workspace name already exists"); + MSException.throwException(Translator.get("workspace_name_already_exists")); } workspace.setId(UUID.randomUUID().toString()); // 设置ID workspace.setCreateTime(currentTime); @@ -89,6 +90,9 @@ public class WorkspaceService { workspaceMapper.deleteByPrimaryKey(workspaceId); } + /** + * ORG_ADMIN 需要检查是否有操作此工作空间的权限 + */ public void checkOwner(String workspaceId) { SessionUser user = SessionUtils.getUser(); List orgIds = user.getUserRoles().stream() @@ -100,7 +104,7 @@ public class WorkspaceService { .andOrganizationIdIn(orgIds) .andIdEqualTo(workspaceId); if (workspaceMapper.countByExample(example) == 0) { - MSException.throwException("The current workspace does not belong to the current user"); + MSException.throwException(Translator.get("workspace_does_not_belong_to_user")); } } @@ -128,7 +132,7 @@ public class WorkspaceService { List resultWorkspaceList = new ArrayList<>(); userRoles.forEach(userRole -> { workspaces.forEach(workspace -> { - if (StringUtils.equals(userRole.getSourceId(),workspace.getId())) { + if (StringUtils.equals(userRole.getSourceId(), workspace.getId())) { if (!resultWorkspaceList.contains(workspace)) { resultWorkspaceList.add(workspace); } diff --git a/backend/src/main/resources/i18n/en-US.json b/backend/src/main/resources/i18n/en-US.json index 10d54c8101..679dffb8b1 100644 --- a/backend/src/main/resources/i18n/en-US.json +++ b/backend/src/main/resources/i18n/en-US.json @@ -1,3 +1,9 @@ { - "error_lang_invalid": "Invalid language parameter" + "error_lang_invalid": "Invalid language parameter", + "load_test_already_exists": "Duplicate load test name", + "project_name_is_null": "Project name cannot be null", + "project_name_already_exists": "The project name already exists", + "workspace_name_is_null": "Workspace name cannot be null", + "workspace_name_already_exists": "The workspace name already exists", + "workspace_does_not_belong_to_user": "The current workspace does not belong to the current user" } \ No newline at end of file diff --git a/backend/src/main/resources/i18n/zh-CN.json b/backend/src/main/resources/i18n/zh-CN.json index cfa517a25c..23fe3b54ed 100644 --- a/backend/src/main/resources/i18n/zh-CN.json +++ b/backend/src/main/resources/i18n/zh-CN.json @@ -1,3 +1,9 @@ { - "error_lang_invalid": "语言参数错误" + "error_lang_invalid": "语言参数错误", + "load_test_already_exists": "测试名称不能重复", + "project_name_is_null": "项目名称不能为空", + "project_name_already_exists": "项目名称已存在", + "workspace_name_is_null": "工作空间名不能为空", + "workspace_name_already_exists": "工作空间名已存在", + "workspace_does_not_belong_to_user": "当前工作空间不属于当前用户" } \ No newline at end of file