Merge branch 'main' of https://github.com/metersphere/metersphere
This commit is contained in:
commit
8b7fe7b807
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ public class PluginService {
|
|||
List<PluginDTO> 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<Plugin> list() {
|
||||
PluginExample example = new PluginExample();
|
||||
example.createCriteria().andScenarioEqualTo(PluginScenario.api.name());
|
||||
List<Plugin> plugins = pluginMapper.selectByExample(example);
|
||||
return plugins;
|
||||
}
|
||||
|
|
|
@ -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<String, List<ApiTestCaseWithBLOBs>> oldCaseMap = new HashMap<>();
|
||||
//重复接口的case
|
||||
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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<String> currentProjectPermissions = getCurrentProjectPermissions(userGroupPermissions, projectId, group, user);
|
||||
if (currentProjectPermissions.contains(permission)) {
|
||||
|
|
|
@ -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<GroupPermission> permissions = request.getPermissions();
|
||||
|
|
|
@ -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<GroupPermission> permissions = request.getPermissions();
|
||||
|
@ -331,19 +330,21 @@ public class GroupService {
|
|||
private List<GroupResourceDTO> getResourcePermission(List<GroupResource> resources, List<GroupPermission> permissions, Group group, List<String> permissionList) {
|
||||
List<GroupResourceDTO> dto = new ArrayList<>();
|
||||
List<GroupResource> 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);
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import {SUPER_GROUP} from 'metersphere-frontend/src/utils/constants';
|
||||
|
||||
export default {
|
||||
name: "GroupPermission",
|
||||
props: {
|
||||
|
@ -45,7 +47,7 @@ export default {
|
|||
isReadOnly() {
|
||||
return function (permission) {
|
||||
// 禁止取消系统管理员用户组权限
|
||||
if (this.group.id === 'super_group') {
|
||||
if (this.group.id === SUPER_GROUP) {
|
||||
return true;
|
||||
}
|
||||
// 禁止取消系统管理员用户组和超级管理员用户组的读取和设置权限
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<el-table-column prop="description" :label="$t('group.description')" show-overflow-tooltip/>
|
||||
<el-table-column :label="$t('commons.operating')" min-width="120">
|
||||
<template v-slot="scope">
|
||||
<div v-if="scope.row.id === 'super_group'">
|
||||
<div v-if="scope.row.id === SUPER_GROUP">
|
||||
<ms-table-operator
|
||||
:is-show="true"
|
||||
@editClick="edit(scope.row)" @deleteClick="del(scope.row)">
|
||||
|
@ -101,6 +101,8 @@ import {_sort} from "metersphere-frontend/src/utils/tableUtils";
|
|||
import GroupMember from "./GroupMember";
|
||||
import {hasPermission} from "metersphere-frontend/src/utils/permission";
|
||||
import {delUserGroupById, getUserGroupListByPage} from "../../../api/user-group";
|
||||
import {SUPER_GROUP} from 'metersphere-frontend/src/utils/constants'
|
||||
|
||||
|
||||
export default {
|
||||
name: "UserGroup",
|
||||
|
@ -123,6 +125,7 @@ export default {
|
|||
total: 0,
|
||||
screenHeight: 'calc(100vh - 160px)',
|
||||
groups: [],
|
||||
SUPER_GROUP
|
||||
};
|
||||
},
|
||||
activated() {
|
||||
|
|
|
@ -491,22 +491,21 @@ 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;
|
||||
}
|
||||
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,24 +517,19 @@ 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());
|
||||
contentExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReport.getId());
|
||||
List<TestPlanReportContentWithBLOBs> contents = testPlanReportContentMapper.selectByExampleWithBLOBs(contentExample);
|
||||
if (CollectionUtils.isNotEmpty(contents)) {
|
||||
content = contents.get(0);
|
||||
|
@ -550,8 +544,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);
|
||||
}
|
||||
|
@ -603,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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue