From cbf4c3a8cc5961381e8dfb6b5dcf2920bf7a8274 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Tue, 19 May 2020 16:27:40 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E8=A7=92=E8=89=B2=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserController.java | 9 +++- .../java/io/metersphere/dto/UserRoleDTO.java | 18 ++++++++ .../io/metersphere/service/UserService.java | 18 +++++--- .../components/settings/system/User.vue | 41 +++++++++++++++---- 4 files changed, 70 insertions(+), 16 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/dto/UserRoleDTO.java diff --git a/backend/src/main/java/io/metersphere/controller/UserController.java b/backend/src/main/java/io/metersphere/controller/UserController.java index 55324f028e..e6314d2788 100644 --- a/backend/src/main/java/io/metersphere/controller/UserController.java +++ b/backend/src/main/java/io/metersphere/controller/UserController.java @@ -17,15 +17,14 @@ import io.metersphere.controller.request.member.SetAdminRequest; import io.metersphere.controller.request.organization.AddOrgMemberRequest; import io.metersphere.controller.request.organization.QueryOrgMemberRequest; import io.metersphere.dto.UserDTO; +import io.metersphere.dto.UserRoleDTO; import io.metersphere.service.OrganizationService; import io.metersphere.service.UserService; import io.metersphere.service.WorkspaceService; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresRoles; -import org.springframework.beans.BeanUtils; import org.springframework.web.bind.annotation.*; - import javax.annotation.Resource; import java.util.List; @@ -54,6 +53,12 @@ public class UserController { return PageUtils.setPageInfo(page, userService.getUserListWithRequest(request)); } + @GetMapping("/special/user/role/{userId}") + @RequiresRoles(RoleConstants.ADMIN) + public UserRoleDTO getUserRole(@PathVariable("userId") String userId) { + return userService.getUserRole(userId); + } + @GetMapping("/special/delete/{userId}") @RequiresRoles(RoleConstants.ADMIN) public void deleteUser(@PathVariable(value = "userId") String userId) { diff --git a/backend/src/main/java/io/metersphere/dto/UserRoleDTO.java b/backend/src/main/java/io/metersphere/dto/UserRoleDTO.java new file mode 100644 index 0000000000..80009d51c3 --- /dev/null +++ b/backend/src/main/java/io/metersphere/dto/UserRoleDTO.java @@ -0,0 +1,18 @@ +package io.metersphere.dto; + +import io.metersphere.base.domain.Role; +import io.metersphere.base.domain.UserRole; +import lombok.Getter; +import lombok.Setter; +import java.util.List; + +@Getter +@Setter +public class UserRoleDTO { + + private String userId; + private List roles; + private List userRoles; + private static final long serialVersionUID = 1L; + +} diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index 7ee198862b..f0c9a24416 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -17,13 +17,13 @@ import io.metersphere.controller.request.member.SetAdminRequest; import io.metersphere.controller.request.organization.AddOrgMemberRequest; import io.metersphere.controller.request.organization.QueryOrgMemberRequest; import io.metersphere.dto.UserDTO; +import io.metersphere.dto.UserRoleDTO; import io.metersphere.i18n.Translator; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; - import javax.annotation.Resource; import java.util.List; import java.util.UUID; @@ -100,16 +100,24 @@ public class UserService { } UserDTO userDTO = new UserDTO(); BeanUtils.copyProperties(user, userDTO); + UserRoleDTO userRole = getUserRole(userId); + userDTO.setUserRoles(userRole.getUserRoles()); + userDTO.setRoles(userRole.getRoles()); + return userDTO; + } + + public UserRoleDTO getUserRole(String userId) { + UserRoleDTO userRoleDTO = new UserRoleDTO(); // UserRoleExample userRoleExample = new UserRoleExample(); userRoleExample.createCriteria().andUserIdEqualTo(userId); List userRoleList = userRoleMapper.selectByExample(userRoleExample); if (CollectionUtils.isEmpty(userRoleList)) { - return userDTO; + return userRoleDTO; } // 设置 user_role - userDTO.setUserRoles(userRoleList); + userRoleDTO.setUserRoles(userRoleList); List roleIds = userRoleList.stream().map(UserRole::getRoleId).collect(Collectors.toList()); @@ -117,9 +125,9 @@ public class UserService { roleExample.createCriteria().andIdIn(roleIds); List roleList = roleMapper.selectByExample(roleExample); - userDTO.setRoles(roleList); + userRoleDTO.setRoles(roleList); - return userDTO; + return userRoleDTO; } public List getUserList() { diff --git a/frontend/src/business/components/settings/system/User.vue b/frontend/src/business/components/settings/system/User.vue index aaf7ca4ca1..56d1dc0389 100644 --- a/frontend/src/business/components/settings/system/User.vue +++ b/frontend/src/business/components/settings/system/User.vue @@ -1,7 +1,7 @@ - + + + - + +