fix: 用户修改last_workspace_id之后执行登录被覆盖的问题
This commit is contained in:
parent
6660bb98d8
commit
4136d25590
|
@ -395,9 +395,13 @@ public class UserService {
|
||||||
User userFromDB = userMapper.selectByPrimaryKey(user.getId());
|
User userFromDB = userMapper.selectByPrimaryKey(user.getId());
|
||||||
// last workspace id 变了
|
// last workspace id 变了
|
||||||
if (user.getLastWorkspaceId() != null && !StringUtils.equals(user.getLastWorkspaceId(), userFromDB.getLastWorkspaceId())) {
|
if (user.getLastWorkspaceId() != null && !StringUtils.equals(user.getLastWorkspaceId(), userFromDB.getLastWorkspaceId())) {
|
||||||
List<Project> projects = getProjectListByWsAndUserId(user.getLastWorkspaceId());
|
List<Project> projects = getProjectListByWsAndUserId(user.getId(), user.getLastWorkspaceId());
|
||||||
if (projects.size() > 0) {
|
if (projects.size() > 0) {
|
||||||
|
// 如果传入的 last_project_id 是 last_workspace_id 下面的
|
||||||
|
boolean present = projects.stream().anyMatch(p -> StringUtils.equals(p.getId(), user.getLastProjectId()));
|
||||||
|
if (!present) {
|
||||||
user.setLastProjectId(projects.get(0).getId());
|
user.setLastProjectId(projects.get(0).getId());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
user.setLastProjectId("");
|
user.setLastProjectId("");
|
||||||
}
|
}
|
||||||
|
@ -417,7 +421,7 @@ public class UserService {
|
||||||
|
|
||||||
if (StringUtils.equals("workspace", sign)) {
|
if (StringUtils.equals("workspace", sign)) {
|
||||||
user.setLastWorkspaceId(sourceId);
|
user.setLastWorkspaceId(sourceId);
|
||||||
List<Project> projects = getProjectListByWsAndUserId(sourceId);
|
List<Project> projects = getProjectListByWsAndUserId(sessionUser.getId(), sourceId);
|
||||||
if (projects.size() > 0) {
|
if (projects.size() > 0) {
|
||||||
user.setLastProjectId(projects.get(0).getId());
|
user.setLastProjectId(projects.get(0).getId());
|
||||||
} else {
|
} else {
|
||||||
|
@ -430,14 +434,13 @@ public class UserService {
|
||||||
userMapper.updateByPrimaryKeySelective(newUser);
|
userMapper.updateByPrimaryKeySelective(newUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Project> getProjectListByWsAndUserId(String workspaceId) {
|
private List<Project> getProjectListByWsAndUserId(String userId, String workspaceId) {
|
||||||
String useId = SessionUtils.getUser().getId();
|
|
||||||
ProjectExample projectExample = new ProjectExample();
|
ProjectExample projectExample = new ProjectExample();
|
||||||
projectExample.createCriteria().andWorkspaceIdEqualTo(workspaceId);
|
projectExample.createCriteria().andWorkspaceIdEqualTo(workspaceId);
|
||||||
List<Project> projects = projectMapper.selectByExample(projectExample);
|
List<Project> projects = projectMapper.selectByExample(projectExample);
|
||||||
|
|
||||||
UserGroupExample userGroupExample = new UserGroupExample();
|
UserGroupExample userGroupExample = new UserGroupExample();
|
||||||
userGroupExample.createCriteria().andUserIdEqualTo(useId);
|
userGroupExample.createCriteria().andUserIdEqualTo(userId);
|
||||||
List<UserGroup> userGroups = userGroupMapper.selectByExample(userGroupExample);
|
List<UserGroup> userGroups = userGroupMapper.selectByExample(userGroupExample);
|
||||||
List<Project> projectList = new ArrayList<>();
|
List<Project> projectList = new ArrayList<>();
|
||||||
userGroups.forEach(userGroup -> projects.forEach(project -> {
|
userGroups.forEach(userGroup -> projects.forEach(project -> {
|
||||||
|
|
Loading…
Reference in New Issue