From f488d8d9770c8356cca2ee7053c380bdb5fac43f Mon Sep 17 00:00:00 2001 From: CaptainB Date: Mon, 20 Jun 2022 15:08:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E7=A9=BA=E9=97=B4=E6=9D=83=E9=99=90=E7=AC=AC=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E4=B9=8B=E5=90=8E=E4=B8=8D=E8=83=BD=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E8=8F=9C=E5=8D=95=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/metersphere/controller/UserController.java | 3 ++- .../src/main/java/io/metersphere/service/UserService.java | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/io/metersphere/controller/UserController.java b/backend/src/main/java/io/metersphere/controller/UserController.java index c20337641c..0f9af0a97b 100644 --- a/backend/src/main/java/io/metersphere/controller/UserController.java +++ b/backend/src/main/java/io/metersphere/controller/UserController.java @@ -30,6 +30,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.List; import java.util.Map; +import java.util.Objects; @RequestMapping("user") @RestController @@ -131,7 +132,7 @@ public class UserController { @PostMapping("/switch/source/ws/{sourceId}") public UserDTO switchWorkspace(@PathVariable(value = "sourceId") String sourceId) { - userService.switchUserResource("workspace", sourceId); + userService.switchUserResource("workspace", sourceId, Objects.requireNonNull(SessionUtils.getUser())); return SessionUtils.getUser(); } diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index c85186af32..53e49b1052 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -410,14 +410,14 @@ public class UserService { } } - public void switchUserResource(String sign, String sourceId) { - SessionUser sessionUser = SessionUtils.getUser(); + public void switchUserResource(String sign, String sourceId, UserDTO sessionUser) { // 获取最新UserDTO UserDTO user = getUserDTO(sessionUser.getId()); User newUser = new User(); if (StringUtils.equals("workspace", sign)) { user.setLastWorkspaceId(sourceId); + sessionUser.setLastWorkspaceId(sourceId); List projects = getProjectListByWsAndUserId(sessionUser.getId(), sourceId); if (projects.size() > 0) { user.setLastProjectId(projects.get(0).getId()); @@ -665,7 +665,7 @@ public class UserService { .collect(Collectors.toList()); if (workspaces.size() > 0) { String wsId = workspaces.get(0).getSourceId(); - switchUserResource("workspace", wsId); + switchUserResource("workspace", wsId, user); } else { // 用户登录之后没有项目和工作空间的权限就把值清空 user.setLastWorkspaceId("");