From 78948351a1075378e98fbaef3a107bef276acbf0 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Mon, 21 Aug 2023 15:54:26 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E9=A1=B9=E7=9B=AE=E5=A2=9E=E5=8A=A0=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=88=97=E8=A1=A8=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OrganizationProjectController.java | 10 ++++++++++ .../system/controller/SystemProjectController.java | 10 ++++++++++ .../java/io/metersphere/system/dto/UserExtend.java | 6 +++++- .../controller/OrganizationProjectControllerTests.java | 10 ++++++++++ .../controller/SystemProjectControllerTests.java | 9 +++++++++ 5 files changed, 44 insertions(+), 1 deletion(-) diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationProjectController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationProjectController.java index 3563408c55..0ba099bff7 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationProjectController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/OrganizationProjectController.java @@ -13,6 +13,7 @@ import io.metersphere.sdk.log.constants.OperationLogType; import io.metersphere.sdk.util.PageUtils; import io.metersphere.sdk.util.Pager; import io.metersphere.sdk.util.SessionUtils; +import io.metersphere.system.domain.User; import io.metersphere.system.dto.UserExtend; import io.metersphere.system.request.OrganizationProjectRequest; import io.metersphere.system.request.ProjectAddMemberBatchRequest; @@ -20,6 +21,7 @@ import io.metersphere.system.request.ProjectAddMemberRequest; import io.metersphere.system.request.ProjectMemberRequest; import io.metersphere.system.service.OrganizationProjectLogService; import io.metersphere.system.service.OrganizationProjectService; +import io.metersphere.system.service.UserService; import io.metersphere.validation.groups.Created; import io.metersphere.validation.groups.Updated; import io.swagger.v3.oas.annotations.Operation; @@ -41,6 +43,8 @@ import java.util.List; public class OrganizationProjectController { @Resource private OrganizationProjectService organizationProjectService; + @Resource + private UserService userService; @PostMapping("/add") @RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ_ADD) @@ -141,5 +145,11 @@ public class OrganizationProjectController { return organizationProjectService.removeProjectMember(projectId, userId, SessionUtils.getUserId()); } + @GetMapping("/user-list") + @Operation(summary = "获取用户列表") + @RequiresPermissions(PermissionConstants.ORGANIZATION_PROJECT_READ) + public List getUserList() { + return userService.getUserList(); + } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemProjectController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemProjectController.java index cc696e9494..5771452ffd 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemProjectController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/SystemProjectController.java @@ -13,6 +13,7 @@ import io.metersphere.sdk.log.constants.OperationLogType; import io.metersphere.sdk.util.PageUtils; import io.metersphere.sdk.util.Pager; import io.metersphere.sdk.util.SessionUtils; +import io.metersphere.system.domain.User; import io.metersphere.system.dto.UserExtend; import io.metersphere.system.request.ProjectAddMemberBatchRequest; import io.metersphere.system.request.ProjectAddMemberRequest; @@ -20,6 +21,7 @@ import io.metersphere.system.request.ProjectMemberRequest; import io.metersphere.system.request.ProjectRequest; import io.metersphere.system.service.SystemProjectLogService; import io.metersphere.system.service.SystemProjectService; +import io.metersphere.system.service.UserService; import io.metersphere.validation.groups.Created; import io.metersphere.validation.groups.Updated; import io.swagger.v3.oas.annotations.Operation; @@ -41,6 +43,8 @@ import java.util.List; public class SystemProjectController { @Resource private SystemProjectService systemProjectService; + @Resource + private UserService userService; @PostMapping("/add") @RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ_ADD) @@ -141,5 +145,11 @@ public class SystemProjectController { return systemProjectService.removeProjectMember(projectId, userId, SessionUtils.getUserId()); } + @GetMapping("/user-list") + @Operation(summary = "获取用户列表") + @RequiresPermissions(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ) + public List getUserList() { + return userService.getUserList(); + } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserExtend.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserExtend.java index beb9c30d2f..61ca52764c 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserExtend.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/UserExtend.java @@ -4,12 +4,14 @@ import io.metersphere.system.domain.User; import lombok.Data; import lombok.EqualsAndHashCode; +import java.io.Serializable; + /** * @author song-cc-rock */ @Data @EqualsAndHashCode(callSuper = false) -public class UserExtend extends User { +public class UserExtend extends User implements Serializable { /** * 是否管理员(组织, 项目) @@ -20,4 +22,6 @@ public class UserExtend extends User { * 是否成员(组织, 项目) */ private boolean memberFlag; + + private static final long serialVersionUID = 1L; } diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationProjectControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationProjectControllerTests.java index cbb7525317..27047e9db7 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationProjectControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationProjectControllerTests.java @@ -65,6 +65,7 @@ public class OrganizationProjectControllerTests extends BaseTest { private final static String removeProjectMember = prefix + "/remove-member/"; private final static String disableProject = prefix + "/disable/"; private final static String enableProject = prefix + "/enable/"; + private final static String userList = prefix + "/user-list"; private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest(); private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError(); @@ -706,4 +707,13 @@ public class OrganizationProjectControllerTests extends BaseTest { this.responseGet(enableProject + id, ERROR_REQUEST_MATCHER); } + @Test + @Order(21) + public void testUserList() throws Exception { + this.requestGetWithOkAndReturn(userList); + + // @@校验权限 + requestGetPermissionTest(PermissionConstants.ORGANIZATION_PROJECT_READ, userList); + } + } diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemProjectControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemProjectControllerTests.java index 467cdb5925..6e553652b7 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemProjectControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/SystemProjectControllerTests.java @@ -63,6 +63,7 @@ public class SystemProjectControllerTests extends BaseTest { private final static String removeProjectMember = prefix + "/remove-member/"; private final static String disableProject = prefix + "/disable/"; private final static String enableProject = prefix + "/enable/"; + private final static String userList = prefix + "/user-list"; private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest(); private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError(); @@ -669,4 +670,12 @@ public class SystemProjectControllerTests extends BaseTest { this.responseGet(enableProject + id, ERROR_REQUEST_MATCHER); } + @Test + @Order(21) + public void testUserList() throws Exception { + this.requestGetWithOkAndReturn(userList); + + // @@校验权限 + requestGetPermissionTest(PermissionConstants.SYSTEM_ORGANIZATION_PROJECT_READ, userList); + } }