From 4dd71774302cbd62ad09c08bbab795c556efbab8 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Wed, 11 Oct 2023 10:19:02 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E9=A1=B9=E7=9B=AE=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E7=BC=BA=E9=99=B7=E5=91=BD=E5=90=8D&?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migration/3.0.0/dml/V3.0.0_11_1__data.sql | 4 +- .../sdk/constants/PermissionConstants.java | 4 +- .../sdk/constants/ProjectApplicationType.java | 6 +- .../resources/i18n/project_en_US.properties | 4 +- .../resources/i18n/project_zh_CN.properties | 4 +- .../resources/i18n/project_zh_TW.properties | 4 +- .../ProjectApplicationController.java | 47 +++++----- .../{IssueSyncJob.java => BugSyncJob.java} | 6 +- .../service/ProjectApplicationService.java | 55 ++++++------ .../project/utils/ModuleSortUtils.java | 22 +++++ .../src/main/resources/permission.json | 27 +----- .../ProjectApplicationControllerTests.java | 88 ++++++++++++------- 12 files changed, 150 insertions(+), 121 deletions(-) rename backend/services/project-management/src/main/java/io/metersphere/project/job/{IssueSyncJob.java => BugSyncJob.java} (70%) create mode 100644 backend/services/project-management/src/main/java/io/metersphere/project/utils/ModuleSortUtils.java diff --git a/backend/framework/domain/src/main/resources/migration/3.0.0/dml/V3.0.0_11_1__data.sql b/backend/framework/domain/src/main/resources/migration/3.0.0/dml/V3.0.0_11_1__data.sql index e19c6787a6..4c6a90f1cc 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.0/dml/V3.0.0_11_1__data.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.0/dml/V3.0.0_11_1__data.sql @@ -118,8 +118,8 @@ INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_API:UPDATE'); INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_CASE:READ'); INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_CASE:UPDATE'); -INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_ISSUE:READ'); -INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_ISSUE:UPDATE'); +INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_BUG:READ'); +INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_BUG:UPDATE'); INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_WORKSTATION:READ'); INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_APPLICATION_WORKSTATION:UPDATE'); INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_LOG:READ'); diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/PermissionConstants.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/PermissionConstants.java index 4e6799c514..f4b68669b4 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/PermissionConstants.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/PermissionConstants.java @@ -154,8 +154,8 @@ public class PermissionConstants { public static final String PROJECT_APPLICATION_API_UPDATE = "PROJECT_APPLICATION_API:UPDATE"; public static final String PROJECT_APPLICATION_CASE_READ = "PROJECT_APPLICATION_CASE:READ"; public static final String PROJECT_APPLICATION_CASE_UPDATE = "PROJECT_APPLICATION_CASE:UPDATE"; - public static final String PROJECT_APPLICATION_ISSUE_READ = "PROJECT_APPLICATION_ISSUE:READ"; - public static final String PROJECT_APPLICATION_ISSUE_UPDATE = "PROJECT_APPLICATION_ISSUE:UPDATE"; + public static final String PROJECT_APPLICATION_BUG_READ = "PROJECT_APPLICATION_BUG:READ"; + public static final String PROJECT_APPLICATION_BUG_UPDATE = "PROJECT_APPLICATION_BUG:UPDATE"; public static final String PROJECT_APPLICATION_WORKSTATION_READ = "PROJECT_APPLICATION_WORKSTATION:READ"; public static final String PROJECT_APPLICATION_WORKSTATION_UPDATE = "PROJECT_APPLICATION_WORKSTATION:UPDATE"; /*------ end: PROJECT_APPLICATION ------*/ diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ProjectApplicationType.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ProjectApplicationType.java index d89a03ce74..bdd995410b 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ProjectApplicationType.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/ProjectApplicationType.java @@ -62,13 +62,13 @@ public class ProjectApplicationType { //缺陷管理 - public enum ISSUE{ - ISSUE_SYNC + public enum BUG{ + BUG_SYNC } //缺陷管理-同步配置项 - public enum ISSUE_SYNC_CONFIG{ + public enum BUG_SYNC_CONFIG{ CRON_EXPRESSION, SYNC_ENABLE, MECHANISM, diff --git a/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties index b6a5347ccd..c38e186bd8 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties @@ -132,8 +132,8 @@ permission.project_application_api.read=API test read permission.project_application_api.update=API test update permission.project_application_case.read=Case read permission.project_application_case.update=Case update -permission.project_application_issue.read=Issue read -permission.project_application_issue.update=Issue update +permission.project_application_bug.read=Bug read +permission.project_application_bug.update=Bug update permission.project_application_workstation.read=Workstation read permission.project_application_workstation.update=Workstation update permission.project_base_info.name=Project base info diff --git a/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties index b628c6dc41..d604c7b60a 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties @@ -132,8 +132,8 @@ permission.project_application_api.read=接口测试-查询 permission.project_application_api.update=接口测试-编辑 permission.project_application_case.read=用例管理-查询 permission.project_application_case.update=用例管理-编辑 -permission.project_application_issue.read=缺陷管理-查询 -permission.project_application_issue.update=缺陷管理-编辑 +permission.project_application_bug.read=缺陷管理-查询 +permission.project_application_bug.update=缺陷管理-编辑 permission.project_application_workstation.read=工作台-查询 permission.project_application_workstation.update=工作台-编辑 permission.project_base_info.name=基本信息 diff --git a/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties index f9009c3b51..243c656c46 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties @@ -132,8 +132,8 @@ permission.project_application_api.read=接口測試-查詢 permission.project_application_api.update=接口測試-編輯 permission.project_application_case.read=用例管理-查詢 permission.project_application_case.update=用例管理-編輯 -permission.project_application_issue.read=缺陷管理-查詢 -permission.project_application_issue.update=缺陷管理-編輯 +permission.project_application_bug.read=缺陷管理-查詢 +permission.project_application_bug.update=缺陷管理-編輯 permission.project_application_workstation.read=工作台-查詢 permission.project_application_workstation.update=工作台-編輯 permission.project_base_info.name=基本信息 diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java index 9c0b8f5eeb..3f73aadee2 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/controller/ProjectApplicationController.java @@ -169,6 +169,7 @@ public class ProjectApplicationController { @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_CASE_READ) public List getCase(@Validated @RequestBody ProjectApplicationRequest request) { List types = Arrays.asList(ProjectApplicationType.CASE.values()).stream().map(ProjectApplicationType.CASE::name).collect(Collectors.toList()); + types.add(ProjectApplicationType.CASE_RELATED_CONFIG.CASE_ENABLE.name()); return projectApplicationService.get(request, types); } @@ -199,7 +200,7 @@ public class ProjectApplicationController { @GetMapping("/case/related/info/{projectId}") @Operation(summary = "用例管理-获取关联需求信息") - @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_ISSUE_READ) + @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_CASE_READ) public Map getRelatedConfigInfo(@PathVariable("projectId") String projectId) { return projectApplicationService.getRelatedConfigInfo(projectId); } @@ -230,52 +231,52 @@ public class ProjectApplicationController { * ==========缺陷管理========== */ - @PostMapping("/update/issue") + @PostMapping("/update/bug") @Operation(summary = "缺陷管理-配置") - @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_ISSUE_UPDATE) + @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_BUG_UPDATE) @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateWorkstationLog(#applications)", msClass = ProjectApplicationService.class) - public void updateIssue(@Validated({Updated.class}) @RequestBody List applications) { + public void updateBug(@Validated({Updated.class}) @RequestBody List applications) { projectApplicationService.update(applications, SessionUtils.getUserId()); } - @PostMapping("/issue") + @PostMapping("/bug") @Operation(summary = "缺陷管理-获取配置") - @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_ISSUE_READ) - public List getIssue(@Validated @RequestBody ProjectApplicationRequest request) { - List types = Arrays.asList(ProjectApplicationType.WORKSTATION.values()).stream().map(ProjectApplicationType.WORKSTATION::name).collect(Collectors.toList()); + @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_BUG_READ) + public List getBug(@Validated @RequestBody ProjectApplicationRequest request) { + List types = Arrays.asList(ProjectApplicationType.BUG_SYNC_CONFIG.SYNC_ENABLE.name()); return projectApplicationService.get(request, types); } - @GetMapping("/issue/platform/{organizationId}") + @GetMapping("/bug/platform/{organizationId}") @Operation(summary = "缺陷管理-获取平台下拉框列表") - @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_ISSUE_READ) - public List getIssuePlatformOptions(@PathVariable String organizationId) { + @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_BUG_READ) + public List getBugPlatformOptions(@PathVariable String organizationId) { return projectApplicationService.getPlatformOptions(organizationId); } - @GetMapping("/issue/platform/info/{pluginId}") + @GetMapping("/bug/platform/info/{pluginId}") @Operation(summary = "缺陷管理-选择平台获取平台信息") - @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_ISSUE_READ) - public Object getIssuePlatformInfo(@PathVariable String pluginId) { + @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_BUG_READ) + public Object getBugPlatformInfo(@PathVariable String pluginId) { return projectApplicationService.getPluginScript(pluginId); } - @PostMapping("/update/issue/sync/{projectId}") + @PostMapping("/update/bug/sync/{projectId}") @Operation(summary = "缺陷管理-同步缺陷配置") - @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_ISSUE_UPDATE) - @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateIssueSyncLog(#projectId, #configs)", msClass = ProjectApplicationService.class) - public void syncIssueConfig(@PathVariable("projectId") String projectId, @RequestBody Map configs) { - projectApplicationService.syncIssueConfig(projectId, configs, SessionUtils.getUserId()); + @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_BUG_UPDATE) + @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateBugSyncLog(#projectId, #configs)", msClass = ProjectApplicationService.class) + public void syncBugConfig(@PathVariable("projectId") String projectId, @RequestBody Map configs) { + projectApplicationService.syncBugConfig(projectId, configs, SessionUtils.getUserId()); } - @GetMapping("/issue/sync/info/{projectId}") + @GetMapping("/bug/sync/info/{projectId}") @Operation(summary = "缺陷管理-获取同步缺陷信息") - @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_ISSUE_READ) - public Map getIssueConfigInfo(@PathVariable("projectId") String projectId) { - return projectApplicationService.getIssueConfigInfo(projectId); + @RequiresPermissions(PermissionConstants.PROJECT_APPLICATION_BUG_READ) + public Map getBugConfigInfo(@PathVariable("projectId") String projectId) { + return projectApplicationService.getBugConfigInfo(projectId); } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/job/IssueSyncJob.java b/backend/services/project-management/src/main/java/io/metersphere/project/job/BugSyncJob.java similarity index 70% rename from backend/services/project-management/src/main/java/io/metersphere/project/job/IssueSyncJob.java rename to backend/services/project-management/src/main/java/io/metersphere/project/job/BugSyncJob.java index 5856002834..74dbce12d3 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/job/IssueSyncJob.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/job/BugSyncJob.java @@ -5,17 +5,17 @@ import org.quartz.JobExecutionContext; import org.quartz.JobKey; import org.quartz.TriggerKey; -public class IssueSyncJob extends BaseScheduleJob { +public class BugSyncJob extends BaseScheduleJob { @Override protected void businessExecute(JobExecutionContext context) { //TODO 定时任务执行 同步issue } public static JobKey getJobKey(String projectId) { - return new JobKey(projectId, IssueSyncJob.class.getName()); + return new JobKey(projectId, BugSyncJob.class.getName()); } public static TriggerKey getTriggerKey(String projectId) { - return new TriggerKey(projectId, IssueSyncJob.class.getName()); + return new TriggerKey(projectId, BugSyncJob.class.getName()); } } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java index 6385e762d5..15898d4afa 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectApplicationService.java @@ -6,11 +6,12 @@ import io.metersphere.project.domain.ProjectApplication; import io.metersphere.project.domain.ProjectApplicationExample; import io.metersphere.project.dto.ModuleDTO; import io.metersphere.project.job.CleanUpReportJob; -import io.metersphere.project.job.IssueSyncJob; +import io.metersphere.project.job.BugSyncJob; import io.metersphere.project.mapper.ExtProjectMapper; import io.metersphere.project.mapper.ExtProjectUserRoleMapper; import io.metersphere.project.mapper.ProjectApplicationMapper; import io.metersphere.project.request.ProjectApplicationRequest; +import io.metersphere.project.utils.ModuleSortUtils; import io.metersphere.sdk.constants.OperationLogConstants; import io.metersphere.sdk.constants.ProjectApplicationType; import io.metersphere.sdk.constants.ScheduleType; @@ -209,41 +210,41 @@ public class ProjectApplicationService { * @param projectId * @param configs */ - public void syncIssueConfig(String projectId, Map configs, String currentUser) { - List issueSyncConfigs = configs.entrySet().stream().map(config -> new ProjectApplication(projectId, ProjectApplicationType.ISSUE.ISSUE_SYNC.name() + "_" + config.getKey().toUpperCase(), config.getValue())).collect(Collectors.toList()); + public void syncBugConfig(String projectId, Map configs, String currentUser) { + List bugSyncConfigs = configs.entrySet().stream().map(config -> new ProjectApplication(projectId, ProjectApplicationType.BUG.BUG_SYNC.name() + "_" + config.getKey().toUpperCase(), config.getValue())).collect(Collectors.toList()); //处理同步缺陷定时任务配置 - doSaveOrUpdateSchedule(issueSyncConfigs, projectId, currentUser); + doSaveOrUpdateSchedule(bugSyncConfigs, projectId, currentUser); ProjectApplicationExample example = new ProjectApplicationExample(); - example.createCriteria().andProjectIdEqualTo(projectId).andTypeLike(ProjectApplicationType.ISSUE.ISSUE_SYNC.name() + "%"); + example.createCriteria().andProjectIdEqualTo(projectId).andTypeLike(ProjectApplicationType.BUG.BUG_SYNC.name() + "%"); if (projectApplicationMapper.countByExample(example) > 0) { example.clear(); - example.createCriteria().andTypeLike(ProjectApplicationType.ISSUE.ISSUE_SYNC.name() + "%"); + example.createCriteria().andTypeLike(ProjectApplicationType.BUG.BUG_SYNC.name() + "%"); projectApplicationMapper.deleteByExample(example); - projectApplicationMapper.batchInsert(issueSyncConfigs); + projectApplicationMapper.batchInsert(bugSyncConfigs); } else { - projectApplicationMapper.batchInsert(issueSyncConfigs); + projectApplicationMapper.batchInsert(bugSyncConfigs); } } - private void doSaveOrUpdateSchedule(List issueSyncConfigs, String projectId, String currentUser) { - List syncCron = issueSyncConfigs.stream().filter(config -> config.getType().equals(ProjectApplicationType.ISSUE.ISSUE_SYNC.name() + "_" + ProjectApplicationType.ISSUE_SYNC_CONFIG.CRON_EXPRESSION.name())).collect(Collectors.toList()); - List syncEnable = issueSyncConfigs.stream().filter(config -> config.getType().equals(ProjectApplicationType.ISSUE.ISSUE_SYNC.name() + "_" + ProjectApplicationType.ISSUE_SYNC_CONFIG.SYNC_ENABLE.name())).collect(Collectors.toList()); + private void doSaveOrUpdateSchedule(List bugSyncConfigs, String projectId, String currentUser) { + List syncCron = bugSyncConfigs.stream().filter(config -> config.getType().equals(ProjectApplicationType.BUG.BUG_SYNC.name() + "_" + ProjectApplicationType.BUG_SYNC_CONFIG.CRON_EXPRESSION.name())).collect(Collectors.toList()); + List syncEnable = bugSyncConfigs.stream().filter(config -> config.getType().equals(ProjectApplicationType.BUG.BUG_SYNC.name() + "_" + ProjectApplicationType.BUG_SYNC_CONFIG.SYNC_ENABLE.name())).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(syncCron)) { Boolean enable = Boolean.valueOf(syncEnable.get(0).getTypeValue()); String typeValue = syncCron.get(0).getTypeValue(); - Schedule schedule = scheduleService.getScheduleByResource(projectId, IssueSyncJob.class.getName()); + Schedule schedule = scheduleService.getScheduleByResource(projectId, BugSyncJob.class.getName()); Optional optional = Optional.ofNullable(schedule); optional.ifPresentOrElse(s -> { s.setEnable(enable); s.setValue(typeValue); scheduleService.editSchedule(s); scheduleService.addOrUpdateCronJob(s, - IssueSyncJob.getJobKey(projectId), - IssueSyncJob.getTriggerKey(projectId), - IssueSyncJob.class); + BugSyncJob.getJobKey(projectId), + BugSyncJob.getTriggerKey(projectId), + BugSyncJob.class); }, () -> { Schedule request = new Schedule(); - request.setName("Issue Sync Job"); + request.setName("Bug Sync Job"); request.setResourceId(projectId); request.setKey(projectId); request.setProjectId(projectId); @@ -252,12 +253,12 @@ public class ProjectApplicationService { request.setType(ScheduleType.CRON.name()); // 每天凌晨2点执行清理任务 request.setValue(typeValue); - request.setJob(IssueSyncJob.class.getName()); + request.setJob(BugSyncJob.class.getName()); scheduleService.addSchedule(request); scheduleService.addOrUpdateCronJob(request, - IssueSyncJob.getJobKey(projectId), - IssueSyncJob.getTriggerKey(projectId), - IssueSyncJob.class); + BugSyncJob.getJobKey(projectId), + BugSyncJob.getTriggerKey(projectId), + BugSyncJob.class); }); } } @@ -269,14 +270,14 @@ public class ProjectApplicationService { * @param projectId * @return */ - public Map getIssueConfigInfo(String projectId) { + public Map getBugConfigInfo(String projectId) { ProjectApplicationExample example = new ProjectApplicationExample(); - example.createCriteria().andProjectIdEqualTo(projectId).andTypeLike(ProjectApplicationType.ISSUE.ISSUE_SYNC.name() + "_%"); + example.createCriteria().andProjectIdEqualTo(projectId).andTypeLike(ProjectApplicationType.BUG.BUG_SYNC.name() + "_%"); List list = projectApplicationMapper.selectByExample(example); Map collect = new HashMap<>(); if (CollectionUtils.isNotEmpty(list)) { list.stream().forEach(config -> { - collect.put(config.getType().replace(ProjectApplicationType.ISSUE.ISSUE_SYNC.name() + "_", "").toLowerCase(), config.getTypeValue()); + collect.put(config.getType().replace(ProjectApplicationType.BUG.BUG_SYNC.name() + "_", "").toLowerCase(), config.getTypeValue()); }); } return collect; @@ -373,8 +374,8 @@ public class ProjectApplicationService { * @param configs * @return */ - public LogDTO updateIssueSyncLog(String projectId, Map configs) { - Map originConfig = getIssueConfigInfo(projectId); + public LogDTO updateBugSyncLog(String projectId, Map configs) { + Map originConfig = getBugConfigInfo(projectId); LogDTO dto = new LogDTO( projectId, "", @@ -435,6 +436,10 @@ public class ProjectApplicationService { } }); moduleDTOList = moduleMap.entrySet().stream().map(entry -> new ModuleDTO(entry.getKey(), entry.getValue())).collect(Collectors.toList()); + Map module = ModuleSortUtils.getHashMap(); + if (CollectionUtils.isNotEmpty(moduleDTOList)) { + moduleDTOList.sort((o1, o2) -> module.getOrDefault(o1.getModule(), Integer.MAX_VALUE) - module.getOrDefault(o2.getModule(), Integer.MAX_VALUE)); + } } return moduleDTOList; } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/utils/ModuleSortUtils.java b/backend/services/project-management/src/main/java/io/metersphere/project/utils/ModuleSortUtils.java new file mode 100644 index 0000000000..202bc8be2e --- /dev/null +++ b/backend/services/project-management/src/main/java/io/metersphere/project/utils/ModuleSortUtils.java @@ -0,0 +1,22 @@ +package io.metersphere.project.utils; + +import java.util.HashMap; +import java.util.Map; + +public class ModuleSortUtils { + + public static Map hashMap = new HashMap<>(7); + + public static Map getHashMap() { + hashMap.put("workstation", 1); + hashMap.put("testPlan", 2); + hashMap.put("bugManagement", 3); + hashMap.put("caseManagement", 4); + hashMap.put("apiTest", 5); + hashMap.put("uiTest", 6); + hashMap.put("loadTest", 7); + return hashMap; + } + + +} diff --git a/backend/services/project-management/src/main/resources/permission.json b/backend/services/project-management/src/main/resources/permission.json index b1cf88963d..040544d9d7 100644 --- a/backend/services/project-management/src/main/resources/permission.json +++ b/backend/services/project-management/src/main/resources/permission.json @@ -159,25 +159,6 @@ } ] }, - { - "id": "PROJECT_FAKE_ERROR", - "name": "permission.project_fake_error.name", - "license": true, - "permissions": [ - { - "id": "PROJECT_FAKE_ERROR:READ" - }, - { - "id": "PROJECT_FAKE_ERROR:READ+ADD" - }, - { - "id": "PROJECT_FAKE_ERROR:READ+UPDATE" - }, - { - "id": "PROJECT_FAKE_ERROR:READ+DELETE" - } - ] - }, { "id": "PROJECT_APPLICATION", "name": "permission.project_application.name", @@ -224,12 +205,12 @@ "name": "permission.project_application_case.update" }, { - "id": "PROJECT_APPLICATION_ISSUE:READ", - "name": "permission.project_application_issue.read" + "id": "PROJECT_APPLICATION_BUG:READ", + "name": "permission.project_application_bug.read" }, { - "id": "PROJECT_APPLICATION_ISSUE:UPDATE", - "name": "permission.project_application_issue.update" + "id": "PROJECT_APPLICATION_BUG:UPDATE", + "name": "permission.project_application_bug.update" }, { "id": "PROJECT_APPLICATION_WORKSTATION:READ", diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java index 303ec0ef5f..21a48a5c15 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectApplicationControllerTests.java @@ -16,6 +16,9 @@ import jakarta.annotation.Resource; import lombok.Getter; import lombok.Setter; import org.junit.jupiter.api.*; +import org.mockserver.client.MockServerClient; +import org.mockserver.model.Header; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.mock.web.MockMultipartFile; @@ -30,6 +33,8 @@ import java.util.*; import static io.metersphere.sdk.constants.InternalUserRole.ADMIN; import static io.metersphere.system.controller.handler.result.MsHttpResultCode.NOT_FOUND; +import static org.mockserver.model.HttpRequest.request; +import static org.mockserver.model.HttpResponse.response; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -407,33 +412,33 @@ public class ProjectApplicationControllerTests extends BaseTest { /** * ==========缺陷管理 start========== */ - public static final String ISSUE_UPDATE_URL = "/project/application/update/issue"; - public static final String GET_ISSUE_URL = "/project/application/issue"; - public static final String GET_ISSUE_PLATFORM_URL = "/project/application/issue/platform"; + public static final String BUG_UPDATE_URL = "/project/application/update/bug"; + public static final String GET_BUG_URL = "/project/application/bug"; + public static final String GET_BUG_PLATFORM_URL = "/project/application/bug/platform"; - public static final String GET_ISSUE_PLATFORM_INFO_URL = "/project/application/issue/platform/info"; + public static final String GET_BUG_PLATFORM_INFO_URL = "/project/application/bug/platform/info"; //工作台 @Test @Order(29) - public void testIssue() throws Exception { - List request = creatRequest(Arrays.asList(ProjectApplicationType.ISSUE.ISSUE_SYNC.name()), "true"); - this.requestPost(ISSUE_UPDATE_URL, request); + public void testBug() throws Exception { + List request = creatRequest(Arrays.asList(ProjectApplicationType.BUG.BUG_SYNC.name()), "true"); + this.requestPost(BUG_UPDATE_URL, request); } @Test @Order(30) - public void testGetIssue() throws Exception { - ProjectApplicationRequest request = this.getRequest("ISSUE"); - this.requestPostWithOkAndReturn(GET_ISSUE_URL, request); + public void testGetBug() throws Exception { + ProjectApplicationRequest request = this.getRequest("BUG"); + this.requestPostWithOkAndReturn(GET_BUG_URL, request); } //缺陷管理 - 获取平台下拉列表 @Test @Order(31) - public void testGetIssuePlatform() throws Exception { - this.requestGetWithOkAndReturn(GET_ISSUE_PLATFORM_URL + "/100002"); - MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_ISSUE_PLATFORM_URL + "/100001"); + public void testGetBugPlatform() throws Exception { + this.requestGetWithOkAndReturn(GET_BUG_PLATFORM_URL + "/100002"); + MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_BUG_PLATFORM_URL + "/100001"); // 获取返回值 String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); @@ -445,8 +450,8 @@ public class ProjectApplicationControllerTests extends BaseTest { //缺陷管理 - 获取平台信息 @Test @Order(32) - public void testGetIssuePlatformInfo() throws Exception { - MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_ISSUE_PLATFORM_INFO_URL + "/" + plugin.getId()); + public void testGetBugPlatformInfo() throws Exception { + MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_BUG_PLATFORM_INFO_URL + "/" + plugin.getId()); // 获取返回值 String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); @@ -495,31 +500,28 @@ public class ProjectApplicationControllerTests extends BaseTest { } - public static final String UPDATE_ISSUE_CONFIG_URL = "/project/application/update/issue/sync"; - public static final String GET_ISSUE_CONFIG_INFO_URL = "/project/application/issue/sync/info"; + public static final String UPDATE_BUG_CONFIG_URL = "/project/application/update/bug/sync"; + public static final String GET_BUG_CONFIG_INFO_URL = "/project/application/bug/sync/info"; @Test @Order(34) - public void testIssueConfig() throws Exception { - Map configs = mockTestData(); - MvcResult mvcResult = this.requestPostWithOkAndReturn(UPDATE_ISSUE_CONFIG_URL + "/default-project-2", configs); + public void testBugConfig() throws Exception { + Map congifs = mockTestData(); + MvcResult mvcResult = this.requestPostWithOkAndReturn(UPDATE_BUG_CONFIG_URL + "/default-project-2", congifs); // 获取返回值 String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); // 返回请求正常 Assertions.assertNotNull(resultHolder); - - //更新 - configs.put("jiraKey", "222"); - MvcResult updateResult = this.requestPostWithOkAndReturn(UPDATE_ISSUE_CONFIG_URL + "/default-project-2", configs); + congifs.put("jiraKey", "222"); + MvcResult updateResult = this.requestPostWithOkAndReturn(UPDATE_BUG_CONFIG_URL + "/default-project-2", congifs); // 获取返回值 String updateData = updateResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder updateResultHolder = JSON.parseObject(updateData, ResultHolder.class); // 返回请求正常 Assertions.assertNotNull(updateResultHolder); - - configs.remove("CRON_EXPRESSION"); - this.requestPostWithOkAndReturn(UPDATE_ISSUE_CONFIG_URL + "/default-project-2", configs); + congifs.remove("CRON_EXPRESSION"); + this.requestPostWithOkAndReturn(UPDATE_BUG_CONFIG_URL + "/default-project-2", congifs); } private Map mockTestData() { @@ -536,8 +538,8 @@ public class ProjectApplicationControllerTests extends BaseTest { @Test @Order(35) - public void testIssueConfigInfo() throws Exception { - MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_ISSUE_CONFIG_INFO_URL + "/default-project-2"); + public void testBugConfigInfo() throws Exception { + MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_BUG_CONFIG_INFO_URL + "/default-project-2"); // 获取返回值 String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); @@ -562,7 +564,7 @@ public class ProjectApplicationControllerTests extends BaseTest { //更新 List request = creatRequest(Arrays.asList("bugManagement"), "false"); request.get(0).setProjectId("100001100001"); - this.requestPost(ISSUE_UPDATE_URL, request); + this.requestPost(BUG_UPDATE_URL, request); MvcResult updateMvcResult = this.requestGetWithOkAndReturn(GET_MODULE_SETTING_URL + "/100001100001"); // 获取返回值 String updateReturnData = updateMvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); @@ -620,7 +622,12 @@ public class ProjectApplicationControllerTests extends BaseTest { public static final String CHECK_PROJECT_KEY_URL = "/project/application/validate"; - + @Resource + private MockServerClient mockServerClient; + @Value("${embedded.mockserver.host}") + private String mockServerHost; + @Value("${embedded.mockserver.port}") + private int mockServerHostPort; @Test @Order(39) public void testCheckProjectKey() throws Exception { @@ -630,6 +637,7 @@ public class ProjectApplicationControllerTests extends BaseTest { configs.put("jiraStoryTypeId", "10010"); assertErrorCode(this.requestPost(CHECK_PROJECT_KEY_URL + "/" + plugin.getId(), configs), NOT_FOUND); JiraIntegrationConfig integrationConfig = new JiraIntegrationConfig(); + integrationConfig.setAddress(String.format("http://%s:%s", mockServerHost, mockServerHostPort)); Map integrationConfigMap = JSON.parseMap(JSON.toJSONString(integrationConfig)); ServiceIntegrationUpdateRequest request = new ServiceIntegrationUpdateRequest(); request.setEnable(true); @@ -637,13 +645,25 @@ public class ProjectApplicationControllerTests extends BaseTest { request.setConfiguration(integrationConfigMap); request.setOrganizationId("100001100001"); this.requestPostWithOkAndReturn("/service/integration/add", request); - // TODO 缺少有效数据 - /*MvcResult mvcResult = this.requestPostWithOkAndReturn(CHECK_PROJECT_KEY_URL + "/" + plugin.getId(), configs); + mockServerClient + .when( + request() + .withMethod("GET") + .withPath("/rest/api/2/project/Test")) + .respond( + response() + .withStatusCode(200) + .withHeaders( + new Header("Content-Type", "application/json; charset=utf-8"), + new Header("Cache-Control", "public, max-age=86400")) + .withBody("{\"id\":\"123456\",\"name\":\"test\"}") + ); + MvcResult mvcResult = this.requestPostWithOkAndReturn(CHECK_PROJECT_KEY_URL + "/" + plugin.getId(), configs); // 获取返回值 String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); // 返回请求正常 - Assertions.assertNotNull(resultHolder);*/ + Assertions.assertNotNull(resultHolder); } @Getter