From ca40ec1332a7982be2d489d4400a604947ea0755 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 22 Dec 2022 10:20:24 +0800 Subject: [PATCH 1/5] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B?= =?UTF-8?q?=E8=AF=95):=20=E4=BC=98=E5=8C=96=E6=8F=92=E4=BB=B6=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E8=BF=87=E6=BB=A4=E6=8E=89=E9=9D=9Eapi=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/service/ApiJMeterFileService.java | 12 ++++++------ .../java/io/metersphere/service/PluginService.java | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java b/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java index 9c862ad4c4..23069e8d8f 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java @@ -23,6 +23,7 @@ import io.metersphere.commons.utils.GenerateHashTreeUtil; import io.metersphere.utils.LoggerUtil; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.jorphan.collections.HashTree; import org.springframework.stereotype.Service; @@ -204,12 +205,11 @@ public class ApiJMeterFileService { new TreeSet<>(Comparator.comparing(Plugin::getPluginId))), ArrayList::new)); plugins.forEach(item -> { File file = new File(item.getSourcePath()); - if (file.isDirectory() && !item.getSourcePath().endsWith("/")) { - file = new File(item.getSourcePath() + "/"); - } - byte[] fileByte = FileUtils.fileToByte(file); - if (fileByte != null) { - jarFiles.put(file.getName(), fileByte); + if (file.exists() && !file.isDirectory()) { + byte[] fileByte = FileUtils.fileToByte(file); + if (ArrayUtils.isNotEmpty(fileByte)) { + jarFiles.put(file.getName(), fileByte); + } } }); diff --git a/api-test/backend/src/main/java/io/metersphere/service/PluginService.java b/api-test/backend/src/main/java/io/metersphere/service/PluginService.java index 777e09fdad..15cdad6b47 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/PluginService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/PluginService.java @@ -89,6 +89,7 @@ public class PluginService { List lists = new LinkedList<>(); try { PluginExample example = new PluginExample(); + example.createCriteria().andScenarioEqualTo(PluginScenario.api.name()); if (StringUtils.isNotBlank(name)) { name = "%" + name + "%"; example.createCriteria().andNameLike(name); @@ -158,6 +159,7 @@ public class PluginService { public List list() { PluginExample example = new PluginExample(); + example.createCriteria().andScenarioEqualTo(PluginScenario.api.name()); List plugins = pluginMapper.selectByExample(example); return plugins; } From e28b8edeff56fb62153c327c5b801254c88e9fdf Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Thu, 22 Dec 2022 10:52:08 +0800 Subject: [PATCH 2/5] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=90=8E=E4=B8=8D=E6=98=BE=E7=A4=BA=E8=80=97?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1021148 --user=宋天阳 【测试跟踪】测试计划执行后不显示运行耗时 https://www.tapd.cn/55049933/s/1318385 --- .../plan/service/TestPlanReportService.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index d7ba20b6af..a2465d4503 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -504,9 +504,10 @@ public class TestPlanReportService { TestPlanReportContentWithBLOBs content = null; try { HttpHeaderUtils.runAsUser(testPlanReport.getCreator()); - testPlanReport.setStatus(status); - content = this.initTestPlanContent(testPlanReport, status); + boolean isRerunningTestPlan = BooleanUtils.isTrue(StringUtils.equalsIgnoreCase(testPlanReport.getStatus(), APITestStatus.Rerunning.name())); + content = this.initTestPlanContent(testPlanReport, status, isRerunningTestPlan); } catch (Exception e) { + testPlanReport.setStatus(status); LogUtil.error("统计测试计划状态失败!", e); } finally { HttpHeaderUtils.clearUser(); @@ -518,22 +519,17 @@ public class TestPlanReportService { return testPlanReport; } - private TestPlanReportContentWithBLOBs initTestPlanContent(TestPlanReport testPlanReport, String status) throws Exception { + private TestPlanReportContentWithBLOBs initTestPlanContent(TestPlanReport testPlanReport, String status, boolean isRerunningTestPlan) throws Exception { + testPlanReport.setStatus(status); TestPlanReportContentWithBLOBs content = null; //初始化测试计划包含组件信息 int[] componentIndexArr = new int[]{1, 3, 4}; testPlanReport.setComponents(JSON.toJSONString(componentIndexArr)); - //如果测试案例没有未结束的功能用例,则更新最后结束日期。 - TestPlanTestCaseMapper testPlanTestCaseMapper = CommonBeanFactory.getBean(TestPlanTestCaseMapper.class); - TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample(); - testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(testPlanReport.getTestPlanId()).andStatusNotEqualTo("Prepare"); long endTime = System.currentTimeMillis(); - long testCaseCount = testPlanTestCaseMapper.countByExample(testPlanTestCaseExample); - boolean updateTestPlanTime = testCaseCount > 0; - if (updateTestPlanTime && !StringUtils.equalsAnyIgnoreCase(testPlanReport.getStatus(), APITestStatus.Rerunning.name())) { - testPlanReport.setEndTime(endTime); - testPlanReport.setUpdateTime(endTime); - } + //原逻辑中要判断包含测试计划功能用例时才会赋予结束时间。执行测试计划产生的测试报告,它的结束时间感觉没有这种判断必要。 + testPlanReport.setEndTime(endTime); + testPlanReport.setUpdateTime(endTime); + TestPlanReportContentExample contentExample = new TestPlanReportContentExample(); contentExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReport.getTestPlanId()); List contents = testPlanReportContentMapper.selectByExampleWithBLOBs(contentExample); @@ -550,8 +546,8 @@ public class TestPlanReportService { testPlanService.checkStatus(testPlanReport.getTestPlanId()); } if (content != null) { - //更新content表对结束日期 - if (!StringUtils.equalsAnyIgnoreCase(testPlanReport.getStatus(), APITestStatus.Rerunning.name())) { + //更新content表对结束日期 重跑的测试计划报告不用更新 + if (!isRerunningTestPlan) { content.setStartTime(testPlanReport.getStartTime()); content.setEndTime(endTime); } From 1083dd32f55b05930529b4401276dff064efc84b Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Thu, 22 Dec 2022 11:54:16 +0800 Subject: [PATCH 3/5] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E9=87=8D=E5=A4=8D=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E6=A8=A1=E5=9D=97=E4=BA=A7=E7=94=9F=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=8E=A5=E5=8F=A3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1021143--user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001021143 --- .../definition/ApiDefinitionImportUtilService.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionImportUtilService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionImportUtilService.java index db1f66375a..d09f7b46ec 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionImportUtilService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionImportUtilService.java @@ -24,7 +24,6 @@ import io.metersphere.service.BaseProjectApplicationService; import io.metersphere.service.MockConfigService; import io.metersphere.service.ServiceUtils; import io.metersphere.service.ext.ExtApiScheduleService; -import io.metersphere.xpack.api.service.ApiDefinitionSyncService; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -322,16 +321,11 @@ public class ApiDefinitionImportUtilService { if (fullCoverage) { removeHttpChooseModuleRepeat(optionData, chooseModulePath); // optionData = singleOptionData; - optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName().concat(t.getMethod()).concat(t.getPath()).concat(chooseModulePath), api -> api)); - } else { - getChooseModuleUrlRepeatOptionMap(optionData, optionMap, chooseModulePath); + // optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName().concat(t.getMethod()).concat(t.getPath()).concat(chooseModulePath), api -> api)); } - repeatDataMap = repeatApiDefinitionWithBLOBs.stream().filter(t -> t.getModuleId().equals(chooseModule.getId())).collect(Collectors.groupingBy(t -> t.getName().concat(t.getMethod()).concat(t.getPath()).concat(t.getModulePath()))); - } else { - //否则在整个系统中过滤 - getUrlRepeatOptionMap(optionData, optionMap); - repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getName().concat(t.getMethod()).concat(t.getPath()).concat(t.getModulePath()))); } + getUrlRepeatOptionMap(optionData, optionMap); + repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getName().concat(t.getMethod()).concat(t.getPath()).concat(t.getModulePath()))); Map> oldCaseMap = new HashMap<>(); //重复接口的case if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) { From 19205a78796dc3deaee29382a79faf67f8b74cf6 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Thu, 22 Dec 2022 12:23:04 +0800 Subject: [PATCH 4/5] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E6=8A=A5=E5=91=8A=E8=AE=A1=E7=AE=97=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化测试计划报告计算方法 --- .../plan/service/TestPlanReportService.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index a2465d4503..35aad533f6 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -491,13 +491,11 @@ public class TestPlanReportService { return testPlanReport; } boolean isSendMessage = false; - if (testPlanReport != null) { testPlanReport.setIsApiCaseExecuting(false); testPlanReport.setIsScenarioExecuting(false); testPlanReport.setIsPerformanceExecuting(false); testPlanReport.setIsUiScenarioExecuting(false); - if (StringUtils.equalsIgnoreCase(testPlanReport.getStatus(), ExecuteResult.TEST_PLAN_RUNNING.toString())) { isSendMessage = true; } @@ -531,7 +529,7 @@ public class TestPlanReportService { testPlanReport.setUpdateTime(endTime); TestPlanReportContentExample contentExample = new TestPlanReportContentExample(); - contentExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReport.getTestPlanId()); + contentExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReport.getId()); List contents = testPlanReportContentMapper.selectByExampleWithBLOBs(contentExample); if (CollectionUtils.isNotEmpty(contents)) { content = contents.get(0); @@ -599,8 +597,13 @@ public class TestPlanReportService { private void initTestPlanReportBaseCount(TestPlanReport testPlanReport, TestPlanReportContentWithBLOBs reportContent) { if (testPlanReport != null && reportContent != null) { - TestPlanReportBuildResultDTO reportBuildResultDTO = testPlanService.buildPlanReport(testPlanReport, reportContent); - reportContent.setApiBaseCount(JSON.toJSONString(reportBuildResultDTO.getTestPlanSimpleReportDTO())); + try { + TestPlanReportBuildResultDTO reportBuildResultDTO = testPlanService.buildPlanReport(testPlanReport, reportContent); + reportContent.setApiBaseCount(JSON.toJSONString(reportBuildResultDTO.getTestPlanSimpleReportDTO())); + } catch (Exception e) { + LogUtil.error("计算测试计划报告信息出错!", e); + } + } } From eef046300bd12621d87130452d1a079840a18bc6 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Thu, 22 Dec 2022 10:58:18 +0800 Subject: [PATCH 5/5] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE):=20=E8=B6=85=E7=BA=A7=E7=94=A8=E6=88=B7=E7=BB=84?= =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frontend/src/utils/constants.js | 1 + .../frontend/src/utils/permission.js | 20 +++++-------------- .../commons/utils/SessionUtils.java | 10 ++++++++++ .../io/metersphere/service/GroupService.java | 4 +--- .../io/metersphere/service/GroupService.java | 17 ++++++++-------- .../business/system/group/EditPermission.vue | 4 ++-- .../business/system/group/GroupPermission.vue | 4 +++- .../src/business/system/group/UserGroup.vue | 5 ++++- 8 files changed, 35 insertions(+), 30 deletions(-) diff --git a/framework/sdk-parent/frontend/src/utils/constants.js b/framework/sdk-parent/frontend/src/utils/constants.js index 0057a94285..e42f2a3706 100644 --- a/framework/sdk-parent/frontend/src/utils/constants.js +++ b/framework/sdk-parent/frontend/src/utils/constants.js @@ -24,6 +24,7 @@ export const ROLE_ORG_ADMIN = 'org_admin'; export const ROLE_TEST_MANAGER = 'test_manager'; export const ROLE_TEST_USER = 'test_user'; export const ROLE_TEST_VIEWER = 'test_viewer'; +export const SUPER_GROUP = 'super_group'; export const ORGANIZATION_ID = 'organization_id'; export const WORKSPACE_ID = 'workspace_id'; diff --git a/framework/sdk-parent/frontend/src/utils/permission.js b/framework/sdk-parent/frontend/src/utils/permission.js index a74ac7e255..f0e093b38e 100644 --- a/framework/sdk-parent/frontend/src/utils/permission.js +++ b/framework/sdk-parent/frontend/src/utils/permission.js @@ -1,8 +1,12 @@ -import {LicenseKey} from "./constants"; +import {LicenseKey, SUPER_GROUP} from "./constants"; import {getCurrentProjectID, getCurrentUser, getCurrentWorkspaceId} from "./token"; export function hasPermission(permission) { let user = getCurrentUser(); + let index = user.groups.findIndex(g => g.id === SUPER_GROUP); + if (index !== -1) { + return true; + } user.userGroups.forEach(ug => { user.groupPermissions.forEach(gp => { @@ -13,20 +17,6 @@ export function hasPermission(permission) { }); }); - let superGroupPermissions = user.userGroups.filter(ug => ug.group && ug.group.id === 'super_group') - .flatMap(ug => ug.userGroupPermissions) - .map(g => g.permissionId) - .reduce((total, current) => { - total.add(current); - return total; - }, new Set); - - for (const p of superGroupPermissions) { - if (p === permission) { - return true; - } - } - // todo 权限验证 let currentProjectPermissions = user.userGroups.filter(ug => ug.group && ug.group.type === 'PROJECT') .filter(ug => ug.sourceId === getCurrentProjectID()) diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/SessionUtils.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/SessionUtils.java index 4f9a5847d5..aa07badaf2 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/SessionUtils.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/SessionUtils.java @@ -2,6 +2,7 @@ package io.metersphere.commons.utils; import io.metersphere.base.domain.Group; import io.metersphere.base.domain.UserGroupPermission; +import io.metersphere.commons.constants.UserGroupConstants; import io.metersphere.commons.user.SessionUser; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; @@ -141,6 +142,15 @@ public class SessionUtils { } })); + long count = user.getGroups() + .stream() + .filter(g -> StringUtils.equals(g.getId(), UserGroupConstants.SUPER_GROUP)) + .count(); + + if (count > 0) { + return true; + } + Set currentProjectPermissions = getCurrentProjectPermissions(userGroupPermissions, projectId, group, user); if (currentProjectPermissions.contains(permission)) { diff --git a/project-management/backend/src/main/java/io/metersphere/service/GroupService.java b/project-management/backend/src/main/java/io/metersphere/service/GroupService.java index 0c857795b7..450aa26549 100644 --- a/project-management/backend/src/main/java/io/metersphere/service/GroupService.java +++ b/project-management/backend/src/main/java/io/metersphere/service/GroupService.java @@ -70,8 +70,6 @@ public class GroupService { @Resource private BaseUserService baseUserService; private static final String GLOBAL = "global"; - private static final String SUPER_GROUP = "super_group"; - // 服务权限拼装顺序 private static final String[] servicePermissionLoadOrder = {MicroServiceName.PROJECT_MANAGEMENT, @@ -225,7 +223,7 @@ public class GroupService { } public void editGroupPermission(EditGroupRequest request) { - if (StringUtils.equals(request.getUserGroupId(), SUPER_GROUP)) { + if (StringUtils.equals(request.getUserGroupId(), UserGroupConstants.SUPER_GROUP)) { return; } List permissions = request.getPermissions(); diff --git a/system-setting/backend/src/main/java/io/metersphere/service/GroupService.java b/system-setting/backend/src/main/java/io/metersphere/service/GroupService.java index d2b5874abe..335a083fec 100644 --- a/system-setting/backend/src/main/java/io/metersphere/service/GroupService.java +++ b/system-setting/backend/src/main/java/io/metersphere/service/GroupService.java @@ -68,7 +68,6 @@ public class GroupService { private UserMapper userMapper; private static final String GLOBAL = "global"; - private static final String SUPER_GROUP = "super_group"; private static final String PERSONAL_PREFIX = "PERSONAL"; @@ -236,7 +235,7 @@ public class GroupService { public void editGroupPermission(EditGroupRequest request) { // 超级用户组禁止修改权限 - if (StringUtils.equals(request.getUserGroupId(), SUPER_GROUP)) { + if (StringUtils.equals(request.getUserGroupId(), UserGroupConstants.SUPER_GROUP)) { return; } List permissions = request.getPermissions(); @@ -331,19 +330,21 @@ public class GroupService { private List getResourcePermission(List resources, List permissions, Group group, List permissionList) { List dto = new ArrayList<>(); List grs; - if (StringUtils.equals(group.getId(), SUPER_GROUP)) { + if (StringUtils.equals(group.getId(), UserGroupConstants.SUPER_GROUP)) { grs = resources; + permissions.forEach(p -> p.setChecked(true)); } else { grs = resources .stream() .filter(g -> g.getId().startsWith(group.getType()) || g.getId().startsWith(PERSONAL_PREFIX)) .collect(Collectors.toList()); + permissions.forEach(p -> { + if (permissionList.contains(p.getId())) { + p.setChecked(true); + } + }); } - permissions.forEach(p -> { - if (permissionList.contains(p.getId())) { - p.setChecked(true); - } - }); + for (GroupResource r : grs) { GroupResourceDTO resourceDTO = new GroupResourceDTO(); resourceDTO.setResource(r); diff --git a/system-setting/frontend/src/business/system/group/EditPermission.vue b/system-setting/frontend/src/business/system/group/EditPermission.vue index 46284076b2..2350686722 100644 --- a/system-setting/frontend/src/business/system/group/EditPermission.vue +++ b/system-setting/frontend/src/business/system/group/EditPermission.vue @@ -71,7 +71,7 @@ import GroupPermission from "./GroupPermission"; import {PROJECT_GROUP_SCOPE, USER_GROUP_SCOPE} from "metersphere-frontend/src/utils/table-constants"; import {hasLicense} from "metersphere-frontend/src/utils/permission"; -import {GROUP_TYPE} from 'metersphere-frontend/src/utils/constants' +import {GROUP_TYPE, SUPER_GROUP} from 'metersphere-frontend/src/utils/constants' import {getUserGroupPermission, modifyUserGroupPermission} from "../../../api/user-group"; export default { @@ -99,7 +99,7 @@ export default { }, isReadOnly() { return function (data) { - if (this.group.id === 'super_group') { + if (this.group.id === SUPER_GROUP) { return true; } const isDefaultSystemGroup = this.group.id === 'admin' && data.resource.id === 'SYSTEM_GROUP'; diff --git a/system-setting/frontend/src/business/system/group/GroupPermission.vue b/system-setting/frontend/src/business/system/group/GroupPermission.vue index 25340bcffc..d5d5054dcb 100644 --- a/system-setting/frontend/src/business/system/group/GroupPermission.vue +++ b/system-setting/frontend/src/business/system/group/GroupPermission.vue @@ -13,6 +13,8 @@