From ef87cce86669bff47e8fad1244192318d57db64a Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Tue, 19 Jul 2022 10:56:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E9=A1=B9=E7=9B=AE=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E7=94=A8=E6=88=B7=E7=BB=84=E6=9D=83=E9=99=90?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E8=A2=AB=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1014839 --user=李玉号 【项目设置】项目设置中系统级别的全局用户组权限可以被修改 https://www.tapd.cn/55049933/s/1203887 --- .../base/mapper/ext/ExtGroupMapper.xml | 17 ++++++ .../controller/request/GroupRequest.java | 1 + .../request/group/EditGroupRequest.java | 1 + .../io/metersphere/service/GroupService.java | 42 +++++--------- .../metersphere/service/WorkspaceService.java | 58 +++++++++++-------- .../components/project/menu/EditUserGroup.vue | 38 +++++------- .../components/project/menu/UserGroup.vue | 32 +++++----- .../components/settings/common/AddMember.vue | 16 ++++- .../BatchToProjectGroupCascader.vue | 4 +- .../system/components/WorkspaceCascader.vue | 2 +- .../settings/workspace/MsProject.vue | 5 +- frontend/src/i18n/en-US.js | 3 +- frontend/src/i18n/zh-CN.js | 3 +- frontend/src/i18n/zh-TW.js | 3 +- 14 files changed, 124 insertions(+), 101 deletions(-) diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtGroupMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtGroupMapper.xml index 371914ebe9..0e39fbe996 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtGroupMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtGroupMapper.xml @@ -41,6 +41,23 @@ + union distinct + select g.*, p.name as scopeName from `group` g, project p + + and g.scope_id = p.id + + AND g.type in + + #{type} + + + + AND g.scope_id in + + #{scope} + + + ) temp where temp.name like CONCAT('%', #{request.name},'%') diff --git a/backend/src/main/java/io/metersphere/controller/request/GroupRequest.java b/backend/src/main/java/io/metersphere/controller/request/GroupRequest.java index a3210f9ed2..db01165221 100644 --- a/backend/src/main/java/io/metersphere/controller/request/GroupRequest.java +++ b/backend/src/main/java/io/metersphere/controller/request/GroupRequest.java @@ -5,5 +5,6 @@ import lombok.Data; @Data public class GroupRequest { private String resourceId; + private String projectId; private String type; } diff --git a/backend/src/main/java/io/metersphere/controller/request/group/EditGroupRequest.java b/backend/src/main/java/io/metersphere/controller/request/group/EditGroupRequest.java index 4ca04f9667..827ff96441 100644 --- a/backend/src/main/java/io/metersphere/controller/request/group/EditGroupRequest.java +++ b/backend/src/main/java/io/metersphere/controller/request/group/EditGroupRequest.java @@ -28,4 +28,5 @@ public class EditGroupRequest extends Group { private String userGroupId; private List orders; private boolean onlyQueryCurrentProject = false; + private boolean onlyQueryGlobal = false; } diff --git a/backend/src/main/java/io/metersphere/service/GroupService.java b/backend/src/main/java/io/metersphere/service/GroupService.java index a5f4391509..a18d8a7d6f 100644 --- a/backend/src/main/java/io/metersphere/service/GroupService.java +++ b/backend/src/main/java/io/metersphere/service/GroupService.java @@ -26,7 +26,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; -import org.apache.poi.ss.formula.functions.T; import org.mybatis.spring.SqlSessionUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -229,6 +228,9 @@ public class GroupService { if (!StringUtils.equals(type, UserGroupType.SYSTEM)) { criteria.andTypeEqualTo(type); } + if (BooleanUtils.isTrue(request.isOnlyQueryGlobal())) { + criteria.andScopeIdEqualTo(GLOBAL); + } return groupMapper.selectByExample(example); } @@ -262,6 +264,9 @@ public class GroupService { String resourceId = request.getResourceId(); String type = request.getType(); List scopeList = Arrays.asList(GLOBAL, resourceId); + if (StringUtils.equals(type, UserGroupType.PROJECT) && StringUtils.isNotBlank(request.getProjectId())) { + scopeList = Arrays.asList(GLOBAL, resourceId, request.getProjectId()); + } GroupExample groupExample = new GroupExample(); groupExample.createCriteria().andScopeIdIn(scopeList) .andTypeEqualTo(type); @@ -313,7 +318,8 @@ public class GroupService { private Pager> getUserGroup(String groupType, EditGroupRequest request) { List types; String workspaceId = SessionUtils.getCurrentWorkspaceId(); - List scopes = Arrays.asList(GLOBAL, workspaceId); + String projectId = SessionUtils.getCurrentProjectId(); + List scopes = Arrays.asList(GLOBAL, workspaceId, projectId); int goPage = request.getGoPage(); int pageSize = request.getPageSize(); Page page = PageHelper.startPage(goPage, pageSize, true); @@ -323,7 +329,6 @@ public class GroupService { types = map.get(groupType); request.setTypes(types); request.setScopes(scopes); -// request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); List groups = extGroupMapper.getGroupList(request); buildUserInfo(groups); return PageUtils.setPageInfo(page, groups); @@ -341,36 +346,17 @@ public class GroupService { } public List getResource(String type, String groupId) { - List resource = new ArrayList<>(); Group group = groupMapper.selectByPrimaryKey(groupId); - String workspaceId = group.getScopeId(); - + if (group == null) { + return new ArrayList<>(); + } if (StringUtils.equals(UserGroupType.WORKSPACE, type)) { - WorkspaceExample workspaceExample = new WorkspaceExample(); - WorkspaceExample.Criteria criteria = workspaceExample.createCriteria(); - if (!StringUtils.equals(workspaceId, GLOBAL)) { - criteria.andIdEqualTo(workspaceId); - } - return workspaceMapper.selectByExample(workspaceExample); + return workspaceService.getWorkspaceGroupResource(group.getScopeId()); } - if (StringUtils.equals(UserGroupType.PROJECT, type)) { - ProjectExample projectExample = new ProjectExample(); - ProjectExample.Criteria pc = projectExample.createCriteria(); - WorkspaceExample workspaceExample = new WorkspaceExample(); - WorkspaceExample.Criteria criteria = workspaceExample.createCriteria(); - if (!StringUtils.equals(workspaceId, GLOBAL)) { - criteria.andIdEqualTo(workspaceId); - List workspaces = workspaceMapper.selectByExample(workspaceExample); - List list = workspaces.stream().map(Workspace::getId).collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(list)) { - pc.andWorkspaceIdIn(list); - } - } - return projectMapper.selectByExample(projectExample); + return workspaceService.getProjectGroupResource(group.getScopeId()); } - - return resource; + return new ArrayList<>(); } public List getGroupUser(EditGroupRequest request) { diff --git a/backend/src/main/java/io/metersphere/service/WorkspaceService.java b/backend/src/main/java/io/metersphere/service/WorkspaceService.java index dfb6832934..1163571387 100644 --- a/backend/src/main/java/io/metersphere/service/WorkspaceService.java +++ b/backend/src/main/java/io/metersphere/service/WorkspaceService.java @@ -60,6 +60,8 @@ public class WorkspaceService { @Resource private EnvironmentGroupService environmentGroupService; + private static final String GLOBAL = "global"; + public Workspace saveWorkspace(Workspace workspace) { if (StringUtils.isBlank(workspace.getName())) { MSException.throwException(Translator.get("workspace_name_is_null")); @@ -299,37 +301,47 @@ public class WorkspaceService { public WorkspaceResource listResource(String groupId, String type) { Group group = groupMapper.selectByPrimaryKey(groupId); - String workspaceId = group.getScopeId(); WorkspaceResource resource = new WorkspaceResource(); - + if (group == null) { + return resource; + } if (StringUtils.equals(UserGroupType.WORKSPACE, type)) { - WorkspaceExample workspaceExample = new WorkspaceExample(); - WorkspaceExample.Criteria criteria = workspaceExample.createCriteria(); - if (!StringUtils.equals(workspaceId, "global")) { - criteria.andIdEqualTo(workspaceId); - } - List workspaces = workspaceMapper.selectByExample(workspaceExample); - resource.setWorkspaces(workspaces); + resource.setWorkspaces(getWorkspaceGroupResource(group.getScopeId())); } - if (StringUtils.equals(UserGroupType.PROJECT, type)) { - ProjectExample projectExample = new ProjectExample(); - ProjectExample.Criteria pc = projectExample.createCriteria(); - WorkspaceExample workspaceExample = new WorkspaceExample(); - WorkspaceExample.Criteria criteria = workspaceExample.createCriteria(); - if (!StringUtils.equals(workspaceId, "global")) { - criteria.andIdEqualTo(workspaceId); - List workspaces = workspaceMapper.selectByExample(workspaceExample); - List list = workspaces.stream().map(Workspace::getId).collect(Collectors.toList()); - pc.andWorkspaceIdIn(list); - } - List projects = projectMapper.selectByExample(projectExample); - resource.setProjects(projects); + resource.setProjects(getProjectGroupResource(group.getScopeId())); } - return resource; } + public List getWorkspaceGroupResource(String scopeId) { + WorkspaceExample workspaceExample = new WorkspaceExample(); + WorkspaceExample.Criteria criteria = workspaceExample.createCriteria(); + if (!StringUtils.equals(scopeId, GLOBAL)) { + criteria.andIdEqualTo(scopeId); + } + return workspaceMapper.selectByExample(workspaceExample); + } + + public List getProjectGroupResource(String scopeId) { + ProjectExample projectExample = new ProjectExample(); + ProjectExample.Criteria criteria = projectExample.createCriteria(); + if (StringUtils.equals(scopeId, GLOBAL)) { + return projectMapper.selectByExample(projectExample); + } + Workspace workspace = workspaceMapper.selectByPrimaryKey(scopeId); + if (workspace != null) { + criteria.andWorkspaceIdEqualTo(workspace.getId()); + return projectMapper.selectByExample(projectExample); + } + Project project = projectMapper.selectByPrimaryKey(scopeId); + List list = new ArrayList<>(); + if (project != null) { + list.add(project); + } + return list; + } + public List getWorkspaceIds() { return extWorkspaceMapper.getWorkspaceIds(); } diff --git a/frontend/src/business/components/project/menu/EditUserGroup.vue b/frontend/src/business/components/project/menu/EditUserGroup.vue index 4997431034..1da6bed6f5 100644 --- a/frontend/src/business/components/project/menu/EditUserGroup.vue +++ b/frontend/src/business/components/project/menu/EditUserGroup.vue @@ -23,11 +23,9 @@ - - + + -