组织和工作空间切换0.1

This commit is contained in:
shiziyuan9527 2020-02-25 14:53:22 +08:00
parent fe12305ec2
commit 9e9951adcb
9 changed files with 72 additions and 49 deletions

View File

@ -2,11 +2,6 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="io.metersphere.base.mapper.ext.ExtUserRoleMapper">
<resultMap id="BaseResultMap" type="io.metersphere.dto.LoadTestDTO"
extends="io.metersphere.base.mapper.LoadTestMapper.BaseResultMap">
<result column="project_name" property="projectName"/>
</resultMap>
<select id="getUserRoleHelpList" parameterType="java.lang.String"
resultType="io.metersphere.dto.UserRoleHelpDTO">
SELECT

View File

@ -61,10 +61,10 @@ public class UserController {
return userService.getUserRoleList(userId);
}
@PostMapping("/switch/source/{sourceId}")
public UserDTO switchUserRole(@PathVariable(value = "sourceId") String sourceId) {
@PostMapping("/switch/source/{sign}/{sourceId}")
public UserDTO switchUserRole(@PathVariable String sign, @PathVariable(value = "sourceId") String sourceId) {
UserDTO user = SessionUtils.getUser();
userService.switchUserRole(user, sourceId);
userService.switchUserRole(user, sign, sourceId);
return SessionUtils.getUser();
}

View File

@ -53,4 +53,10 @@ public class WorkspaceController {
public List<Workspace> getWorkspaceListByUserId(@PathVariable String userId) {
return workspaceService.getWorkspaceListByUserId(userId);
}
@GetMapping("/list/orgworkspace/")
public List<Workspace> getWorkspaceListByOrgId() {
String currentOrganizationId = SessionUtils.getCurrentOrganizationId();
return workspaceService.getWorkspaceListByOrgId(currentOrganizationId);
}
}

View File

@ -21,9 +21,9 @@ public class UserDTO {
private Long updateTime;
private String workspaceId;
private String lastWorkspaceId;
private String organizationId;
private String lastOrganizationId;
private List<Role> roles = new ArrayList<>();
@ -103,19 +103,19 @@ public class UserDTO {
this.userRoles = userRoles;
}
public String getWorkspaceId() {
return workspaceId;
public String getLastWorkspaceId() {
return lastWorkspaceId;
}
public void setWorkspaceId(String workspaceId) {
this.workspaceId = workspaceId;
public void setLastWorkspaceId(String lastWorkspaceId) {
this.lastWorkspaceId = lastWorkspaceId;
}
public String getOrganizationId() {
return organizationId;
public String getLastOrganizationId() {
return lastOrganizationId;
}
public void setOrganizationId(String organizationId) {
this.organizationId = organizationId;
public void setLastOrganizationId(String lastOrganizationId) {
this.lastOrganizationId = lastOrganizationId;
}
}

View File

@ -1,10 +1,7 @@
package io.metersphere.service;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.OrganizationMapper;
import io.metersphere.base.mapper.RoleMapper;
import io.metersphere.base.mapper.UserMapper;
import io.metersphere.base.mapper.UserRoleMapper;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.exception.MSException;
@ -22,7 +19,6 @@ import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
@ -41,6 +37,8 @@ public class UserService {
private ExtUserRoleMapper extUserRoleMapper;
@Resource
private OrganizationMapper organizationMapper;
@Resource
private WorkspaceMapper workspaceMapper;
public UserDTO insert(User user) {
checkUserParam(user);
@ -221,10 +219,17 @@ public class UserService {
return resultList;
}
public void switchUserRole(UserDTO user, String sourceId) {
public void switchUserRole(UserDTO user,String sign,String sourceId) {
User newUser = new User();
// todo 切换处理
// user.setLastSourceId(sourceId);
if (StringUtils.equals("organization", sign)) {
user.setLastOrganizationId(sourceId);
user.setLastWorkspaceId("");
}
if (StringUtils.equals("workspace", sign)) {
Workspace workspace = workspaceMapper.selectByPrimaryKey(sourceId);
user.setLastOrganizationId(workspace.getOrganizationId());
user.setLastWorkspaceId(sourceId);
}
BeanUtils.copyProperties(user, newUser);
// 切换工作空间或组织之后更新 session 里的 user
SessionUtils.putUser(SessionUser.fromUser(user));

View File

@ -100,4 +100,10 @@ public class WorkspaceService {
return workspaceMapper.selectByExample(workspaceExample);
}
public List<Workspace> getWorkspaceListByOrgId(String orgId) {
WorkspaceExample workspaceExample = new WorkspaceExample();
workspaceExample.createCriteria().andOrganizationIdEqualTo(orgId);
return workspaceMapper.selectByExample(workspaceExample);
}
}

View File

@ -26,10 +26,10 @@ public class SessionUtils {
}
public static String getCurrentWorkspaceId() {
return Optional.ofNullable(getUser()).orElse(new SessionUser()).getWorkspaceId();
return Optional.ofNullable(getUser()).orElse(new SessionUser()).getLastWorkspaceId();
}
public static String getCurrentOrganizationId() {
return Optional.ofNullable(getUser()).orElse(new SessionUser()).getOrganizationId();
return Optional.ofNullable(getUser()).orElse(new SessionUser()).getLastOrganizationId();
}
}

View File

@ -9,18 +9,18 @@
<el-submenu index="1" popper-class="submenu" v-permission="['org_admin']">
<template slot="title">组织</template>
<label v-for="(item,index) in organizationList" :key="index">
<el-menu-item @click="clickMenu(item)">{{item.name}}
<el-menu-item @click="changeOrg(item)">{{item.name}}
<i class="el-icon-check"
v-if="item.id === currentUserInfo.lastSourceId || item.id === workspaceParentId"></i>
v-if="item.id === currentUserInfo.lastOrganizationId"></i>
</el-menu-item>
</label>
</el-submenu>
<el-submenu index="2" popper-class="submenu" v-permission="['test_manager', 'test_user', 'test_viewer']">
<template slot="title">工作空间</template>
<label v-for="(item,index) in workspaceList" :key="index">
<el-menu-item @click="clickMenu(item)">
<el-menu-item @click="changeWs(item)">
{{item.name}}
<i class="el-icon-check" v-if="item.id === currentUserInfo.lastSourceId"></i>
<i class="el-icon-check" v-if="item.id === currentUserInfo.lastWorkspaceId"></i>
</el-menu-item>
</label>
</el-submenu>
@ -54,7 +54,7 @@
data() {
return {
organizationList: [
{index: '7-1', name: '组织1'},
{index: '7-1', name: '组织'},
],
workspaceList: [
{index: '2-1', name: '无工作空间'},
@ -105,10 +105,15 @@
});
}
if (roles.indexOf(ROLE_TEST_MANAGER) > -1 || roles.indexOf(ROLE_TEST_USER) > -1 || roles.indexOf(ROLE_TEST_VIEWER) > -1) {
this.$get("/workspace/list/userworkspace/" + this.currentUserId, response => {
this.workspaceList = response.data;
this.workspaceIds = response.data.map(r => r.id);
});
this.$get("/workspace/list/orgworkspace/", response => {
let data = response.data;
if (data.length == 0) {
this.workspaceList = [{index:'1-1', name: '无工作区间'}]
} else {
this.workspaceList = data;
}
// this.workspaceIds = response.data.map(r = r.id);
})
}
},
getCurrentUserInfo() {
@ -116,19 +121,25 @@
this.currentUserInfo = response.data;
})
},
clickMenu(data) {
if (data.id === this.currentUserInfo.lastSourceId) {
return false;
}
window.console.log(data.id);
let user = {};
user.id = this.currentUserInfo.id;
user.lastSourceId = data.id;
this.$post("/user/switch/source/" + user.lastSourceId, {}, response => {
changeOrg(data) {
let orgId = data.id;
let sign = "organization";
this.$post("/user/switch/source/" + sign + "/" + orgId, {}, response => {
Cookies.set(TokenKey, response.data);
window.location.reload();
})
},
changeWs(data) {
let sign = "workspace";
let workspaceId = data.id;
// todo
if (typeof(workspaceId) == "undefined") {
return false;
}
this.$post("/user/switch/source/" + sign + "/" + workspaceId, {}, response => {
Cookies.set(TokenKey, response.data);
window.location.reload();
})
}
}
}

View File

@ -127,7 +127,7 @@
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.result = this.$get('/user/orgmember/delete/' + this.currentOrganizationId + '/' + row.id, () => {
this.result = this.$get('/user/orgmember/delete/' + this.currentUser().organizationId + '/' + row.id, () => {
this.$message({
type: 'success',
message: '删除成功!'
@ -153,7 +153,7 @@
if (valid) {
let param = {
userIds: this.form.userIds,
organizationId: this.currentOrganizationId
organizationId: this.currentUser().organizationId
};
this.result = this.$post("user/orgmember/add", param,() => {
this.initTableData();