From ce8d123e58f0b59cee7c7489c8dcde97fe4b4b2f Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Fri, 19 Apr 2024 16:43:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E9=80=9A=E7=94=A8=E5=8A=9F=E8=83=BD):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B7=A8=E9=A1=B9=E7=9B=AE=E7=A6=81=E7=94=A8?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1039611 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001039611 --- .../service/FunctionalCaseService.java | 1 + .../project/controller/ProjectController.java | 7 ++++ .../project/mapper/ExtProjectMapper.java | 3 ++ .../project/mapper/ExtProjectMapper.xml | 24 +++++++++++ .../project/service/ProjectService.java | 42 +++++++++++++++++-- .../controller/ProjectControllerTests.java | 35 ++++++++++++++++ .../tabContent/tabCase/tabCaseTable.vue | 41 +++++++++--------- 7 files changed, 131 insertions(+), 22 deletions(-) diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java index ec850a8b1e..efb5c9c232 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java @@ -820,6 +820,7 @@ public class FunctionalCaseService { functional.setPos(nextOrder.get()); functional.setLastExecuteResult(FunctionalCaseExecuteResult.UN_EXECUTED.name()); functional.setCreateUser(userId); + functional.setUpdateUser(userId); functional.setCreateTime(System.currentTimeMillis()); functional.setUpdateTime(System.currentTimeMillis()); functionalCaseMapper.insert(functional); diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectController.java b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectController.java index 3586a156cf..4025dac746 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectController.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectController.java @@ -47,6 +47,13 @@ public class ProjectController { return projectService.getUserProject(organizationId, SessionUtils.getUserId()); } + @GetMapping("/list/options/{organizationId}/{module}") + @Operation(summary = "根据组织ID获取所有开启某个模块的所有权限的项目") + @CheckOwner(resourceId = "#organizationId", resourceType = "organization") + public List getUserProjectWidthModule(@PathVariable String organizationId, @PathVariable String module) { + return projectService.getUserProjectWidthModule(organizationId, module, SessionUtils.getUserId()); + } + @PostMapping("/switch") @Operation(summary = "切换项目") @RequiresPermissions(PermissionConstants.PROJECT_BASE_INFO_READ) diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMapper.java b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMapper.java index a8405390f8..260c075c07 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMapper.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMapper.java @@ -28,5 +28,8 @@ public interface ExtProjectMapper { List getAllProject(@Param("organizationId") String organizationId); List getResourcePoolOption(@Param("projectId") String projectId, @Param("type") String type); + List getAllProjectWidthModule(@Param("organizationId") String organizationId, @Param("module") String module); + + List getUserProjectWidthModule(@Param("organizationId") String organizationId, @Param("userId") String userId, @Param("module") String module); } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMapper.xml b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMapper.xml index 2782f4c873..c373822bac 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMapper.xml +++ b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtProjectMapper.xml @@ -94,4 +94,28 @@ and t.deleted = 0 and t.${type} = 1 + + + + + \ No newline at end of file diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectService.java index 26c744bfdf..1c7ac7ce46 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectService.java @@ -68,9 +68,7 @@ public class ProjectService { public List getUserProject(String organizationId, String userId) { - if (organizationMapper.selectByPrimaryKey(organizationId) == null) { - throw new MSException(Translator.get("organization_not_exist")); - } + checkOrg(organizationId); //查询用户当前的项目 如果存在默认排在第一个 User user = baseUserMapper.selectById(userId); String projectId; @@ -100,6 +98,12 @@ public class ProjectService { .orElse(allProject); } + private void checkOrg(String organizationId) { + if (organizationMapper.selectByPrimaryKey(organizationId) == null) { + throw new MSException(Translator.get("organization_not_exist")); + } + } + public UserDTO switchProject(ProjectSwitchRequest request, String currentUserId) { if (!StringUtils.equals(currentUserId, request.getUserId())) { throw new MSException(Translator.get("not_authorized")); @@ -245,5 +249,37 @@ public class ProjectService { } return extSystemProjectMapper.getMemberByProjectId(projectId, keyword); } + + public List getUserProjectWidthModule(String organizationId, String module, String userId) { + checkOrg(organizationId); + //查询用户当前的项目 如果存在默认排在第一个 + User user = baseUserMapper.selectById(userId); + String projectId; + if (user != null && StringUtils.isNotBlank(user.getLastProjectId())) { + projectId = user.getLastProjectId(); + } else { + projectId = null; + } + //判断用户是否是系统管理员 + List allProject; + UserRoleRelationExample userRoleRelationExample = new UserRoleRelationExample(); + userRoleRelationExample.createCriteria().andUserIdEqualTo(userId).andRoleIdEqualTo(InternalUserRole.ADMIN.name()); + if (userRoleRelationMapper.countByExample(userRoleRelationExample) > 0) { + allProject = extProjectMapper.getAllProjectWidthModule(organizationId, module); + } else { + allProject = extProjectMapper.getUserProjectWidthModule(organizationId, userId, module); + } + List temp = allProject; + return allProject.stream() + .filter(project -> StringUtils.equals(project.getId(), projectId)) + .findFirst() + .map(project -> { + temp.remove(project); + temp.add(0, project); + return temp; + }) + .orElse(allProject); + + } } diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectControllerTests.java index 2482ac6002..cbfcfffc33 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectControllerTests.java @@ -53,6 +53,7 @@ public class ProjectControllerTests extends BaseTest { private static final String prefix = "/project"; private static final String getOptions = prefix + "/list/options/"; private final static String updateProject = prefix + "/update"; + private static final String getOptionsWidthModule = prefix + "/list/options/"; private static final String getPoolOptions = prefix + "/pool-options/"; @@ -214,6 +215,20 @@ public class ProjectControllerTests extends BaseTest { example.createCriteria().andOrganizationIdEqualTo(DEFAULT_ORGANIZATION_ID).andEnableEqualTo(true); Assertions.assertEquals(projectMapper.countByExample(example), list.size()); + MvcResult mvcResultModule = this.responseGet(getOptionsWidthModule + DEFAULT_ORGANIZATION_ID +"/apiTest"); + List listModule = parseObjectFromMvcResult(mvcResultModule, List.class); + Assertions.assertNotNull(listModule); + ProjectExample exampleWidthModule = new ProjectExample(); + exampleWidthModule.createCriteria().andOrganizationIdEqualTo(DEFAULT_ORGANIZATION_ID).andEnableEqualTo(true); + List projects = projectMapper.selectByExample(exampleWidthModule); + int a = 0; + for (Project project : projects) { + if (StringUtils.isNotBlank(project.getModuleSetting()) && project.getModuleSetting().contains("apiTest")) { + a = a+1; + } + } + Assertions.assertEquals(a, listModule.size()); + UserRoleRelation userRoleRelation = new UserRoleRelation(); userRoleRelation.setUserId("admin1"); userRoleRelation.setOrganizationId(DEFAULT_ORGANIZATION_ID); @@ -244,6 +259,15 @@ public class ProjectControllerTests extends BaseTest { list = parseObjectFromMvcResult(mvcResult, List.class); Assertions.assertNotNull(list); + mvcResult = mockMvc.perform(MockMvcRequestBuilders.get(getOptions + DEFAULT_ORGANIZATION_ID+"/apiTest") + .header(SessionConstants.HEADER_TOKEN, sessionId) + .header(SessionConstants.CSRF_TOKEN, csrfToken) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + listModule = parseObjectFromMvcResult(mvcResult, List.class); + Assertions.assertNotNull(listModule); + //被删除的用户 查出来的是空的 mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/login") .content(String.format("{\"username\":\"%s\",\"password\":\"%s\"}", "delete", "deleted@metersphere.io")) @@ -262,6 +286,17 @@ public class ProjectControllerTests extends BaseTest { list = parseObjectFromMvcResult(mvcResult, List.class); //断言list是空的 Assertions.assertEquals(0, list.size()); + + mvcResult = mockMvc.perform(MockMvcRequestBuilders.get(getOptions + DEFAULT_ORGANIZATION_ID+"/apiTest") + .header(SessionConstants.HEADER_TOKEN, sessionId) + .header(SessionConstants.CSRF_TOKEN, csrfToken) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + listModule = parseObjectFromMvcResult(mvcResult, List.class); + Assertions.assertNotNull(listModule); + //断言list是空的 + Assertions.assertEquals(0, listModule.size()); } @Test diff --git a/frontend/src/views/case-management/caseManagementFeature/components/tabContent/tabCase/tabCaseTable.vue b/frontend/src/views/case-management/caseManagementFeature/components/tabContent/tabCase/tabCaseTable.vue index 819df419d0..9932b1e6bc 100644 --- a/frontend/src/views/case-management/caseManagementFeature/components/tabContent/tabCase/tabCaseTable.vue +++ b/frontend/src/views/case-management/caseManagementFeature/components/tabContent/tabCase/tabCaseTable.vue @@ -89,7 +89,6 @@ getPublicLinkCaseList, getPublicLinkModuleTree, } from '@/api/modules/case-management/featureCase'; - import { postTabletList } from '@/api/modules/project-management/menuManagement'; import { useI18n } from '@/hooks/useI18n'; import { useAppStore } from '@/store'; import useFeatureCaseStore from '@/store/modules/case/featureCase'; @@ -212,8 +211,8 @@ setLoadListParams({ keyword: keyword.value, sourceId: props.caseId, - projectId: currentProjectId.value, - sourceType: currentSelectCase.value, + // projectId: currentProjectId.value, // 加了项目筛选再打开,目前先关闭 + // sourceType: currentSelectCase.value, // 加了类型筛选再打开, 目前先关闭 condition: { keyword: keyword.value, }, @@ -247,25 +246,29 @@ label: t('caseManagement.featureCase.sceneCase'), }, ], - uiTest: [ - { - value: 'UI', - label: t('caseManagement.featureCase.uiCase'), - }, - ], - loadTest: [ - { - value: 'PERFORMANCE', - label: t('caseManagement.featureCase.propertyCase'), - }, - ], + // uiTest: [ + // { + // value: 'UI', + // label: t('caseManagement.featureCase.uiCase'), + // }, + // ], + // loadTest: [ + // { + // value: 'PERFORMANCE', + // label: t('caseManagement.featureCase.propertyCase'), + // }, + // ], }; async function getEnabledModules() { - const result = await postTabletList({ projectId: currentProjectId.value }); - const caseArr = result.filter((item) => Object.keys(moduleMaps).includes(item.module)); - caseArr.forEach((item: any) => { - const currentModule = moduleMaps[item.module]; + // const result = await postTabletList({ projectId: currentProjectId.value }); + // const caseArr = result.filter((item) => Object.keys(moduleMaps).includes(item.module)); + // caseArr.forEach((item: any) => { + // const currentModule = moduleMaps[item.module]; + // caseTypeOptions.value.push(...currentModule); + // }); + Object.keys(moduleMaps).forEach((item: any) => { + const currentModule = moduleMaps[item]; caseTypeOptions.value.push(...currentModule); }); currentSelectCase.value = caseTypeOptions.value[0].value;