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("");