From 2ad4b4fa3b2cf3d0177a8eb01ca201892002d456 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Fri, 21 May 2021 18:43:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=88=90=E5=91=98=E5=88=97=E8=A1=A8=20?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/mapper/ext/ExtUserGroupMapper.java | 4 + .../base/mapper/ext/ExtUserGroupMapper.xml | 13 ++ .../controller/GroupController.java | 5 + .../controller/ProjectController.java | 7 + .../controller/UserController.java | 24 +++ .../request/member/AddMemberRequest.java | 1 + .../request/member/QueryMemberRequest.java | 1 + .../metersphere/dto/WorkspaceMemberDTO.java | 1 + .../io/metersphere/service/GroupService.java | 4 + .../metersphere/service/ProjectService.java | 44 ++++ .../io/metersphere/service/UserService.java | 49 +++++ .../settings/project/EditMember.vue | 143 +++++++++++++ .../components/settings/project/Member.vue | 196 ++++++++++++++++++ .../business/components/settings/router.js | 5 + 14 files changed, 497 insertions(+) create mode 100644 frontend/src/business/components/settings/project/EditMember.vue create mode 100644 frontend/src/business/components/settings/project/Member.vue diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserGroupMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserGroupMapper.java index 8d2bf2b0b5..0fbac63038 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserGroupMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserGroupMapper.java @@ -24,4 +24,8 @@ public interface ExtUserGroupMapper { List getMemberList(@Param("member") QueryMemberRequest request); List getUserRoleHelpList(@Param("userId") String userId); + + List getProjectMemberList(@Param("request") QueryMemberRequest request); + + List getProjectMemberGroups(@Param("projectId") String projectId,@Param("userId") String userId); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserGroupMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserGroupMapper.xml index 896495689a..7007563690 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserGroupMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserGroupMapper.xml @@ -66,4 +66,17 @@ WHERE ug.user_id = #{userId} + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/controller/GroupController.java b/backend/src/main/java/io/metersphere/controller/GroupController.java index 828275ed85..897a5fdb56 100644 --- a/backend/src/main/java/io/metersphere/controller/GroupController.java +++ b/backend/src/main/java/io/metersphere/controller/GroupController.java @@ -78,6 +78,11 @@ public class GroupController { return groupService.getWorkspaceMemberGroups(workspaceId, userId); } + @GetMapping("/list/project/{projectId}/{userId}") + public List getProjectMemberGroups(@PathVariable String projectId, @PathVariable String userId) { + return groupService.getProjectMemberGroups(projectId, userId); + } + @GetMapping("/org/{userId}") public List getOrganization(@PathVariable String userId) { return groupService.getOrganization(userId); diff --git a/backend/src/main/java/io/metersphere/controller/ProjectController.java b/backend/src/main/java/io/metersphere/controller/ProjectController.java index 18b78d41d9..57da33f2bc 100644 --- a/backend/src/main/java/io/metersphere/controller/ProjectController.java +++ b/backend/src/main/java/io/metersphere/controller/ProjectController.java @@ -13,6 +13,7 @@ import io.metersphere.commons.utils.SessionUtils; import io.metersphere.controller.request.AddProjectRequest; import io.metersphere.controller.request.ProjectRequest; import io.metersphere.dto.ProjectDTO; +import io.metersphere.dto.WorkspaceMemberDTO; import io.metersphere.log.annotation.MsAuditLog; import io.metersphere.service.CheckPermissionService; import io.metersphere.service.ProjectService; @@ -123,4 +124,10 @@ public class ProjectController { public void deleteFile(@PathVariable String fileId) { projectService.deleteFile(fileId); } + + @PostMapping("/member/update") +// @MsAuditLog(module = "workspace_member", type = OperLogConstants.UPDATE, title = "#memberDTO.name") + public void updateMember(@RequestBody WorkspaceMemberDTO memberDTO) { + projectService.updateMember(memberDTO); + } } diff --git a/backend/src/main/java/io/metersphere/controller/UserController.java b/backend/src/main/java/io/metersphere/controller/UserController.java index c26a178e31..f84081df96 100644 --- a/backend/src/main/java/io/metersphere/controller/UserController.java +++ b/backend/src/main/java/io/metersphere/controller/UserController.java @@ -212,6 +212,12 @@ public class UserController { return PageUtils.setPageInfo(page, userService.getMemberList(request)); } + @PostMapping("/project/member/list/{goPage}/{pageSize}") + public Pager> getProjectMemberList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryMemberRequest request) { + Page page = PageHelper.startPage(goPage, pageSize, true); + return PageUtils.setPageInfo(page, userService.getProjectMemberList(request)); + } + /** * 获取工作空间成员用户 不分页 */ @@ -234,6 +240,13 @@ public class UserController { userService.addMember(request); } + @PostMapping("/project/member/add") +// @MsAuditLog(module = "workspace_member", type = OperLogConstants.CREATE, title = "添加项目成员成员") + public void addProjectMember(@RequestBody AddMemberRequest request) { +// workspaceService.checkWorkspaceOwner(wsId); + userService.addProjectMember(request); + } + /** * 删除工作空间成员 */ @@ -249,6 +262,17 @@ public class UserController { userService.deleteMember(workspaceId, userId); } + @GetMapping("/project/member/delete/{projectId}/{userId}") +// @MsAuditLog(module = "workspace_member", type = OperLogConstants.DELETE, title = "删除工作空间成员") + public void deleteProjectMember(@PathVariable String projectId, @PathVariable String userId) { +// workspaceService.checkWorkspaceOwner(workspaceId); +// String currentUserId = SessionUtils.getUser().getId(); +// if (StringUtils.equals(userId, currentUserId)) { +// MSException.throwException(Translator.get("cannot_remove_current")); +// } + userService.deleteProjectMember(projectId, userId); + } + /** * 添加组织成员 */ diff --git a/backend/src/main/java/io/metersphere/controller/request/member/AddMemberRequest.java b/backend/src/main/java/io/metersphere/controller/request/member/AddMemberRequest.java index 4d9e86e96e..ce22697b3f 100644 --- a/backend/src/main/java/io/metersphere/controller/request/member/AddMemberRequest.java +++ b/backend/src/main/java/io/metersphere/controller/request/member/AddMemberRequest.java @@ -13,4 +13,5 @@ public class AddMemberRequest { private List userIds; private List roleIds; private List groupIds; + private String projectId; } diff --git a/backend/src/main/java/io/metersphere/controller/request/member/QueryMemberRequest.java b/backend/src/main/java/io/metersphere/controller/request/member/QueryMemberRequest.java index 40360cb01f..0b54e98ef2 100644 --- a/backend/src/main/java/io/metersphere/controller/request/member/QueryMemberRequest.java +++ b/backend/src/main/java/io/metersphere/controller/request/member/QueryMemberRequest.java @@ -8,4 +8,5 @@ import lombok.Setter; public class QueryMemberRequest { private String name; private String workspaceId; + private String projectId; } diff --git a/backend/src/main/java/io/metersphere/dto/WorkspaceMemberDTO.java b/backend/src/main/java/io/metersphere/dto/WorkspaceMemberDTO.java index 4e1e7aa69b..46a5ef50b3 100644 --- a/backend/src/main/java/io/metersphere/dto/WorkspaceMemberDTO.java +++ b/backend/src/main/java/io/metersphere/dto/WorkspaceMemberDTO.java @@ -19,6 +19,7 @@ public class WorkspaceMemberDTO { private Long updateTime; private String language; private String workspaceId; + private String projectId; private List roleIds = new ArrayList<>(); private List groupIds = new ArrayList<>(); diff --git a/backend/src/main/java/io/metersphere/service/GroupService.java b/backend/src/main/java/io/metersphere/service/GroupService.java index 06b1bbb529..076809c7c1 100644 --- a/backend/src/main/java/io/metersphere/service/GroupService.java +++ b/backend/src/main/java/io/metersphere/service/GroupService.java @@ -325,4 +325,8 @@ public class GroupService { list = organizationMapper.selectByExample(organizationExample); return list; } + + public List getProjectMemberGroups(String projectId, String userId) { + return extUserGroupMapper.getProjectMemberGroups(projectId, userId); + } } diff --git a/backend/src/main/java/io/metersphere/service/ProjectService.java b/backend/src/main/java/io/metersphere/service/ProjectService.java index 6b3eba0de4..50b4a78156 100644 --- a/backend/src/main/java/io/metersphere/service/ProjectService.java +++ b/backend/src/main/java/io/metersphere/service/ProjectService.java @@ -7,12 +7,15 @@ import io.metersphere.api.service.APITestService; import io.metersphere.api.service.ApiAutomationService; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; +import io.metersphere.base.mapper.ext.ExtOrganizationMapper; import io.metersphere.base.mapper.ext.ExtProjectMapper; +import io.metersphere.base.mapper.ext.ExtUserGroupMapper; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.ServiceUtils; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.controller.request.ProjectRequest; import io.metersphere.dto.ProjectDTO; +import io.metersphere.dto.WorkspaceMemberDTO; import io.metersphere.i18n.Translator; import io.metersphere.log.utils.ReflexObjectUtil; import io.metersphere.log.vo.DetailColumn; @@ -70,6 +73,12 @@ public class ProjectService { private ApiAutomationService apiAutomationService; @Resource private PerformanceReportService performanceReportService; + @Resource + private UserGroupMapper userGroupMapper; + @Resource + private ExtOrganizationMapper extOrganizationMapper; + @Resource + private ExtUserGroupMapper extUserGroupMapper; public Project addProject(Project project) { if (StringUtils.isBlank(project.getName())) { @@ -304,4 +313,39 @@ public class ProjectService { } return null; } + + public void updateMember(WorkspaceMemberDTO memberDTO) { + String projectId = memberDTO.getProjectId(); + String userId = memberDTO.getId(); + // 已有角色 + List memberGroups = extUserGroupMapper.getProjectMemberGroups(projectId, userId); + // 修改后的角色 + List groups = memberDTO.getGroupIds(); + List allGroupIds = memberGroups.stream().map(Group::getId).collect(Collectors.toList()); + // 更新用户时添加了角色 + for (int i = 0; i < groups.size(); i++) { + if (checkSourceRole(projectId, userId, groups.get(i)) == 0) { + UserGroup userGroup = new UserGroup(); + userGroup.setId(UUID.randomUUID().toString()); + userGroup.setUserId(userId); + userGroup.setGroupId(groups.get(i)); + userGroup.setSourceId(projectId); + userGroup.setCreateTime(System.currentTimeMillis()); + userGroup.setUpdateTime(System.currentTimeMillis()); + userGroupMapper.insertSelective(userGroup); + } + } + allGroupIds.removeAll(groups); + if (allGroupIds.size() > 0) { + UserGroupExample userGroupExample = new UserGroupExample(); + userGroupExample.createCriteria().andUserIdEqualTo(userId) + .andSourceIdEqualTo(projectId) + .andGroupIdIn(allGroupIds); + userGroupMapper.deleteByExample(userGroupExample); + } + } + + public Integer checkSourceRole(String workspaceId, String userId, String roleId) { + return extOrganizationMapper.checkSourceRole(workspaceId, userId, roleId); + } } diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index 79756816bf..529f7859f7 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -1124,4 +1124,53 @@ public class UserService { return null; } + public List getProjectMemberList(QueryMemberRequest request) { + return extUserGroupMapper.getProjectMemberList(request); + } + + public void addProjectMember(AddMemberRequest request) { + if (!CollectionUtils.isEmpty(request.getUserIds())) { + for (String userId : request.getUserIds()) { + UserGroupExample userGroupExample = new UserGroupExample(); + userGroupExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(request.getProjectId()); + List userGroups = userGroupMapper.selectByExample(userGroupExample); + if (userGroups.size() > 0) { + MSException.throwException(Translator.get("user_already_exists")); + } else { + for (String groupId : request.getGroupIds()) { + UserGroup userGroup = new UserGroup(); + userGroup.setGroupId(groupId); + userGroup.setSourceId(request.getProjectId()); + userGroup.setUserId(userId); + userGroup.setId(UUID.randomUUID().toString()); + userGroup.setUpdateTime(System.currentTimeMillis()); + userGroup.setCreateTime(System.currentTimeMillis()); + userGroupMapper.insertSelective(userGroup); + } + } + } + } + } + + public void deleteProjectMember(String projectId, String userId) { + GroupExample groupExample = new GroupExample(); + groupExample.createCriteria().andTypeEqualTo(UserGroupType.PROJECT); + List groups = groupMapper.selectByExample(groupExample); + + List groupIds = groups.stream().map(Group::getId).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(groupIds)) { + return; + } + UserGroupExample userGroupExample = new UserGroupExample(); + userGroupExample.createCriteria().andUserIdEqualTo(userId) + .andSourceIdEqualTo(projectId) + .andGroupIdIn(groupIds); + User user = userMapper.selectByPrimaryKey(userId); + if (StringUtils.equals(projectId, user.getLastProjectId())) { + user.setLastProjectId(""); + userMapper.updateByPrimaryKeySelective(user); + } + + userGroupMapper.deleteByExample(userGroupExample); + } } diff --git a/frontend/src/business/components/settings/project/EditMember.vue b/frontend/src/business/components/settings/project/EditMember.vue new file mode 100644 index 0000000000..1c0c294a2b --- /dev/null +++ b/frontend/src/business/components/settings/project/EditMember.vue @@ -0,0 +1,143 @@ + + + + + diff --git a/frontend/src/business/components/settings/project/Member.vue b/frontend/src/business/components/settings/project/Member.vue new file mode 100644 index 0000000000..ea99aea328 --- /dev/null +++ b/frontend/src/business/components/settings/project/Member.vue @@ -0,0 +1,196 @@ + + + + + diff --git a/frontend/src/business/components/settings/router.js b/frontend/src/business/components/settings/router.js index feaab443a4..2401f105ec 100644 --- a/frontend/src/business/components/settings/router.js +++ b/frontend/src/business/components/settings/router.js @@ -89,6 +89,11 @@ export default { component: () => import('@/business/components/settings/workspace/WorkspaceMember'), meta: {workspace: true, title: 'commons.member', permissions: ['WORKSPACE_USER:READ']} }, + { + path: 'projectmember', + component: () => import('@/business/components/settings/project/Member'), + meta: {project: true, title: 'commons.member', permissions: ['PROJECT_USER:READ']} + }, { path: 'personsetting', component: () => import('@/business/components/settings/personal/PersonSetting'),