diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index c8bc97e34b..179cbb51ec 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -632,6 +632,7 @@ public class UserService { } private void autoSwitch(UserDTO user) { + // 用户有 last_project_id 权限 if (StringUtils.isNotBlank(user.getLastProjectId())) { List projectUserGroups = user.getUserGroups().stream() .filter(ug -> StringUtils.equals(user.getLastProjectId(), ug.getSourceId())) @@ -640,6 +641,15 @@ public class UserService { return; } } + // 用户有 last_workspace_id 权限 + if (StringUtils.isNotBlank(user.getLastWorkspaceId())) { + List workspaceUserGroups = user.getUserGroups().stream() + .filter(ug -> StringUtils.equals(user.getLastWorkspaceId(), ug.getSourceId())) + .collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(workspaceUserGroups)) { + return; + } + } List userGroups = user.getUserGroups(); List projectGroupIds = user.getGroups() .stream().filter(ug -> StringUtils.equals(ug.getType(), UserGroupType.PROJECT))