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; } 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)) { 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 @@