切换组织时自动选取工作空间

This commit is contained in:
chenjianxing 2020-06-12 09:49:27 +08:00
parent ba7e9288af
commit d96578f305
2 changed files with 14 additions and 2 deletions

View File

@ -22,6 +22,7 @@ import io.metersphere.i18n.Translator;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authc.DisabledAccountException; import org.apache.shiro.authc.DisabledAccountException;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -48,6 +49,9 @@ public class UserService {
private WorkspaceMapper workspaceMapper; private WorkspaceMapper workspaceMapper;
@Resource @Resource
private ExtUserMapper extUserMapper; private ExtUserMapper extUserMapper;
@Lazy
@Resource
private WorkspaceService workspaceService;
public UserDTO insert(UserRequest user) { public UserDTO insert(UserRequest user) {
checkUserParam(user); checkUserParam(user);
@ -250,11 +254,16 @@ public class UserService {
SessionUser sessionUser = SessionUtils.getUser(); SessionUser sessionUser = SessionUtils.getUser();
// 获取最新UserDTO // 获取最新UserDTO
UserDTO user = getUserDTO(sessionUser.getId()); UserDTO user = getUserDTO(sessionUser.getId());
User newUser = new User(); User newUser = new User();
if (StringUtils.equals("organization", sign)) { if (StringUtils.equals("organization", sign)) {
user.setLastOrganizationId(sourceId); user.setLastOrganizationId(sourceId);
user.setLastWorkspaceId(""); List<Workspace> workspaces = workspaceService.getWorkspaceListByOrgIdAndUserId(sourceId);
if (workspaces.size() > 0) {
user.setLastWorkspaceId(workspaces.get(0).getId());
} else {
user.setLastWorkspaceId("");
}
} }
if (StringUtils.equals("workspace", sign)) { if (StringUtils.equals("workspace", sign)) {
Workspace workspace = workspaceMapper.selectByPrimaryKey(sourceId); Workspace workspace = workspaceMapper.selectByPrimaryKey(sourceId);

View File

@ -104,6 +104,9 @@
} }
this.$post("/user/switch/source/org/" + orgId, {}, response => { this.$post("/user/switch/source/org/" + orgId, {}, response => {
saveLocalStorage(response); saveLocalStorage(response);
if (response.data.workspaceId) {
localStorage.setItem("workspace_id", response.data.workspaceId);
}
this.$router.push('/'); this.$router.push('/');
window.location.reload(); window.location.reload();
}); });