From e9bef3c856e8c4972fe33803362ae5bf40c65116 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Fri, 20 Dec 2024 15:20:59 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=B7=A5=E4=BD=9C=E5=8F=B0):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=9C=AA=E6=8C=89=E7=85=A7=E5=88=97=E8=A1=A8=E9=A1=BA?= =?UTF-8?q?=E5=BA=8F=E8=8E=B7=E5=8F=96=E9=BB=98=E8=AE=A4=E6=9D=83=E9=99=90?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1050600 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001050600 --- .../metersphere/dashboard/dto/LayoutDTO.java | 2 + .../service/DashboardProjectService.java | 54 +++++++++---------- .../dashboard/service/DashboardService.java | 9 ++++ .../service/PermissionCheckService.java | 21 ++++---- .../plan/mapper/ExtTestPlanMapper.java | 13 +++-- .../plan/mapper/ExtTestPlanMapper.xml | 10 ++++ 6 files changed, 66 insertions(+), 43 deletions(-) diff --git a/backend/services/dashboard/src/main/java/io/metersphere/dashboard/dto/LayoutDTO.java b/backend/services/dashboard/src/main/java/io/metersphere/dashboard/dto/LayoutDTO.java index 6036c162a8..112c0e90c9 100644 --- a/backend/services/dashboard/src/main/java/io/metersphere/dashboard/dto/LayoutDTO.java +++ b/backend/services/dashboard/src/main/java/io/metersphere/dashboard/dto/LayoutDTO.java @@ -34,5 +34,7 @@ public class LayoutDTO implements Serializable { private List handleUsers; @Schema(description = "测试计划ID") private String planId; + @Schema(description = "测试计划组ID") + private String groupId; } diff --git a/backend/services/dashboard/src/main/java/io/metersphere/dashboard/service/DashboardProjectService.java b/backend/services/dashboard/src/main/java/io/metersphere/dashboard/service/DashboardProjectService.java index 9716cfc52c..e27999d556 100644 --- a/backend/services/dashboard/src/main/java/io/metersphere/dashboard/service/DashboardProjectService.java +++ b/backend/services/dashboard/src/main/java/io/metersphere/dashboard/service/DashboardProjectService.java @@ -36,17 +36,17 @@ public class DashboardProjectService { boolean isAdmin = isAdmin(userId); Set projectSet; Map moduleMap; - projectSet = projects.stream().map(Project::getId).collect(Collectors.toSet()); + projectSet = projects.stream() .map(Project::getId).collect(Collectors.toCollection(LinkedHashSet::new)); moduleMap = projects.stream().collect(Collectors.toMap(Project::getId, Project::getModuleSetting)); Map> hasModuleProjectIds = new HashMap<>(); Map finalModuleMap = moduleMap; - Set searchCaseProjectIds = new HashSet<>(); - Set searchReviewProjectIds = new HashSet<>(); - Set searchApiProjectIds = new HashSet<>(); - Set searchApiCaseProjectIds = new HashSet<>(); - Set searchScenarioProjectIds = new HashSet<>(); - Set searchPlanProjectIds = new HashSet<>(); - Set searchBugProjectIds = new HashSet<>(); + Set searchCaseProjectIds = new LinkedHashSet<>(); + Set searchReviewProjectIds = new LinkedHashSet<>(); + Set searchApiProjectIds = new LinkedHashSet<>(); + Set searchApiCaseProjectIds = new LinkedHashSet<>(); + Set searchScenarioProjectIds = new LinkedHashSet<>(); + Set searchPlanProjectIds = new LinkedHashSet<>(); + Set searchBugProjectIds = new LinkedHashSet<>(); //查出用户在选中的项目中有读取权限的, admin所有项目都有权限 if (!isAdmin) { Set permissionSet = getPermissionSet(); @@ -56,44 +56,44 @@ public class DashboardProjectService { //检查是否开启功能用例模块 if (CollectionUtils.isNotEmpty(functionalProjectIds)) { //有权限 - searchCaseProjectIds = functionalProjectIds.stream().filter(t -> finalModuleMap.get(t).contains(FUNCTIONAL_CASE)).collect(Collectors.toSet()); + searchCaseProjectIds = functionalProjectIds.stream().filter(t -> finalModuleMap.get(t).contains(FUNCTIONAL_CASE)).collect(Collectors.toCollection(LinkedHashSet::new)); } Set reviewProjectIds = hasUserPermissionProjectIds.get(PermissionConstants.CASE_REVIEW_READ); if (CollectionUtils.isNotEmpty(reviewProjectIds)) { - searchReviewProjectIds = reviewProjectIds.stream().filter(t -> finalModuleMap.get(t).contains(FUNCTIONAL_CASE)).collect(Collectors.toSet()); + searchReviewProjectIds = reviewProjectIds.stream().filter(t -> finalModuleMap.get(t).contains(FUNCTIONAL_CASE)).collect(Collectors.toCollection(LinkedHashSet::new)); } //检查是否开启接口模块 Set apiProjectIds = hasUserPermissionProjectIds.get(PermissionConstants.PROJECT_API_DEFINITION_READ); if (CollectionUtils.isNotEmpty(apiProjectIds)) { - searchApiProjectIds = apiProjectIds.stream().filter(t -> finalModuleMap.get(t).contains(API_TEST)).collect(Collectors.toSet()); + searchApiProjectIds = apiProjectIds.stream().filter(t -> finalModuleMap.get(t).contains(API_TEST)).collect(Collectors.toCollection(LinkedHashSet::new)); } Set apiCaseProjectIds = hasUserPermissionProjectIds.get(PermissionConstants.PROJECT_API_DEFINITION_CASE_READ); if (CollectionUtils.isNotEmpty(apiCaseProjectIds)) { - searchApiCaseProjectIds = apiCaseProjectIds.stream().filter(t -> finalModuleMap.get(t).contains(API_TEST)).collect(Collectors.toSet()); + searchApiCaseProjectIds = apiCaseProjectIds.stream().filter(t -> finalModuleMap.get(t).contains(API_TEST)).collect(Collectors.toCollection(LinkedHashSet::new)); } Set scenarioProjectIds = hasUserPermissionProjectIds.get(PermissionConstants.PROJECT_API_SCENARIO_READ); if (CollectionUtils.isNotEmpty(scenarioProjectIds)) { - searchScenarioProjectIds = scenarioProjectIds.stream().filter(t -> finalModuleMap.get(t).contains(API_TEST)).collect(Collectors.toSet()); + searchScenarioProjectIds = scenarioProjectIds.stream().filter(t -> finalModuleMap.get(t).contains(API_TEST)).collect(Collectors.toCollection(LinkedHashSet::new)); } //检查是否开启测试计划模块 Set planProjectIds = hasUserPermissionProjectIds.get(PermissionConstants.TEST_PLAN_READ); if (CollectionUtils.isNotEmpty(planProjectIds)) { - searchPlanProjectIds = planProjectIds.stream().filter(t -> finalModuleMap.get(t).contains(TEST_PLAN)).collect(Collectors.toSet()); + searchPlanProjectIds = planProjectIds.stream().filter(t -> finalModuleMap.get(t).contains(TEST_PLAN)).collect(Collectors.toCollection(LinkedHashSet::new)); } //检查是否开启缺陷模块 Set bugProjectIds = hasUserPermissionProjectIds.get(PermissionConstants.PROJECT_BUG_READ); if (CollectionUtils.isNotEmpty(bugProjectIds)) { - searchBugProjectIds = bugProjectIds.stream().filter(t -> finalModuleMap.get(t).contains(BUG)).collect(Collectors.toSet()); + searchBugProjectIds = bugProjectIds.stream().filter(t -> finalModuleMap.get(t).contains(BUG)).collect(Collectors.toCollection(LinkedHashSet::new)); } } else { //查出这些项目分别有模块的 - searchCaseProjectIds = projectSet.stream().filter(t -> finalModuleMap.get(t).contains(FUNCTIONAL_CASE)).collect(Collectors.toSet()); - searchReviewProjectIds = projectSet.stream().filter(t -> finalModuleMap.get(t).contains(FUNCTIONAL_CASE)).collect(Collectors.toSet()); - searchApiProjectIds = projectSet.stream().filter(t -> finalModuleMap.get(t).contains(API_TEST)).collect(Collectors.toSet()); - searchApiCaseProjectIds = projectSet.stream().filter(t -> finalModuleMap.get(t).contains(API_TEST)).collect(Collectors.toSet()); - searchScenarioProjectIds = projectSet.stream().filter(t -> finalModuleMap.get(t).contains(API_TEST)).collect(Collectors.toSet()); - searchPlanProjectIds = projectSet.stream().filter(t -> finalModuleMap.get(t).contains(TEST_PLAN)).collect(Collectors.toSet()); - searchBugProjectIds = projectSet.stream().filter(t -> finalModuleMap.get(t).contains(BUG)).collect(Collectors.toSet()); + searchCaseProjectIds = projectSet.stream().filter(t -> finalModuleMap.get(t).contains(FUNCTIONAL_CASE)).collect(Collectors.toCollection(LinkedHashSet::new)); + searchReviewProjectIds = projectSet.stream().filter(t -> finalModuleMap.get(t).contains(FUNCTIONAL_CASE)).collect(Collectors.toCollection(LinkedHashSet::new)); + searchApiProjectIds = projectSet.stream().filter(t -> finalModuleMap.get(t).contains(API_TEST)).collect(Collectors.toCollection(LinkedHashSet::new)); + searchApiCaseProjectIds = projectSet.stream().filter(t -> finalModuleMap.get(t).contains(API_TEST)).collect(Collectors.toCollection(LinkedHashSet::new)); + searchScenarioProjectIds = projectSet.stream().filter(t -> finalModuleMap.get(t).contains(API_TEST)).collect(Collectors.toCollection(LinkedHashSet::new)); + searchPlanProjectIds = projectSet.stream().filter(t -> finalModuleMap.get(t).contains(TEST_PLAN)).collect(Collectors.toCollection(LinkedHashSet::new)); + searchBugProjectIds = projectSet.stream().filter(t -> finalModuleMap.get(t).contains(BUG)).collect(Collectors.toCollection(LinkedHashSet::new)); } //如果value 为空,则没有权限或者没开启模块 hasModuleProjectIds.put(PermissionConstants.FUNCTIONAL_CASE_READ, searchCaseProjectIds); @@ -115,11 +115,11 @@ public class DashboardProjectService { */ public Map> getModuleProjectIds(List userProject) { Map moduleMap = userProject.stream().collect(Collectors.toMap(Project::getId, Project::getModuleSetting)); - Set projectIds = userProject.stream().map(Project::getId).collect(Collectors.toSet()); - Set searchCaseProjectIds = projectIds.stream().filter(t -> moduleMap.get(t).contains(FUNCTIONAL_CASE)).collect(Collectors.toSet()); - Set searchApiProjectIds = projectIds.stream().filter(t -> moduleMap.get(t).contains(API_TEST)).collect(Collectors.toSet()); - Set searchPlanProjectIds = projectIds.stream().filter(t -> moduleMap.get(t).contains(TEST_PLAN)).collect(Collectors.toSet()); - Set searchBugProjectIds = projectIds.stream().filter(t -> moduleMap.get(t).contains(BUG)).collect(Collectors.toSet()); + Set projectIds = userProject.stream().map(Project::getId).collect(Collectors.toCollection(LinkedHashSet::new)); + Set searchCaseProjectIds = projectIds.stream().filter(t -> moduleMap.get(t).contains(FUNCTIONAL_CASE)).collect(Collectors.toCollection(LinkedHashSet::new)); + Set searchApiProjectIds = projectIds.stream().filter(t -> moduleMap.get(t).contains(API_TEST)).collect(Collectors.toCollection(LinkedHashSet::new)); + Set searchPlanProjectIds = projectIds.stream().filter(t -> moduleMap.get(t).contains(TEST_PLAN)).collect(Collectors.toCollection(LinkedHashSet::new)); + Set searchBugProjectIds = projectIds.stream().filter(t -> moduleMap.get(t).contains(BUG)).collect(Collectors.toCollection(LinkedHashSet::new)); Map> hasModuleProjectIds = new HashMap<>(); hasModuleProjectIds.put(PermissionConstants.FUNCTIONAL_CASE_READ, searchCaseProjectIds); hasModuleProjectIds.put(PermissionConstants.CASE_REVIEW_READ, searchCaseProjectIds); diff --git a/backend/services/dashboard/src/main/java/io/metersphere/dashboard/service/DashboardService.java b/backend/services/dashboard/src/main/java/io/metersphere/dashboard/service/DashboardService.java index f0575f0f96..2a8ba6e4f8 100644 --- a/backend/services/dashboard/src/main/java/io/metersphere/dashboard/service/DashboardService.java +++ b/backend/services/dashboard/src/main/java/io/metersphere/dashboard/service/DashboardService.java @@ -495,6 +495,12 @@ public class DashboardService { checkHasPermissionProject(layoutDTO, hasReadProjectIds); if (StringUtils.equalsIgnoreCase(layoutDTO.getKey(), DashboardUserLayoutKeys.PROJECT_PLAN_VIEW.toString())) { setPlanId(layoutDTO); + if (StringUtils.isBlank(layoutDTO.getPlanId())) { + TestPlan latestPlanByProjectIds = extTestPlanMapper.getLatestPlanByProjectIds(hasReadProjectIds); + layoutDTO.setPlanId(latestPlanByProjectIds.getId()); + layoutDTO.setGroupId(latestPlanByProjectIds.getGroupId()); + layoutDTO.setProjectIds(List.of(latestPlanByProjectIds.getProjectId())); + } } } else if (StringUtils.equalsIgnoreCase(layoutDTO.getKey(), DashboardUserLayoutKeys.BUG_COUNT.toString()) || StringUtils.equalsIgnoreCase(layoutDTO.getKey(), DashboardUserLayoutKeys.CREATE_BUG_BY_ME.toString()) @@ -516,6 +522,9 @@ public class DashboardService { TestPlan latestPlan = extTestPlanMapper.getLatestPlan(layoutDTO.getProjectIds().getFirst()); if (latestPlan != null) { layoutDTO.setPlanId(latestPlan.getId()); + layoutDTO.setGroupId(layoutDTO.getGroupId()); + } else { + layoutDTO.setPlanId(null); } } } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/PermissionCheckService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/PermissionCheckService.java index bbf7e8b270..c7a57d19e8 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/PermissionCheckService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/PermissionCheckService.java @@ -9,6 +9,7 @@ import io.metersphere.sdk.util.JSON; import io.metersphere.system.domain.UserRole; import io.metersphere.system.domain.UserRolePermission; import io.metersphere.system.dto.user.UserDTO; +import io.metersphere.system.dto.user.UserRoleResourceDTO; import io.metersphere.system.service.UserLoginService; import jakarta.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; @@ -101,28 +102,26 @@ public class PermissionCheckService { UserDTO user = getUserDTO(userId); if (user == null) return new HashMap<>(); // 注意超级管理员包含所有权限,这里不予返回,请在方法外自行判断 - Map> permissionProjectIdMap = new HashMap<>(); - Map> projectPermissionMap = new HashMap<>(); - Map>rolePermissionMap = new HashMap<>(); + Map> permissionProjectIdMap = new LinkedHashMap<>(); + Map> projectPermissionMap = new LinkedHashMap<>(); + + Map>rolePermissionMap = user.getUserRolePermissions().stream().filter(t->StringUtils.equalsIgnoreCase(t.getUserRole().getType(), UserRoleType.PROJECT.name())).collect(Collectors.toMap(f->f.getUserRole().getId(), UserRoleResourceDTO::getUserRolePermissions)); - user.getUserRolePermissions().forEach(t->{ - if (StringUtils.equalsIgnoreCase(t.getUserRole().getType(), UserRoleType.PROJECT.name())) { - rolePermissionMap.put(t.getUserRole().getId(),t.getUserRolePermissions()); - } - }); user.getUserRoleRelations().forEach(ug -> { List userRolePermissions = rolePermissionMap.get(ug.getRoleId()); if (CollectionUtils.isNotEmpty(userRolePermissions) && projectIds.contains(ug.getSourceId())) { projectPermissionMap.put(ug.getSourceId(),userRolePermissions); } }); - projectPermissionMap.forEach((projectId, userRolePermissions)->{ + + for (String projectId : projectIds) { + List userRolePermissions = projectPermissionMap.get(projectId); for (UserRolePermission userRolePermission : userRolePermissions) { if (permissions.contains(userRolePermission.getPermissionId())) { - permissionProjectIdMap.computeIfAbsent(userRolePermission.getPermissionId(), key -> new HashSet<>()).add(projectId); + permissionProjectIdMap.computeIfAbsent(userRolePermission.getPermissionId(), key -> new LinkedHashSet<>()).add(projectId); } } - }); + } return permissionProjectIdMap; } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.java index 7b51694d27..228ade4b80 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.java @@ -71,7 +71,7 @@ public interface ExtTestPlanMapper { List selectRightfulIdsForExecute(@Param("ids") List ids); - List listHis(@Param("request")TestPlanExecuteHisPageRequest request); + List listHis(@Param("request") TestPlanExecuteHisPageRequest request); List selectGroupIdByKeyword(@Param("projectId") String projectId, @Param("keyword") String keyword); @@ -90,9 +90,10 @@ public interface ExtTestPlanMapper { /** * 获取项目下的计划关联缺陷 - * @param projectId 项目 - * @param type 计划类型 - * @param platform 缺陷平台集合 + * + * @param projectId 项目 + * @param type 计划类型 + * @param platform 缺陷平台集合 * @param statusList 缺陷状态 * @return List */ @@ -102,12 +103,14 @@ public interface ExtTestPlanMapper { /** * @param projectId 项目 - * 获取项目下计划组和计划的名称 + * 获取项目下计划组和计划的名称 */ List getGroupAndPlanInfo(@Param("projectId") String projectId); TestPlan getLatestPlan(@Param("projectId") String projectId); + TestPlan getLatestPlanByProjectIds(@Param("projectIds") Set projectIds); + List selectTestPlanConfigByTestPlanIds(@Param("testPlanIds") List testPlanIds); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.xml b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.xml index 6e0d74f63e..c43af68f3e 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.xml +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.xml @@ -929,6 +929,16 @@ where type = 'TEST_PLAN' and status='NOT_ARCHIVED' and project_id = #{projectId} order by create_time desc limit 1; + +